HELP Lesson: 34
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
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:
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...
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...

Black holes are where God divided by 0.
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
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).
I''m not sure it works and I''m not sure the spelling is ok.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement