Last active
August 29, 2015 14:18
-
-
Save agjaeger/ca288407ad1c57d8a2d6 to your computer and use it in GitHub Desktop.
This is starter code for OpenGL 4.0 in C++ using FreeGlut
This file contains hidden or 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
/* | |
g++ main.cpp -lglut -lGL -lGLU | |
*/ | |
#include "GL/freeglut.h" | |
#include "GL/gl.h" | |
char title[] = "OpenGL Window"; | |
void initGL() { | |
glClearColor(0.93f, 0.93f, 0.93f, 1.0f); | |
glClearDepth(1.0f); | |
glEnable(GL_DEPTH_TEST); // Enable for z-culling | |
glDepthFunc(GL_LEQUAL); | |
glShadeModel(GL_SMOOTH); | |
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | |
} | |
void display() { | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
/* | |
Insert Code Here | |
*/ | |
glutSwapBuffers(); | |
} | |
void reshape(GLsizei width, GLsizei height) { | |
if(height == 0) { | |
height = 1; // Avoids divide by zero error | |
} | |
GLFloat aspect = (GLfloat) width / (Glfloat) height; | |
glViewport(0, 0, width, height); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
gluPerspective(45.0f, aspect, 0.1f, 100.0f); | |
} | |
int main(int argc, char **argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE); | |
glutInitWindowSize(640, 480); | |
glutInitWindowPosition(50, 50); | |
glutCreateWindow(title); | |
glutDisplayFunc(display); | |
glutReshapeFunc(reshape); | |
initGL(); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment