/* * Graphic module for the Gnome Graphics Project * * See the .h file for more information on how to use this library * * Changes: * * When What * --------- ---------------------------------------------------- * * Todo: */ #include #include #include #include #include #include #include "gnomegr.h" #ifndef CALLBACK #define CALLBACK #endif /* CALLBACK */ typedef void (CALLBACK *glucallback)(); /* * Some must-have global variables */ static t_program_start startup_routine; static int screen_width, screen_height; /* * [ END of Some must-have global variables ] */ /* * DEBUG: * * Check for openGL error, if there was one, print it on the screen * This routine is used during debugging of this library. */ /* static void checkgl() { int e; e = glGetError(); if (e != GL_NO_ERROR) { printf("Gl error: 0x%x\n", e); } } */ /* * OpenGL initialization */ static void schematic_init(void) { glDisable(GL_DEPTH_TEST); glClearColor(1.0, 1.0, 1.0, 0.0); } /* * OpenGL initialization */ static void init(void) { schematic_init(); } /*---------- Tesselation callbacks - for drawing the track -----------*/ /* * See comments in the .h file */ void Render(const GnomeBitmap *canvas_ptr) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* Initialize the screen */ glClearColor(1.0, 1.0, 1.0, 1.0); /* Background color is white */ glClear(GL_COLOR_BUFFER_BIT); /* Render the bitmap */ glColor3f(0.0, 0.0, 0.0); /* Bitmap is drawn in black */ glRasterPos2i(0, 0); glBitmap(canvas_ptr->width, canvas_ptr->height, 0, 0, 0, 0, canvas_ptr->bits); glFinish(); /* Display the result */ glutSwapBuffers (); } static void display_cb(void) { } /* ---------- GLUT callbacks --------------*/ /* * glut callback that to notify change in the screen size * Setup the projection matrix. */ static void reshape_cb (int w, int h) { /* Reset the viewport... */ glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLfloat)w, 0.0, (GLfloat)h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); } /* * A hack: * this routine is setup by InitGnomeGr to call the users * main_loop (startup_routine) function. * This hack is here because glutMainLoop must be called, but * it never returns */ void timer_cb(int id) { startup_routine(); } /* ---------- [ End GLUT callbacks ] --------------*/ void InitGr( const GnomeBitmap *canvas_ptr, t_program_start start) { int argc = 1; char *argv[] = {""}; startup_routine = start; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(canvas_ptr->width, canvas_ptr->height); screen_width = canvas_ptr->width; screen_height = canvas_ptr->height; glutInitWindowPosition(0, 0); glutCreateWindow ("Gnome Graphics 2004"); init(); glutTimerFunc(100, timer_cb, 0); glutDisplayFunc(display_cb); glutReshapeFunc(reshape_cb); glutMainLoop(); }