cant map textures to my terrain!

Started by
16 comments, last by _Titan_ 21 years, 10 months ago
how can i map my texture over all of the triangles instead of each triangle hacing been mapped with the texture? int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(tX,tY,tZ); // Move Left 1.5 Units And Into The Screen 6.0 glPushMatrix(); glTranslatef(0.0,0.0,0.0); //glRotatef(Degree,0.0,0.0,0.0); glBindTexture(GL_TEXTURE_2D, Texture[0].texID); for(int y=1;y<149;y++) { for(int x=1;x<149;x++) { glBegin(GL_TRIANGLE_STRIP); glColor3f(MapCoord[x][y].y/40,MapCoord[x][y].y/40,MapCoord[x][y].y/40); glTexCoord2d(1,1); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right glTexCoord2d(0,1); glVertex3f(MapCoord[x][y+1].x,MapCoord[x][y+1].y,MapCoord[x][y+1].z); // Top Left glTexCoord2d(1,0); glVertex3f(MapCoord[x+1][y].x,MapCoord[x+1][y].y,MapCoord[x+1][y].z); // Bottom Right glTexCoord2d(0,0); glVertex3f(MapCoord[x+1][y+1].x,MapCoord[x+1][y+1].y,MapCoord[x+1][y+1].z); // Bottom Left glEnd(); } } glPopMatrix(); return TRUE; // Keep Going } [edited by - _Titan_ on June 5, 2002 4:24:42 PM]
Advertisement
Right now you''re specifying a texture coordinate of 0 or 1 for every vertex, and doing this every iteration in your for loops. Instead, calculate the texture coordinates, so that 0 is first vertex of the initial triangle, and 1 is the final vertex of the last triangle. And then intermediary vertices will have a texture coordinate that is some appropriate value between 0 and 1.

Hope that makes sense.
----------------Amusing quote deleted at request of owner
Ok, i understand, but...if you have to specify a TexCoord for each vertex, how would i do it for only the the four corners?
You''ll still specify texcoords for each vertex, but instead of each texcoord being 0 or 1, you''ll have something like this:

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right

So each texcoord is between 0 and 1 for the entire range of vertices...

Does that help?
----------------Amusing quote deleted at request of owner
Hmm...did not work, it just mapped as a big green one color map...not what i intended...maybe i did it wrong? I''m sur ei did

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x][y+1].x,MapCoord[x][y+1].y,MapCoord[x][y+1].z); // Top Left

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x+1][y].x,MapCoord[x+1][y].y,MapCoord[x+1][y].z); // Bottom Right

glTexCoord2d(x/149,y/149); glVertex3f(MapCoord[x+1][y+1].x,MapCoord[x+1][y+1].y,MapCoord[x+1][y+1].z); // Bottom Left
That's going to make all 4 texcoords have the same value for each of the 4 vertices per trianglestrip. What I gave you was just to explain the idea, not exactly make it work.

Basically, divide the range of 0 to 1 over each vertex, so that there is an increment over the entire range of your terrain.

With 4 quads,texcoords would look like this:

  // Quad1    glTexCoord2f(0,0); glVertex3f(0,0,0);glTexCoord2f(0.5,0); glVertex3f(1,0,0);glTexCoord2f(0,0.5); glVertex3f(0,1,0);glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);//Quad 2glTexCoord2f(0.5,0); glVertex3f(1,0,0);glTexCoord2f(1.0,0); glVertex3f(2,0,0);glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);glTexCoord2f(1.0,0.5); glVertex3f(2,1,0);//Quad 3glTexCoord2f(0,0.5); glVertex3f(0,1,0);glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);glTexCoord2f(0.0,1.0); glVertex3f(0,2,0);glTexCoord2f(0.5,1.0); glVertex3f(1,2,0);//Quad 4glTexCoord2f(0.5,0.5); glVertex3f(1,1,0);glTexCoord2f(1.0,0.5); glVertex3f(2,1,0);glTexCoord2f(0.5,1.0); glVertex3f(1,2,0);glTexCoord2f(1.0,1.0); glVertex3f(2,2,0);    


See, I have the texcoords stretched over four quads. It's up to you how you implement this.


Edit: Damn source tags aren't holding my formatting...grrrr.

[edited by - yakuza on June 5, 2002 6:10:51 PM]
----------------Amusing quote deleted at request of owner
Ok...Still cant get this to work. Am i just lame or what? How would i do this in my loop?
Sorry, I''m at work and can''t take anymore time to help you right now. I''d suggest reading the Height Map tutorials at GameTutorials.com, I think they might be exactly what you need.

http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg3.htm
----------------Amusing quote deleted at request of owner
lol! I''m at work too

Will read them and see what i find. Thanks anyways
you''ll need to use glTexCoord2f instead of glTexCoord2d

just my 2 eurocents ...

This topic is closed to new replies.

Advertisement