#include #include #include using namespace std; void drawfunc(void); void keyfunc(unsigned char, int, int); void myglinit(void); char *easel; int width, height; int main(int argc, char **argv) { // width and height of the window width = height = 256; // create a char buffer, 3 bytes per pixel of the window easel = new char[width*height*3]; // initialize the glut system and create a window glutInitWindowSize(width, height); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("example"); // initialize some OpenGL state myglinit(); // set callback functions. drawfunc is the function that gets // called automatically as fast as possible. keyfunc only is // invoked if the user hits a keyboard key. glutDisplayFunc(drawfunc); glutKeyboardFunc(keyfunc); // start the main glut loop, no code runs after this glutMainLoop(); } void setpixel(char *buf, int x, int y, int r, int g, int b) { buf[(y*width+x)*3+0] = r; buf[(y*width+x)*3+1] = g; buf[(y*width+x)*3+2] = b; } // main draw function, gets called over and over, as fast as possible void drawfunc(void) { int i,j; cout << "in drawfunc" << endl; // set first half of buffer to red for (i=0; i