1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| /* initialisation */
void realize(GtkWidget *widget, gpointer data)
{
donnees *d=(donnees *) data;
GdkGLContext *glcontext=gtk_widget_get_gl_context(widget);
GdkGLDrawable *gldrawable=gtk_widget_get_gl_drawable(widget);
GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0},light_position[] = {1.0, 1.0, 1.0, 0.0};
if(!gdk_gl_drawable_gl_begin(gldrawable,glcontext))
return;
/* début openGL */
glClearColor(0.0,0.0,0.0,0.0);
glClearDepth (1.0);
glShadeModel(GL_FLAT);
/* glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv (GL_LIGHT0, GL_POSITION, light_position);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_DEPTH_TEST);*/
/* fin OpenGL */
gdk_gl_drawable_gl_end(gldrawable);
}
/* chgt de configuration (redimensionnement etc...) */
gboolean configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
{
donnees *d=(donnees *) data;
GdkGLContext *glcontext=gtk_widget_get_gl_context(widget);
GdkGLDrawable *gldrawable=gtk_widget_get_gl_drawable(widget);
GLfloat l=widget->allocation.width, h=widget->allocation.height;
if(!gdk_gl_drawable_gl_begin(gldrawable,glcontext))
return FALSE;
glViewport(0,0,(GLsizei) l,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
gdk_gl_drawable_gl_end(gldrawable);
return TRUE;
}
/* "redessinage" de la scène OpenGL */
gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
donnees *d=(donnees *) data;
GdkGLContext *glcontext=gtk_widget_get_gl_context(widget);
GdkGLDrawable *gldrawable=gtk_widget_get_gl_drawable(widget);
GLUquadricObj *quad;
if(!gdk_gl_drawable_gl_begin(gldrawable,glcontext))
return FALSE;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* pour gérer seulement la sph (push et pop) */
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glTranslatef(30.0,-1.0,1.0);
quad=gluNewQuadric();
gluQuadricDrawStyle(quad,GLU_FILL);
gluQuadricNormals(quad, GLU_SMOOTH);
/* gluQuadricOrientation(quad, GLU_OUTSIDE); */
gluSphere(quad,10.0,10,10);
glPopMatrix ();
glPushMatrix();
glRotatef(d->spin,0.0, 0.0, 1.0);
glTranslatef(1.0,2.0,0.0);
glColor3f(1.0,0.0,1.0);
glRectf(-25.0,-25.0,25.0,25.0);
glPopMatrix ();
glPushMatrix();
glTranslatef(1.0,0.0,0.0);
glColor3f(1.0,1.0,0.0);
glRectf(-25.0,-25.0,25.0,25.0);
glPopMatrix ();
/* Gestion de(s) buffer(s) */
if(gdk_gl_drawable_is_double_buffered(gldrawable))
gdk_gl_drawable_swap_buffers(gldrawable);
else
glFlush();
gluDeleteQuadric(quad);
gdk_gl_drawable_gl_end(gldrawable);
return TRUE;
} |
Partager