// This code example is created for educational purpose // by Thorsten Thormaehlen (contact: www.thormae.de). // It is distributed without any warranty. #include // we use glut here as window manager #include using namespace std; class Renderer { public: void init() {} void resize(int w, int h) { glViewport(0, 0, w, h); } void display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_TRIANGLES); glVertex3f(-0.5f, -0.5f, 0.0f); // vertex on the left glVertex3f(0.5f, -0.5f, 0.0f); // vertex on the right glVertex3f(0.0f, 0.5f, 0.0f); // vertex at the top of the triangle glEnd(); } void dispose() { } }; //this is a static pointer to a Renderer used in the glut callback functions static Renderer *renderer; //glut static callbacks start static void glutResize(int w, int h) { renderer->resize(w, h); } static void glutDisplay() { renderer->display(); glutSwapBuffers(); } static void glutClose() { renderer->dispose(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(320, 320); glutCreateWindow("GlutFirstTriangle"); glutDisplayFunc(glutDisplay); glutReshapeFunc(glutResize); glutCloseFunc(glutClose); renderer = new Renderer; renderer->init(); glutMainLoop(); }