#include "..\glut.h" #include #include #include #include "button.cpp" /* Global object declarations */ const int window_width = 500; const int window_height = 500; bool polygon_on = false; PushButton OKButton(20, 450, 50, 30, "ON/OFF"); PushButton QuitButton(420, 450, 50, 30, "Quit", 1.0, 0.0, 0.0); const GLubyte my_pattern[4][32] = {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }; void my_init() { glClearColor(0.6, 0.6, 0.2, 1.0); glEnable(POLYGON_STIPPLE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 500.0); glMatrixMode(GL_MODELVIEW); } // end of my_init() void my_display() { glClear(GL_COLOR_BUFFER_BIT); OKButton.Draw(); QuitButton.Draw(); if (polygon_on) { glPolygonStipple((GLubyte *) my_pattern ); glBegin(GL_POLYGON); glColor3f(0.3, 0.3, 1.0); glVertex2i(300, 50); glColor3f(1.0, 0.3, 0.3); glVertex2i(50, 450); glColor3f(0.3, 1.0, 0.3); glVertex2i(410, 400); glEnd(); } // end if glFlush(); } // end of my_display() void my_mouse_callback(int mouse_btn, int state, int x, int y) { if (mouse_btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN && OKButton.WasClicked(x, y)) { OKButton.Depress(); } if (mouse_btn == GLUT_LEFT_BUTTON && state == GLUT_UP && OKButton.WasClicked(x, y)) { polygon_on = !polygon_on; OKButton.Draw(); my_display(); } if (mouse_btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN && QuitButton.WasClicked(x, y)) { QuitButton.Depress(); } if (mouse_btn == GLUT_LEFT_BUTTON && state == GLUT_UP && QuitButton.WasClicked(x, y)) { QuitButton.Draw(); exit(0); } } // end of my_mouse_callback() void main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize(window_width, window_height); glutInitWindowPosition(0, 0); glutCreateWindow("OpenGL PushButton Example"); glutDisplayFunc(my_display); glutMouseFunc(my_mouse_callback); my_init(); glutMainLoop(); }