1 / 7

Texturing in OpenGL Lab #7

Texturing in OpenGL Lab #7. Creating Textures glEnable ( GL_TEXTURE_2D ); GLuint myTex; glGenTextures ( 1, (GLuint*) &myTex );

chanel
Download Presentation

Texturing in OpenGL Lab #7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Texturing in OpenGLLab #7

  2. 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 );

  3. 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}

  4. 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 );

  5. Lab #7 You are given a rendered cube like this.An image which contains 6 sides is already loaded: abc.jpg

  6. 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.

  7. 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.

More Related