Jump to content
  • Advertisement

Archived

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

pDK

Normals (or Lights) And Triangle Strips

This topic is 5867 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

Well, i''ve been doing alot of terrain creation... And I''m almost finished (besides from model loading and such). But one of the basic things have been quite troublesome: Lighting. I''m able to light simple objects (Ie: squares), but I''m not quite sure how you would do this for a Triangle Strip... I have an idea how I would calculate the normals... but where to place them? I realy dont want to go to creating pure triangles, but to occomplish this is quite daunting... Any ideas from the experts? Btw, my code is a hightmap (from a modified raw file). And it loops through all the points, drawing two points at a time (in pairal to each other). And when it reaches the farthes side of the map, it loops back (going in the opposite direction). You can find something similar to this in the GameTutorials.com website. Thanks again!

Share this post


Link to post
Share on other sites
Advertisement
Well, you''d simply call glNormalXX before the relevant call to glVertexXX ( for immediate mode ), or glNormalPointer if you''re using vertex arrays.

Is that what you mean? How you render the terrain ( tri-strips, single triangles, tri-fans ) doesn''t matter at all, because it''s the vertex normals that change the lighting.

Calculating the normals is another thing all together though...

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
well.. Thanks for in the info... I know I have to call NormalXX() before the first vertex (in the group). But with a triangle strip.. what one(s) are the "relevent" vertexs? I have an idea how they are build (read the OpenGL Red book)... but it doesnt realy clue me in on where to put the normal codin inside my code...

Just to give you an idea, here is my terrian coding as off now (about 90% of the code was cut out for your sanity):


glBegin( GL_TRIANGLE_STRIP );

// Go through all of the rows of the height map
for ( X = 0; X <= MAP_SIZE; X += STEP_SIZE )
{
// Chechk if we need to render the opposite way for this column
if(bSwitchSides)
{
// Render a column of the terrain, for this current X.
// We start at MAP_SIZE and render down to 0.
for ( Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE )
{
// Get the (X, Y, Z) value for the bottom left vertex
x = X;
y = Height(pHeightMap, X, Y );
z = Y;

// Set the current texture coordinate and render the vertex
SetTextureCoord( (float)x, (float)z );
glVertex3i(x, y, z);

// Get the (X, Y, Z) value for the bottom right vertex
x = X + STEP_SIZE;
y = Height(pHeightMap, X + STEP_SIZE, Y );
z = Y;

// Set the current texture coordinate and render the vertex
SetTextureCoord( (float)x, (float)z );
glVertex3i(x, y, z);
}
}
else
{
// Render a column of the terrain, for this current X.
// We start at 0 and render down up to MAP_SIZE.
for ( Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE )
{
// Get the (X, Y, Z) value for the bottom right vertex
x = X + STEP_SIZE;
y = Height(pHeightMap, X + STEP_SIZE, Y );
z = Y;

// Set the current texture coordinate and render the vertex
SetTextureCoord( (float)x, (float)z );
glVertex3i(x, y, z);

// Get the (X, Y, Z) value for the bottom left vertex
x = X;
y = Height(pHeightMap, X, Y );
z = Y;

// Set the current texture coordinate and render the vertex
SetTextureCoord( (float)x, (float)z );
glVertex3i(x, y, z);
}
}

// Switch the direction the column renders to allow the fluid tri strips
bSwitchSides = bSwitchSides;
}

// Stop rendering triangle strips
glEnd();
[/CODE]

Ohh I do hope that turns out.. if not, just view it in the View->Source. Thanks again!

Share this post


Link to post
Share on other sites
Btw... you can find to FULL source code here: http://www.gametutorials.com/download/OpenGL/HeightMap2_OGL.zip

Yes.. its not mine. But mine is based off of that (same concept.. just with ALOT of revisions on it... so i can''t safely call it my own).

Share this post


Link to post
Share on other sites
You call glNormalXX before EVERY vertex that you render. This is needed for vertex lighting. Pre-calculate the normals though.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!