| |||||||||||
|
Main Menu Other |
Tutorials -- Texture Mapping | ||||||||||
|
Drawing Polygons With a TextureglBindTexture(GL_TEXTURE_2D, TEX_TILE); glEnable(GL_TEXTURE_2D); glColor4f(1, 1, 1, 1); glBegin(GL_POLYGON); glTexCoord3f( 0, 0, 0); glVertex3f(-5, 5, 0); glTexCoord3f( 1, 0, 0); glVertex3f( 5, 5, 0); glTexCoord3f( 1, 1, 0); glVertex3f( 5, -5, 0); glTexCoord3f( 0, 1, 0); glVertex3f(-5, -5, 0); glEnd(); Lets go through this code step by step. First we make the texture active in OpenGL. Then we glEnable the GL_TEXTURE_2D value. (If you know GL_TEXTURE_2D is already enabled from any previous glEnable command, take this line out.) Then we set our color to white so our texture shows up normal. If you set the color to something else, the polygon will end up textured that color. Finally, we begin drawing a GL_POLYGON. Before each vertex is set, we set the current texture coordinates. This tells OpenGL which corner of the texture belongs to each vertex. So for the top left vertex, we want the top left corner of the texture, top right gets top right, and so on. You can also set the texcoords to values greater than one, which will cause the texture to repeat that many times. For example, set all the texcoords that are 1 to 10, and the texture will be drawn 100 times over the polygon.
|
|||||||||||