Jump to content
  • Advertisement

Archived

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

Quicksilver696

Texture Mapping Question...

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

Hello gang, I''m very new to the OpenGL programming scene. As such I''m only on the 6th tutorial, though am quite enjoying myself. I was able to get tutorial 5 to incorporate 6 textures one on each side of the cube. Now I have a really stupid question, how can I wrap a texture around 2,3,or 4 sides of a cube and not just 1 face? I was on the net and found a picture of a Quake2 texture of a face, and it got me wondering how they wrap the entire texture around the head? If anyone has any info/ideas I would very much appreciate it! -Quicksilver696

Share this post


Link to post
Share on other sites
Advertisement
It is just a matter of calculating the correct texture coordinates. Normally people uses some kind of modeller like 3dmax, truespace,.... In these applications you apply the texture using the techniques the offer, and export vertices, faces, texture coordinates and so on, to a file format their software can read.

Edited by - Claus Hansen Ries on May 18, 2000 4:42:48 AM

Share this post


Link to post
Share on other sites
Ok lets see.

If you imagine that the top right quarter of the texture holds the interesting part for what you are about to do, lets say is a face.
Now you have to learn hown glTexCoord works.

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); //means that the lower left part of the texture will be mapped to this vertex.
glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); //the lower right part of the texture is mapped to this vertex
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); //and so on..
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); //

This uses the whole texture.

So if you want to use just the upper right part of it(like we do), then type

glTexCoord2f(0.5f, 0.5f); glVertex3f(-1.0f, -1.0f, 0.0f); //means that the middle part of the texture will be mapped to this vertex.
glTexCoord2f(1.0f, 0.5f); glVertex3f(1.0f, -1.0f, 0.0f); //the middle right(my awkward english here) part of the texture is mapped to this vertex
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); //and so on..
glTexCoord2f(0.5f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); //

Not that in the above code i only change the glTexCoord not the values in glVertex.
This is for one quad, then you just repeat this for the rest of the head, using different parts of the texture as you go along.

I hope this is a correct(albeit long) way to explain it.

Share this post


Link to post
Share on other sites
In response to the question how do you wrap a texture round a cube:

Another way would to be change the texture matrix to do it. This way you don't have to work out the texture co-ordinates by hand...

So what you would need to do is:

//change the matrix mode to texture matrix

glMatrixMode( GL_TEXTURE );

//You want the texture to wrap round n faces, so you need

//to scale the matrix by 1 / n ( so that you get one complete texture around the n faces).

glScale( 1.0 / n, 1.0, 1.0 );

// you then need to offset the texture for each face by the face number over n.

for ( int f=0 ; f < n ;f++ )
{

glTexCoord2f(0.0f, 0.0f); glVertex(...);

glTexCoord2f(1.0f, 0.0f); glVertex(...);

glTexCoord2f(1.0f, 1.0f); glVertex(...);

glTexCoord2f(0.0f, 1.0f); glVertex(...);

glTranslatef( 1 / n, 0, 0 );

}
This will draw the first face with co-ord 0,0 the second with 1/n, 0, the third with 2/n, 0.....


If you wanted to, you could easily add a value that changed with time to the glTranslate(...) to get the texture to rotate round the object...

but as claus said for models you really need to have the vertex txeture info from the modelling program.

cheers dan

btw does anyone know how to do the code tags for this forum...






Edited by - Danack on May 19, 2000 4:48:41 AM

Edited by - Danack on May 19, 2000 4:50:21 AM

Share this post


Link to post
Share on other sites
Thanks a ton guys, it sure is great having hundreds of people to assist with any questions. Looking forward to seeing you all around....


-Quicksilver696

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!