Download presentation
Presentation is loading. Please wait.
Published byKathryn Carroll Modified over 9 years ago
1
Texturing in OpenGL Lab #7
2
Creating Textures glEnable ( 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 );
3
In IGX, these steps are already done for you: ImageXimg; void setup () { img.Load ( “abc.jpg” );// does glGenTexture img.Update (0);// does glTexImage2D int id = img.getGLID ();// Give the OpenGL id }
4
Binding and Using Textures glEnable ( 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 );
5
Lab #7 You are given a rendered cube like this. An image which contains 6 sides is already loaded: abc.jpg
6
Modify the code to bind the texture and apply UV coordinates so that the cube is properly textured to look like a Toy block. Lab #7 Notice that the side letters are B, C, D, E in order, upright. The bottom is F.
7
Advanced: * Create and animate a texture without using the ImageX class. You need to: 1) Create an array of bytes to hold the data 2) Call glGenTexture and glTexImage2D to load the data 3) Change the texture over time. This could be done by painting 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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.