Jump to content
  • Advertisement
Sign in to follow this  
mbanghart

Texture Coordinates

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

Hi, I am trying to specify my texture coordinates. I am confused because texture coordinates are specified in 2D, but my block is defined in 3D. Here is my code:
 //Block defined with 6 polygons   
  glNewList(2, GL_COMPILE);      
     glBegin(GL_QUADS);
       glNormal3f( 0.0, 0.0, 1.0 );      
       glVertex3f( 0.5f, 0.5f,-0.5f);			// Top Right Of The Quad (Top)
       glVertex3f(-0.5f, 0.5f,-0.5f);			// Top Left Of The Quad (Top)
       glVertex3f(-0.5f, 0.5f, 0.5f);			// Bottom Left Of The Quad (Top)
       glVertex3f( 0.5f, 0.5f, 0.5f);			// Bottom Right Of The Quad (Top)

       glNormal3f( 0.0, 1.0, -1.0 );   
       glVertex3f( 0.5f,-0.5f, 0.5f);			// Top Right Of The Quad (Bottom)
       glVertex3f(-0.5f,-0.5f, 0.5f);			// Top Left Of The Quad (Bottom)
       glVertex3f(-0.5f,-0.5f,-0.5f);			// Bottom Left Of The Quad (Bottom)
       glVertex3f( 0.5f,-0.5f,-0.5f);			// Bottom Right Of The Quad (Bottom)

       glNormal3f( 0.0, 1.0, 0.0 );   
       glVertex3f( 0.5f, 0.5f, 0.5f);			// Top Right Of The Quad (Front)
       glVertex3f(-0.5f, 0.5f, 0.5f);			// Top Left Of The Quad (Front)
       glVertex3f(-0.5f,-0.5f, 0.5f);			// Bottom Left Of The Quad (Front)
       glVertex3f( 0.5f,-0.5f, 0.5f);			// Bottom Right Of The Quad (Front)

       glNormal3f( 0.0, -1.0, 0.0 );   
       glVertex3f( 0.5f,-0.5f,-0.5f);			// Bottom Left Of The Quad (Back)
       glVertex3f(-0.5f,-0.5f,-0.5f);			// Bottom Right Of The Quad (Back)
       glVertex3f(-0.5f, 0.5f,-0.5f);			// Top Right Of The Quad (Back)
       glVertex3f( 0.5f, 0.5f,-0.5f);			// Top Left Of The Quad (Back)

       glNormal3f( -1.0, 0.0, 0.0 );   
       glVertex3f(-0.5f, 0.5f, 0.5f);			// Top Right Of The Quad (Left)
       glVertex3f(-0.5f, 0.5f,-0.5f);			// Top Left Of The Quad (Left)
       glVertex3f(-0.5f,-0.5f,-0.5f);			// Bottom Left Of The Quad (Left)
       glVertex3f(-0.5f,-0.5f, 0.5f);			// Bottom Right Of The Quad (Left)

       glNormal3f( 1.0, 0.0, 0.0 );   
       glVertex3f( 0.5f, 0.5f,-0.5f);			// Top Right Of The Quad (Right)
       glVertex3f( 0.5f, 0.5f, 0.5f);			// Top Left Of The Quad (Right)		
       glVertex3f( 0.5f,-0.5f, 0.5f);			// Bottom Left Of The Quad (Right)
       glVertex3f( 0.5f,-0.5f,-0.5f);			// Bottom Right Of The Quad (Right)
     glEnd();						            // Done Drawing The Quad   
  glEndList();

Share this post


Link to post
Share on other sites
Advertisement
Texture co-ordinates address texels (i.e. pixels of a texture), and usually textures are 2D images. Hence usually texture co-ordinates are 2D, too. Nevertheless 1D and 3D textures exist as well. For those kinds of textures obviously 1D or 3D co-ordinates are used.

The correspondence of all texture co-ordinates to vertices of a model is called texture mapping. There are several ways of doing so. For the usual case of 2D textures and 3D models, accelerated graphics APIs provide the often so-called u,v-mapping, where u,v stand for the both texture co-ordinates (are also often named s,t).

Now, mapping a 2D texture to a 3D object is not problematic if you consider that the object has a surface, and although the object is defined in 3D, a surface in 3D is still a 2D topological element. E.g. a triangle is infinitely thin and hence has no 3rd dimension.

What is your specific question?

Share this post


Link to post
Share on other sites
So if you want to map the entire texture to a single face of your cube, you just use the texture coordinates (0,0) (1,0) (0,1) and (1,1) for the vertices on one side of the cube. I'll just give an example using your first face:

glNormal3f( 0.0, 0.0, 1.0 );

glTexCoord2f(1.0f, 1.0f);
glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Top)

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Top)

glTexCoord2f(0.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left Of The Quad (Top)

glTexCoord2f(1.0f, 0.0f);
glVertex3f( 0.5f, 0.5f, 0.5f); // Bottom Right Of The Quad (Top)

I've mapped the bottom left corner of the texture (0,0) to the bottom left corner of the quad, and the top right corner of the texture (1,1) to the top right corner of the quad, and so on.

Share this post


Link to post
Share on other sites
Ok so is this correct? Texturing is still not showing up. I used cout statements to make sure my variables do contain the image, width and height. I am pretty sure the problem is not there.


glEnable( GL_TEXTURE_2D );


if (textureGround == true)
{
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,wwidth,wheight,0,GL_RGB,GL_UNSIGNED_BYTE,worldtexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
}

//Draw ground and orientate correctly
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glScalef(worldx,worldy,1);
glBegin(GL_QUADS);
glColor3f(wc1, wc2, wc3); //Set color of ground
glNormal3f( 0.0, 0.0, 1.0 );
glTexCoord2f(0.0f, 0.0f);
glVertex3f( -0.5f,-0.5f, 0);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f,0.5f, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.5f,0.5f,0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 0.5f,-0.5f,0);
glEnd();
glPopAttrib();
glPopMatrix();

Share this post


Link to post
Share on other sites
Also, here are my vars:

//World Texturing Info
GLubyte *worldtexture;
GLsizei wheight;
GLsizei wwidth;
bool textureGround = false;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!