Skip to content

Instantly share code, notes, and snippets.

@agjaeger
Last active August 29, 2015 14:18

Revisions

  1. agjaeger revised this gist Apr 9, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions OpenGL Starter Code
    Original file line number Diff line number Diff line change
    @@ -36,10 +36,10 @@ void reshape(GLsizei width, GLsizei height) {
    height = 1; // Avoids divide by zero error
    }

    GLFloat aspect = (GLFloat) width / (GLFloat) height;
    GLFloat aspect = (GLfloat) width / (Glfloat) height;
    glViewport(0, 0, width, height);

    glMatrixMode(PROJECTION);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0f, aspect, 0.1f, 100.0f);
  2. agjaeger revised this gist Apr 9, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion OpenGL Starter Code
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    /*
    g++ main.cpp -lglut -lGL -lGLU
    */
  3. agjaeger created this gist Apr 9, 2015.
    64 changes: 64 additions & 0 deletions OpenGL Starter Code
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@

    /*
    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(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;
    }