Jump to content
  • Advertisement

Archived

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

KillerSneak

HELP Lesson: 34

This topic is 5320 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 just finishid this tutorial (i needed a hightmap code) But now i want to know how to aply a texture to the HightMap ? Now it''s been given a COLOR (blue) and it looks like one big blue ting.. I wan to have a texture aplied on it. Hope some one can help me

Share this post


Link to post
Share on other sites
Advertisement
Well, I haven''t looked at lesson34 myself, but when I texture heightmaps I basically just iterate between 0 and 1 by the stepsize for the texture coordinates. That''s not a very good description so here''s some code:


for( int i = 0; i < width; i++){
for(int j = 0; j < height; j++){
glTexture2f(i/(float)width,j/(float)height);
glVertex3f(i, height(i,j),j);
}
}



that''s not meant to be working code. Basically what I''m trying to say is that when you specify a coordinate, you specify it''s texture coordinate as well. Each time you take a step in the position, you also take a step in the texture coord.

Sorry if that isn''t very clear... it''s nearly 4am...

Share this post


Link to post
Share on other sites

Well im sure it''s helpfull for someone that''s already a little advanced in Coding. I''m just starting :| Maybe you could take a quick look at the code from lesson 34 ? And give me some code that needs to be changed ? I hope this isn''t asked to much

Share this post


Link to post
Share on other sites
Since you''re already looking at lesson 34 I suppose you know how to load and use a texture (otherwise try reading some previous lesson before going on).

Basically, what you have to do is exactly what Spockmeat said.
Anyway, this is thae code for lesson 34 (this means it uses the same variables).

for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )
for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE )
{
// Get The (X, Y, Z) Value For The Bottom Left Vertex

x = X;
y = Height(pHeightMap, X, Y );
z = Y;

// Set Texture coordinates Of The Current Vertex

glTexCoord2f(X/MAP_SIZE,Y/MAP_SIZE);

glVertex3i(x, y, z); // Send This Vertex To OpenGL To Be Rendered


// Get The (X, Y, Z) Value For The Top Left Vertex

x = X;
y = Height(pHeightMap, X, Y + STEP_SIZE );
z = Y + STEP_SIZE ;

glTexCoord2f(X/MAP_SIZE,(Y+STEP_SIZE)/MAP_SIZE);

glVertex3i(x, y, z); // Send This Vertex To OpenGL To Be Rendered


// Get The (X, Y, Z) Value For The Top Right Vertex

x = X + STEP_SIZE;
y = Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE );
z = Y + STEP_SIZE ;

glTexCoord2f((X+STEP_SIZE)/MAP_SIZE,(Y+STEP_SIZE)/MAP_SIZE);

glVertex3i(x, y, z); // Send This Vertex To OpenGL To Be Rendered


// Get The (X, Y, Z) Value For The Bottom Right Vertex

x = X + STEP_SIZE;
y = Height(pHeightMap, X + STEP_SIZE, Y );
z = Y;

glTexCoord2f((X+STEP_SIZE)/MAP_SIZE,Y/MAP_SIZE);

glVertex3i(x, y, z); // Send This Vertex To OpenGL To Be Rendered

}



I''m not sure it works and I''m not sure the spelling is ok.

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!