Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 2.75 KB

cube.md

File metadata and controls

58 lines (40 loc) · 2.75 KB

cube

This module renders the 3D reference cube using OpenGL. It is useful for testing object transformations and debugging OpenGL applictions. The implementation gives a simple example of basic rendering with the ARB_vertex_buffer_object specification.

To better enable a concrete understanding of 3D transforms, a real-world instance of the 3D reference cube may be constructed from paper or cardstock using this template PDF.

Compilation

To use this module, simply link it with your own code. It requires OpenGL, GLEW, and the image utility. To load the cube texture images, the image utility requires the PNG libraries.

cc -o program program.c cube.c image.c -lpng -lz -lGLEW -lGL -lm

API

  • cube *cube_create(void)

    Initialize and return a pointer to a new cube object. This object contains OpenGL state, so it may be called only after the OpenGL context has been initialized.

  • void cube_delete(cube *C)

    Delete cube C and release all OpenGL resources held by it.

  • void cube_render(cube *C)

    Render cube C using the current OpenGL context and state. The necessary texture and vertex array states are pushed to the attribute stack before modification and popped after rendering.

Textures

The orientation of the texture image applied to each face is significant. It indicates the orientation expected by the OpenGL cube map texture mode. The default textures are each "upright" in their own 2D space.

On the 3D cube, the four "sides" of the cube remain "upright" as viewed in the default eye space, where the +y axis points up. The "top" is oriented with the −z axis pointing locally up, and the "bottom" is oriented with the +z axis pointing locally up. These orientations must be considered when designing cube map textures. Here is the cube as seen from above and below.