Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm learning how to use VBOs and I'm following up on the tutorial at the bottom of this page.

So I went ahead and created a structure Vertex to hold vertex data.(coordinates and normals).

struct Vertex  {
  GLfloat  x,  y,  z;
  GLfloat nx, ny, nz;
  GLfloat   r, g,  b;
  GLfloat padding[7];
};

For the moment I'm trying to draw a cube.So I created an array with 8 vertices. My question is how do I set the normals?

When I used immediate rendering, I would just do a glNormal3f and proceeded to draw the vertices for that face. Now that the normals are defined on a per-vertex basis, and a vertex practically belongs to 3 faces, I'm somewhat confused as what I should do here.

Have I taken a wrong approach on making that structure, or I am missing something else.

I would also like to note that I want to make something more generic, so I don't want it to be limited to just drawing cubes.

Thanks.

share|improve this question
    
why don't you try using average of the normals of the faces which contain that vertex? –  Ali.S Jun 3 '11 at 16:31
add comment

2 Answers

up vote 2 down vote accepted

As you note, every vertex can only have one normal. That means that, depending on the lighting appearance you want, you may need to duplicate vertices. Specifically, if you want the edges of the cube to have a sharp boundary, then you will need to have separate vertices for each side. Make new vertices at the exact same position and use each duplicate for a different face.

If however you want to keep the vertices shared between multiple faces and have the lighting smoothed out over the edge, then you should set the normal of the vertex to the average of the normals of its faces.

share|improve this answer
add comment

The answer for your "cube" problem is probably that you're probably going to need more than 8 vertices. Make 4 for each face and set the normals for them to be the normal of the surface.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.