Created
November 29, 2015 15:56
-
-
Save zeffii/131fb3a0f6fc3ca117fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#include "vgl.h" | |
#include "LoadShaders.h" | |
enum VAO_IDs { Triangles, NumVAOs }; | |
enum Buffer_IDs { ArrayBuffer, NumBuffers }; | |
enum Attrib_IDs { vPosition = 0 }; | |
GLuint VAOs[NumVAOs]; | |
GLuint Buffers[NumBuffers]; | |
const GLuint NumVertices = 6; | |
void init(void){ | |
glGenVertexArrays(NumVAOs, VAOs); | |
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); | |
} | |
void display(void){ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glBindVertexArray(VAOs[Triangles]); | |
glDrawArrays(GL_TRIANGLES, 0, NumVertices); | |
glFlush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment