How to do it...

Use the following steps to set up your buffer objects and render the triangle:

  1. Create a global (or private instance) variable to hold our handle to the vertex array object:
GLuint vaoHandle;
  1. Within the initialization function, we create and populate the vertex buffer objects for each attribute:
float positionData[] = { -0.8f, -0.8f, 0.0f, 0.8f, -0.8f, 0.0f, 0.0f, 0.8f, 0.0f }; float colorData[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; // Create and populate the buffer objects GLuint vboHandles[2]; glGenBuffers(2, vboHandles); GLuint positionBufferHandle = vboHandles[0]; GLuint colorBufferHandle = vboHandles[1]; // Populate the position buffer glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle); glBufferData(GL_ARRAY_BUFFER, ...

Get OpenGL 4 Shading Language Cookbook - Third 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.