Im actually learning some OpenGL, i managed to load a mesh and show it in a window. Then i made a function with SDL that let me rotate the mesh with the arrow keys. But when i dived into Shaders i made some changes, but i cannot get a simple rotation for the 3d model.
Here is my drawing function:
glMatrixMode(GL_MODELVIEW); //set the matrix to model view mode
glPushMatrix(); // push the matrix
glRotatef(1.0,0.0,0.0,1.0); //apply transformation
//Primer buffer, modelo
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
glEnableVertexAttribArray(0);
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0,vertices.size());
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glPopMatrix();//pop the matrix
glMatrixMode(GL_PROJECTION); // Apply projection matrix again
Theese are my shaders:
Fragment Shader( only for give color)
#version 130
out vec3 color;
void main()
{
color = vec3(0.0,0.5,1.0);
}
Vertex Shader(Used it to mess around and try):
#version 130
in vec3 vertexPosition;
void main()
{
gl_Position.x = vertexPosition.x;
gl_Position.y = vertexPosition.y-1.0;
gl_Position.z = vertexPosition.z;
gl_Position.w = 1.0;
}
SOURCE: I actually used this to get a reference, but didnt do the trick: OpenGL - Object Transformations and VBOs
EDIT: The problem is that the "glRotatef" command in the drawing function doesn't rotate the mesh...
EDIT2: see comments
void GLSLProgram::use()
{
glUseProgram(_shaderEnteroID);
for(int i = 0; i< _numeroAtributos; i++)
{
glEnableVertexAttribArray(i);
}
}
void GLSLProgram::unuse()
{
glUseProgram(0);
for(int i = 0; i< _numeroAtributos; i++)
{
glDisableVertexAttribArray(i);
}
}