PDA

saikumar
11-13-2015, 09:38 PM
hey guys i am animating a triangle so that colors rotates inside side the triangle by interpolation. but i am getting a blank window, please help me out, thanks in advance.

main code

int main(int argc, char* argv[])
{
display disp(800,600,"anime");

GLfloat vertices[] = { -0.5f, -0.5f, 0.0f,

0.5f, -0.5f, 0.0f,

+0.0f, +0.5f, 0.0f,
};

GLfloat color[] = { +1.0f, +0.0f, +0.0f,
+0.0f, +1.0f, +0.0f,
+0.0f, +0.0f, +1.0f,
};

mesh mes(vertices, (sizeof(vertices))/3,color);

GLfloat deltacolor=0.05f;

while (!disp.windowclose())
{

disp.clear(0.0f, 0.15f, 0.3f, 1.0f);
mes.updatemesh(vertices, color);
mes.draw();
disp.update();

////vertex 1 coloar change
if (color[0] <= 1 && color[0] > 0)
{
color[1] += deltacolor;
color[0] -= deltacolor;
}
else if (color[1] <= 1 && color[1] > 0)
{
color[2] += deltacolor;
color[1] -= deltacolor;
}
else if (color[2] <= 1 && color[2] > 0)
{
color[0] += deltacolor;
color[2] -= deltacolor;
}

////vertex 2 coloar change
if (color[3] <= 1 && color[3] > 0)
{
color[4] += deltacolor;
color[3] -= deltacolor;
}
else if (color[4] <= 1 && color[4] > 0)
{
color[5] += deltacolor;
color[4] -= deltacolor;
}
else if (color[5] <= 1 && color[5] > 0)
{
color[3] += deltacolor;
color[5] -= deltacolor;
}

//vertex 3 coloar change
if (color[6] <= 1 && color[6] > 0)
{
color[7] += deltacolor;
color[6] -= deltacolor;
}
else if (color[7] <= 1 && color[7] > 0)
{
color[8] += deltacolor;
color[7] -= deltacolor;
}
else if (color[8] <= 1 && color[8] > 0)
{
color[6] += deltacolor;
color[8] -= deltacolor;
}
SDL_Delay(1);
}

return 0;
}

mesh code

mesh::mesh(const GLfloat* vertices, unsigned int num_vertices,GLfloat* color)
{
m_drawCount = num_vertices;

glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);

glGenBuffers(num_buffers, vertexArrayBuffers);
glBindBuffer(GL_ARRAY_BUFFER, vertexArrayBuffers[position]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices)+sizeof(color), NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(vertices)));

glBindVertexArray(0);
}

mesh::~mesh()
{
glDeleteBuffers(num_buffers, vertexArrayBuffers);
glDeleteVertexArrays(1, &vertexArrayObject);
}

void mesh::draw()
{
glBindVertexArray(vertexArrayObject);
glDrawArrays(GL_TRIANGLES, 0, m_drawCount);
glBindVertexArray(0);
}

void mesh::updatemesh(const GLfloat* vertices, const GLfloat* color)
{
glBindVertexArray(vertexArrayObject);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(color), color);
}

#include <iostream>
#include <fstream>

{
m_program = glCreateProgram();

for (unsigned int i = 0; i < NUM_SHADERS; i++)

glBindAttribLocation(m_program, 0, "position");
glBindAttribLocation(m_program, 1, "vertexColor");

glValidateProgram(m_program);

}

{
for (unsigned int i = 0; i < NUM_SHADERS; i++)
{
}

glDeleteProgram(m_program);
}

{
glUseProgram(m_program);
}

{
std::ifstream file;
file.open((fileName).c_str());

std::string output;
std::string line;

if (file.is_open())
{
while (file.good())
{
getline(file, line);
output.append(line + "\n");
}
}
else
{
}

return output;
}

{
GLint success = 0;
GLchar error[1024] = { 0 };

if (isProgram)
else

if (success == GL_FALSE)
{
if (isProgram)
else

std::cerr << errorMessage << ": '" << error << "'" << std::endl;
}
}

{

std::cerr << "Error compiling shader type " << type << std::endl;

const GLchar* p[1];
p[0] = text.c_str();
GLint lengths[1];
lengths[0] = text.length();