70 likes | 185 Views
Texturing in OpenGL Lab #7. Creating Textures glEnable ( GL_TEXTURE_2D ); GLuint myTex; glGenTextures ( 1, (GLuint*) &myTex );
E N D
Creating TexturesglEnable ( GL_TEXTURE_2D );GLuint myTex; glGenTextures ( 1, (GLuint*) &myTex ); glBindTexture ( GL_TEXTURE_2D, myTex );glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );int xres = 256;int yres = 256;char* data; glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, xres, yres, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
In IGX, these steps are already done for you: ImageX img;void setup (){ img.Load ( “abc.jpg” ); // does glGenTexture img.Update (0); // does glTexImage2D int id = img.getGLID (); // Give the OpenGL id}
Binding and Using TexturesglEnable ( GL_TEXTURE_2D ); glBindTexture ( GL_TEXTURE_2D, id ); Texture Coordinates Similar to glColor and glNormal3f, goes before glVertex.Sets the UV texture coordinate for the next vertex.glTexCoord2f ( u ,v ); glVertex3f ( 1, 0, 0 ); glTexCoord2f ( u ,v ); glVertex3f ( 0, 1, 0 );
Lab #7 You are given a rendered cube like this.An image which contains 6 sides is already loaded: abc.jpg
Lab #7 Modify the code to bind the texture and apply UV coordinatesso that the cube is properly textured to look like a Toy block. Notice that the side letters are B, C, D, E in order, upright. The bottom is F.
Advanced: * Create and animate a texture without using the ImageX class.You need to:1) Create an array of bytes to hold the data2) Call glGenTexture and glTexImage2D to load the data3) Change the texture over time. This could be done bypainting it using the mouse, or modifying by a function over time.4) If you animate the texture, you must call glTexImage2D in the draw3D portion (not setup). This makes sure the image is continuously updated on the GPU.5) Call glBindTexture and glTexCoords to render the texture on object.