Jump to content
  • Advertisement
Sign in to follow this  
OnTheRun

Problem with VBOs and normals

This topic is 5393 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm trying to get VBOs running. Right now I have an array with the model-data in it, which I pass to the following functions:
glEnableClientState(GL_VERTEX_ARRAY);
    	
glGenBuffersARB(1, &buffer2);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer2);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB);
I'm drawing it with:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer2);
glVertexPointer(3, GL_FLOAT, 0, 0);
               
glDrawArrays(GL_TRIANGLES, 0, 2880);
This works pretty good right now. So I thought about implementing the normals with a normal array, which I read out:
for(int i=0; i<numFaces; i++)
{	
	glNormal3f(normals.v[0], normals.v[1], normals.v[2]);
}
As I was using glVertex3f these coordinates worked without problems, so I read the coordinates into a file, copied them by hand in an array called normalz and tried to do a normal-array with them:
glEnableClientState(GL_NORMAL_ARRAY);
    	
glGenBuffersARB(1, &norm);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, norm);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(normalz), normalz, GL_STATIC_DRAW_ARB);
I tried to bind them with:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, norm);
                glNormalPointer(GL_FLOAT, 0, NULL);
But now the object looks kindof weird. Some normals work, some don't. Any hints what I'm doing wrong? Thanks and greetings

Share this post


Link to post
Share on other sites
Advertisement
Your normals array has three normals in it for each face. However, when using the array modes in OpenGL (normal vertex array, or VBO as in your case), you have to supply a normal for each vertex. OpenGL will select the correct normals using the index array.

So:
nofNormals == nofVertices

not
nofNormals==3*nofFaces


Edit: hmm, not so sure about if this applies to you. Just noticed you're not using indices.

Share this post


Link to post
Share on other sites
Thanks for your answer.
The problem is, i'm taking the normals out of an .obj-file, made with maya.
For example:

vn -0.306219 0.895231 -0.323715
f 1//1 2//2 3//3



The description of the .obj-format says:

f v1[/vt1][/vn1] v2[/vt2][/vn2] v3[/vt3][/vn3] ...

Share this post


Link to post
Share on other sites
And have you tried calculating the normals by hand?


CVec3 a = v1;
CVec3 b = v2;
CVec3 c = v3;
CVec3 ab = b-a;
CVec3 ac = c-a;
ab.MakeUnit();
ac.MakeUnit();
CVec3 normal = ab.CrossProduct(ac);



Use the above, and then just set all three normals to this value. This should give you flat shaded triangles.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!