5f134637 | /// Inlcudes |
b23636c9 | #include "MicroGlut.h" |
5f134637 | #include "GL_utilities.h" /// Defines #define ARRAY_COUNT(ARRAY) (sizeof(ARRAY)/sizeof(*(ARRAY))) |
b23636c9 | |
5f134637 | /// Globals GLuint vertexArray; GLfloat positions[] = |
b23636c9 | { |
4f77e6b0 | -0.5f, -0.5f, 0.0f, -0.5f, +0.5f, 0.0f, +0.5f, -0.5f, 0.0f, |
b23636c9 | }; |
5f134637 | /// Init |
b23636c9 | void init(void) { |
4f77e6b0 | // GL inits. glClearColor(0.2, 0.2, 0.5, 0.0); glDisable(GL_DEPTH_TEST); printError("init GL"); // Load and compile shader. GLuint program = loadShaders("tsbk07.vert", "tsbk07.frag"); printError("init shader"); // Allocate and activate Vertex Array Object (VAO), used for uploading // the geometry. glGenVertexArrays(1, &vertexArray); glBindVertexArray(vertexArray); // Allocate and activate Vertex Buffer Objects (VBO), for vertex data. GLint positionLocation = glGetAttribLocation(program, "inPosition"); GLuint positionBuffer; glGenBuffers(1, &positionBuffer); glBindBuffer(GL_ARRAY_BUFFER, positionBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(positionLocation); printError("init VBOs"); |
b23636c9 | } |
5f134637 | /// Display |
b23636c9 | void display(void) { |
4f77e6b0 | // Clear the screen. glClear(GL_COLOR_BUFFER_BIT); |
b23636c9 | |
4f77e6b0 | // Select VAO. glBindVertexArray(vertexArray); |
5f134637 | |
4f77e6b0 | // Draw. glDrawArrays(GL_TRIANGLES, 0, ARRAY_COUNT(positions)/3); printError("display draw"); |
5f134637 | |
4f77e6b0 | // Show on the screen. glutSwapBuffers(); |
b23636c9 | } |
5f134637 | /// Main int main(int argc, char * argv[]) |
b23636c9 | { |
4f77e6b0 | glutInit(&argc, argv); glutInitContextVersion(3, 2); glutInitWindowSize(600, 600); glutCreateWindow("TSBK07"); |
5f134637 | |
4f77e6b0 | glutDisplayFunc(display); |
5f134637 | |
4f77e6b0 | dumpInfo(); init(); glutMainLoop(); |
b23636c9 | } |