“Hello OpenGL”
During my research period I came across many times on OpenGL when reading AR related articles and paper. Unforturnately I did not have time to actually play with it. So I promised myself that I am going to have to look into it later on (which I believe this is the time!)
Pre-requisite installation
env variable: Go to envirnment setting under “System” in the controrl panel and add PATH to the binary files.
Cbuild: CMake then build lib via VS studio.
“#include” package
For development on Windows platform, include both “GLEW” and “freeglut”
#include <gl/glew.h>
#include <gl/GL.h>
#include <gl/freeglut.h>
“GLFW” will be used to handle the window and the keyboard input
#include <GLFW/glfw3.h>
GLM for math algorithm
#include <glm/glm.hpp>
using namespace glm;
Creating a window
Full usage explanation on window reference should be referred to official API documentation.
1. Configure GLFW setting
glwWindowHint(GLFW_SAMPLES, 4)
means 4x anti-aliasing.
The version of GLFW is “3.3”
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
2. Create window and draw simple content
Create a “window”
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window.\n" );
getchar();
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
Initialise GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
getchar();
glfwTerminate();
return -1;
}
Set “window” to listen to keyboard
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
Enter the main loop and exit when uesr presses Esc button.
do {
glClear(GL_COLOR_BUFFER_BIT); // STUFF HAPPENS HERE glfwSwapBuffers(window);
glfwPollEvents();}while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); glfwTerminate();