OpenGL Drawing Exercises

This is a relatively simple example of using a few of the OpenGL drawing commands covered so far in this chapter. Example 3.5 shows how the data is loaded into the buffers required to use the draw commands in the example. Example 3.6 shows how the drawing commands are called.

Example 3.5. Setting up for the Drawing Command Example

// A four verticesstatic const GLfloat vertex_positions[] ={    -1.0f, -1.0f, 0.0f, 1.0f,     1.0f, -1.0f, 0.0f, 1.0f,    -1.0f,  1.0f, 0.0f, 1.0f,    -1.0f, -1.0f, 0.0f, 1.0f,};// Color for each vertexstatic const GLfloat vertex_colors[] ={    1.0f, 1.0f, 1.0f, 1.0f,    1.0f, 1.0f, 0.0f, 1.0f,    1.0f, 0.0f, 1.0f, 1.0f,    0.0f, 1.0f, 1.0f, 1.0f};// Three indices ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.