Jump to content
  • Advertisement

Archived

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

_Titan_

cant map textures to my terrain!

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

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 2

glTexCoord2f(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 3

glTexCoord2f(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 4

glTexCoord2f(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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you''ll need to use glTexCoord2f instead of glTexCoord2d

just my 2 eurocents ...

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!