Hello everyone!
What I’m trying to do is using the normals I got from an obj file. I recently had to re-code large parts of my program to accomodate new standards. Before I did this, the normals worked. I was, however, using a weird mix of fixed pipeline and newer functions. I think I’m still using a pretty weird code, but at least it has worked (until now).
Here is how it looks:
Here is the model in Blender:
Here’s how I’m drawing:
First I get the data from my obj file as seen in this tutorial: Tutorial 7 : Model loading
Then I use it to render the arm:
once:
glGenBuffers(1, &vbo_arm_vertices);
glBindBuffer(GL_ARRAY_BUFFER, vbo_arm_vertices);
glBufferData(GL_ARRAY_BUFFER, temp_arm_coords.size(), temp_arm_coords.data(), GL_STATIC_DRAW);
and in the drawing loop:
glBindBuffer(GL_ARRAY_BUFFER, vbo_arm_vertices);
glBufferData(GL_ARRAY_BUFFER, armVertexFinalData.size()*sizeof(GLfloat), &armVertexFinalData[0], GL_STATIC_DRAW);
glVertexAttribPointer(
attribute_coord3d, // attribute
3, // number of elements per vertex, here (x,y,z)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
0 // offset of first element
);
glDrawArrays(GL_TRIANGLES, 0, armVertexFinalData.size()/3);
basically.
Now I try to get the normals in there.
glEnableVertexAttribArray(attribute_v_normal);
glBindBuffer(GL_ARRAY_BUFFER, armNormalVBO);
glVertexAttribPointer(
attribute_v_normal, // attribute
3, // number of elements per vertex, here (R,G,B)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
0 // offset of first element
);
How would I have to modify my shader to use the normals?
Vertex shader:
attribute vec3 coord3d;
attribute vec3 v_color;
attribute vec3 v_normal;
uniform mat4 mvp;
varying vec3 f_color;
void main(void) {
gl_Position = mvp * vec4(coord3d, 1.0);
f_color = v_color;
}
Fragment shader:
varying vec3 f_color;
void main(void) {
gl_FragColor = vec4(f_color.x, f_color.y, f_color.z, 1.0);
}
I first tried to get my normals with glnormalpointer, like this:
glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, armNormalVBO);
glBufferData(GL_ARRAY_BUFFER, armNormalFinalData.size()*sizeof(GLfloat), &armNormalFinalData[0], GL_STATIC_DRAW);
glNormalPointer(GL_FLOAT, 0, NULL);
But that didn’t work.
Now I don’t even know where to start looking so could anyone please help me.
I want to say that I really only need the simplest kind of ambient light; nothing fancy or good-looking at all. I need to finish this project and I’m always running into new problems. I had no hard time understanding fixed pipeline openGL, but the whole shader stuff just doesn’t work with my brain.