Skip to content

esmitt/OGLCube

Repository files navigation

Cube Rendering using OpenGL 4.0

This is a template code for use OpenGL 4.0 using FreeGLUT and C++. The code is shader-based using freeglut as window manager, GLM to the data structures (e.g. vec4, vec3, ma4x4, and so on) and GLEW to manage the libraries necessaries in shaders.

The display is just a cube where each face is split into 2 triangles. For convenience and simplicity, 36 vertexes are used to cube definition, 2 triangles * 3 vertexes each * 6 faces = 36. Also, a vertex is composed by v=(x,y,z,w) for simplicity too.

The class GLSLProgram was written by me to loading/creating/managing of shaders. For example, to load and assign attributes and uniforms is just:
// this is on the variable defintion
CGLSLProgram program;
...
// this is on the init function
program.loadShader(SHADER_PATH, CGLSLProgram::{VERTEX or TESSELLATION or GEOMETRY or FRAGMENT});
program.create_link();
program.enable();
program.addAttribute(ATTRIB_NAME);
program.addUniform(UNIFORM_NAME);
program.addSubroutine(SUBROUTINE_NAME);
program.addUniformSubroutine(UNIFORM_SUBR);
program.disable();

Next, in the display function, only using enable and disable function, the program can be activated. It was developed using Visual Studio 2012 compiler because its using #pragma comment to link the .lib of freeglut and GLEW.

This code is only to be used as a template. There is no efficiency inside the code.