頂点の初期化

vertex-initialization.png
  1. glGenVertexArrays…vertex array objectを割り当てる。
  2. glBindVertexArray
  3. glGenBuffers
  4. glBindBuffer
  5. glBufferData
  6. glUseProgram
  7. glVertexAttribPointer
  8. glEnableVertexAttribArray
void
init(void)
{
glGenVertexArrays(NumVAOs, VAOs);//vertex array objectを割り当てる。
glBindVertexArray(VAOs[Triangles]);
GLfloat vertices[NumVertices][2] = {
{ -0.90, -0.90 }, // Triangle 1
{ 0.85, -0.90 },
{ -0.90, 0.85 },
{ 0.90, -0.85 }, // Triangle 2
{ 0.90, 0.90 },
{ -0.85, 0.90 }
};
glGenBuffers(NumBuffers, Buffers);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, "triangles.vert" },
{ GL_FRAGMENT_SHADER, "triangles.frag" },
{ GL_NONE, NULL }
};
GLuint program = LoadShaders(shaders);
glUseProgram(program);
glVertexAttribPointer(vPosition, 2, GL_FLOAT,GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vPosition);
}

opengl-init

サポートサイト Wikidot.com opengl-init