//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();
Texture Coordinates
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:
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?
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?
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.
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.
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();
Also, here are my vars:
//World Texturing Info
GLubyte *worldtexture;
GLsizei wheight;
GLsizei wwidth;
bool textureGround = false;
//World Texturing Info
GLubyte *worldtexture;
GLsizei wheight;
GLsizei wwidth;
bool textureGround = false;
It looks like you are calling glTexImage2D out of the blue.
If you want a short explanations to creating a texture
http://www.opengl.org/wiki/index.php/Texture_Mapping
and I also suggest some tutorials. Make sure you understand how things work.
If you want a short explanations to creating a texture
http://www.opengl.org/wiki/index.php/Texture_Mapping
and I also suggest some tutorials. Make sure you understand how things work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement