5f134637 |
/// Inlcudes
|
60392b05 |
#include <iostream>
|
b23636c9 |
#include "MicroGlut.h"
|
5f134637 |
#include "GL_utilities.h"
/// Defines
#define ARRAY_COUNT(ARRAY) (sizeof(ARRAY)/sizeof(*(ARRAY)))
|
b23636c9 |
|
5f134637 |
/// Globals
GLuint vertexArray;
|
cc373d1c |
GLfloat positions[][3] =
|
b23636c9 |
{
|
cc373d1c |
{-0.5f, -0.5f, 0.0f},
{-0.5f, +0.5f, 0.0f},
{+0.5f, -0.5f, 0.0f},
|
b23636c9 |
};
|
60392b05 |
/// Debug message callback
void APIENTRY debugMessageCallback(
GLenum /* source */,
GLenum /* type */,
GLuint /* id */,
GLenum /* severity */,
GLsizei /* length */,
GLchar const * message,
void const * /* userParam */
)
{
std::cerr << message << std::endl;
}
|
5f134637 |
/// Init
|
b23636c9 |
void init(void)
{
|
60392b05 |
// Debug message callback.
// Requires OpenGL 4.3 or the GL_KHR_debug extension (which is not hardware
// dependent and supported almost everywhere *except* MacOS).
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(debugMessageCallback, nullptr);
|
4f77e6b0 |
// GL inits.
glClearColor(0.2, 0.2, 0.5, 0.0);
glDisable(GL_DEPTH_TEST);
// Load and compile shader.
GLuint program = loadShaders("tsbk07.vert", "tsbk07.frag");
// 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);
|
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.
|
cc373d1c |
glDrawArrays(GL_TRIANGLES, 0, ARRAY_COUNT(positions));
|
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 |
}
|