#### Archived

This topic is now archived and is closed to further replies.

# Mesh rendering

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

## Recommended Posts

Hello Everybody I posted this message in the beginner forum and relalised that it didn''t really fit. I am using vertex and index lists in gl and i was wondering about the best way to handle a problem. Imagine a box 8 vertex 24 Indicies 24 Normals So here is the question. Are the normals related to the vertex or to the indicies. If its related to the vertecies then i could do a average at each point to define a normal that would work for the 3 faces that are attached to it. But what i would like is to assign the normals to the indicies. So for each vertex there would be 3 normals, one for each attached face. So is this possible in gl or do i have to have 24 vertices to match the normals. Thanks for your help. Ben

##### Share on other sites
24 normals for a cube? isn''t it a bit more than necessary?

ok, you have two main methods for applying normals in all the 3d (only THEORY and NOT implemented by DX/OGL, you must do it yourself):
first, _flat_ is about that every face has only one normal, so it has constant color. better for objs with sharp edges->better for your cube.

_smooth_ needs some type of smoooth_shading and every triangle has THREE, in most cases different normals, but every vertex has only one(and is used by all triangles which use your vertex.)

result: normals aren''t related to anything. They only "change color" of vertex.

result 2: it is possible. everything i possible in OpenGL...

##### Share on other sites
quote:
Original post by zander76
So here is the question. Are the normals related to the vertex or to the indicies. If its related to the vertecies then i could do a average at each point to define a normal that would work for the 3 faces that are attached to it.

But what i would like is to assign the normals to the indicies. So for each vertex there would be 3 normals, one for each attached face.

Normals are related to the Vertices. Each vertex is a single point in space and has only one normal. The normal simply defines how light will reflect of the suface at that vertex position. So you should have 8 normals, not 24.

I think you might also be a bit confused about indices and how you use them, it might help to read the section on Vertex Lists in ''The OpenGL programming guide'', that should clear up most of your problems.

Hope that helps.

---
"When I''m in command, every mission''s a suicide mission" - Zapp Branigan

##### Share on other sites
Yah, unfortunately right now I think you''d have to have 24 vertices. I don''t think there''s a way to specify multiple normals for one vertex.

##### Share on other sites
Thanks guys..

I appreciate the help. I didn''t think it was possible without duplicating the verticies. That really sucks. What about texture coordinates. Is it the samething.

Ben

##### Share on other sites
A vertex will also usually have only 1 texture co-ordinate, but you can have more if you use multitexturing.

---
When I''m in command, every mission''s a suicide mission!

##### Share on other sites
Hello

I just took a look at nehes lesson 6, the rotating box.

// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);

As you can probobly see is that the texture coordinates go from first of the image to the last and do that again for the next face.
The problem with this, if texture coordinates are not using the indicies the you can't do this. Each vertex requires 3 different u,v coordanites, for the sides a -1,1 and 1,1 and what ever the top is.

Later, Ben

[edited by - zander76 on August 13, 2003 11:38:56 AM]

##### Share on other sites
That section of code has nothing to do with indices, they are only used in vertex arrays.

I don''t think you quite understand what''s going on here, do you know what the two functions ''glTexCoord2f()'' and ''glVertex3f()'' are actually doing?

---
When I''m in command, every mission''s a suicide mission!

##### Share on other sites
A cube has eight vertexes and six surfaces. Not sure where you''re getting the "indices" from.

If you specify the normals of a cube, you''ve got a few options. One is to specify a normal for each surface. glNormal*() sets the normal for every vertex after it, until the next glNormal*() call. So to specify the normal for a surface, you would do something like:

glNormal()
glVertex3f()
glVertex3f()
glVertex3f()
glVertex3f()
glNormal()
...

You can also specify the normal for each vertex. This is used in Gourand shading, where the normal for a vertex is the average of the normals of its associated surfaces:
glNormal()
glVertex3f()
glNormal()
glVertex3f()
glNormal()
glVertex3f()
glNormal()
glVertex3f()

Hope this helps.

##### Share on other sites
Sorry.. i guess i should have been more clear. That was just an example of a problem i would like to solve using an index list instead of just straight calls. The example was ment to show the problem of using an index list with texture coordinates.

Here is a better example. (if there is a mistake sorry, i am just trying to do it in my head)

Vertex data.
<-1, 1, 1> <1,1,1>
<-1, 1, -1> <1,1,-1>
<-1, -1, 1> <1,-1,1>
<-1, -1, -1> <1,-1,-1>

Texcoords
<-1,1> <1,1>
<-1,-1> <1,-1>
<-1,1> <1,1>
<-1,-1> <1,-1>

Index list

// Front Face
1,4,3
1,2,4

// Side Face
2,7,4
2,6,7

Now here is the problem. I have 8 texture coordinates and 8 verticies. This may seem correct but if you take a look at point 2 it needs 2 different texture coordinates. On the front face it should have texture coordinates of <1,1> but on the side face connected to it it needs to have texture coordinates of <-1,1>

Does that explain the problem a little better. One the front face point 2 will be top/right of the texture image but on the side its top/left.

Thanks, Ben

1. 1
2. 2
Rutin
22
3. 3
JoeJ
20
4. 4
5. 5

• 27
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631735
• Total Posts
3001940
×