1 / 10

A Bit More on OpenGL

A Bit More on OpenGL. Matt Wronkiewicz Be Users Group at UIUC. Introduction. This presentation will cover 3D OpenGL programming as seen in Quake 2. Model files: MD2 for models and PCX for textures. Model Files. Files contain vertices, triangles, and texture coordinates.

baba
Télécharger la présentation

A Bit More on OpenGL

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. A Bit More on OpenGL Matt Wronkiewicz Be Users Group at UIUC

  2. Introduction • This presentation will cover 3D OpenGL programming as seen in Quake 2. • Model files: MD2 for models and PCX for textures.

  3. Model Files • Files contain vertices, triangles, and texture coordinates. • Vertices are groups of three floats • Triangles are groups of three vertices. • Vertices used by more than one triangle are only listed once. • Code for reading model files available from ftp.idsoftware.com

  4. Textures • Texture coordinates contained in model file. • Textures are in PCX image files. • Texture size must be a power of 2 (use gluScaleImage()). • Automatically mapped to drawn triangles.

  5. Texture Settings glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D. GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

  6. Setting up OpenGL for 3D Drawing • glEnable() sets flags in OpenGL • GL_CULL_FACE • GL_TEXTURE_2D • Set drawing mode with glPolygonMode(GL_FRONT, GL_FILL). • Set view with glOrtho(), glViewport(), and operations on the GL_PROJECTION matrix.

  7. Drawing Triangles in 3D // Transform GL_MODELVIEW matrix // Repeat for every triangle glBegin(GL_TRIANGLES); for (i = 0; i < numTriangles; i++) { // Get vertices v1..v3 glVertex3f(v1.x, v1.y, v1.z); glVertex3f(v2.x, v2.y, v2.z); glVertex3f(v3.x, v3.y, v3.z); } glEnd(); BGLView::SwapBuffers();

  8. Putting Triangles and Textures Together

  9. Lighting the Model • Enable lighting with glEnable(). • Create lights with glLight(). • Eight lights can be created with parameters GL_LIGHT1...GL_LIGHT8. • Use glLightfv(GL_LIGHTi, GL_POSITION, &v) to place light. • Other parameters set the color, intensity, and shape of the light.

  10. Get More Code • OpenGL Programmers Guide and Reference Manual are available online (pester Vik for URLs). • Dr. Dobb’s journal has source code for Quake 2 model viewer at http://www.ddj.com/ftp/1998/1998_07/. • Be’s GLTeapot source code is in the /boot/optional directory. Model format is similar to the Quake format.

More Related