OpenGL Programming/reference/basic testing app

From Wikibooks, open books for an open world
< OpenGL Programming‎ | reference
Jump to: navigation, search

This is the basic opengl testing app to use with examples in the function reference section.

To run many examples you will only need to replace the setup or display function.

#ifndef WIN32 //if using windows then do windows specific stuff.
#define WIN32_LEAN_AND_MEAN //remove MFC overhead from windows.h witch can cause slowness
#define WIN32_EXTRA_LEAN

#include <windows.h>
#endif

#include <GL/gl.h>
#include <glut.h>
#include <GL/glu.h>
#include <conio.h>//needed for getch

void setup(void)
{
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

void display(void)
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        /* drawing commands would go below here, if we had any yet... */

        /* drawing commands would go above here, if we had any yet... */
        glutSwapBuffers();
}

int main(int argc, char *argv[])
{
       glutInit(&argc, argv);
       glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
       glutInitWindowSize(800,600);
       glutCreateWindow("Hello World");
                
        setup();
        glutDisplayFunc(display);

        glutMainLoop();

        getch();//pause here to see results or lack there of
        return 0;
}