IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

opengl et gtk ?


Sujet :

OpenGL

  1. #1
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut opengl et gtk ?
    bonjour,

    j'ai vu qu'il éxistait un widget en gtk+ qui permettait de faire de l'opengl mais je n'ai trouvé aucun exemple, ai-je loupé un lien ?

    Je programme sous linux et je me demande également si ce code gtk+opengl serait portable sous windows.

  2. #2
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    J'ai réussi à faire marcher gtkglext mais :

    j'ai ce code mais ma sphère n'est pas affichée, je n'ai fait que mettre une structure à la place de variables globales par rapport à la demo :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    /* Compile with
     *  gcc `pkg-config --cflags --libs gtk+-2.0 gtkglext-1.0` -o sph sph0.c 
     */
     
    #include <stdlib.h>
    #include <gtk/gtk.h>
    #include <gdk/gdkgl.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
     
    typedef struct _config
    {
    	GdkGLConfig *glconfig;
    	GdkGLWindow *glwindow;
    	GdkGLContext *glcontext;
    	int config_attributes[11];
    	int nb_argt;
    }config;
     
    typedef struct _fenetre
    {
    	config *conf;
    	GtkWidget *win;
    	GtkWidget *zone_gl;
    }fenetre;
     
    static void realize(GtkWidget *widget,gpointer data)
    {
    	fenetre *f=(fenetre *)data;
    	GLUquadricObj *qobj;
    	static GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0};
    	static GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
     
    	/* Create GdkGLWindow for widget->window. */
    	f->conf->glwindow=gdk_gl_window_new(f->conf->glconfig,widget->window,NULL);
     
    	/* Set a background of "None" on window to avoid AIX X server crash */
    	gdk_window_set_back_pixmap(widget->window, NULL, FALSE);
     
    	/* Create OpenGL rendering context. */
    	if (f->conf->glcontext==NULL)
    	{
    		f->conf->glcontext=gdk_gl_context_new(GDK_GL_DRAWABLE(f->conf->glwindow),NULL,TRUE,GDK_GL_RGBA_TYPE);
    		if (f->conf->glcontext == NULL)
    		{
    				g_print ("Erreur pdt la création du contexte OpenGL\n");
    				exit (1);
    		}
    	}
     
    	/*** OpenGL BEGIN ***/
     
    	if (!gdk_gl_drawable_gl_begin(GDK_GL_DRAWABLE(f->conf->glwindow),f->conf->glcontext))
    		return;
     
    	glEnable (GL_DEPTH_TEST);
    	glEnable (GL_LIGHTING);
    	glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    	glLightfv (GL_LIGHT0, GL_POSITION, light_position);
    	glEnable (GL_LIGHT0);
     
    	qobj=gluNewQuadric();
    	gluQuadricDrawStyle(qobj,GLU_FILL);
    	glNewList (1, GL_COMPILE);
    	gluSphere(qobj, 1.0, 20, 20);
    	glEndList();
     
    	glClearColor(1.0, 1.0, 1.0, 1.0);
    	glClearDepth(1.0);
     
    	glViewport(0, 0,widget->allocation.width, widget->allocation.height);
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(40.0, 1.0, 1.0, 10.0);
     
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	gluLookAt(0.0, 0.0, 3.0,0.0, 0.0, 0.0,0.0, 1.0, 0.0);
    	glTranslatef(0.0, 0.0, -3.0);
     
    	gdk_gl_drawable_gl_end(GDK_GL_DRAWABLE(f->conf->glwindow));
    	/*** OpenGL END ***/
    }
     
    static gboolean expose_event (GtkWidget *widget,GdkEventExpose *event,gpointer data)
    {
    	fenetre *f=(fenetre *)data;
     
    	/*** OpenGL BEGIN ***/
    	if (!gdk_gl_drawable_gl_begin(GDK_GL_DRAWABLE(f->conf->glwindow),f->conf->glcontext))
    		return FALSE;
     
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glCallList(1);
     
    	if (gdk_gl_drawable_is_double_buffered (GDK_GL_DRAWABLE(f->conf->glwindow)))
    		gdk_gl_drawable_swap_buffers (GDK_GL_DRAWABLE(f->conf->glwindow));
    	else
    		glFlush ();
     
    	gdk_gl_drawable_gl_end(GDK_GL_DRAWABLE(f->conf->glwindow));
     
    	/*** OpenGL END ***/
     
    	return TRUE;
    }
     
    static void size_allocate (GtkWidget *widget,GtkAllocation *allocation,gpointer data)
    {
    	fenetre *f=(fenetre *)data;
     
    	/*	Synchronize OpenGL rendering pipeline on resizing X window. */
    	if (f->conf->glwindow != NULL)
    		gdk_gl_drawable_wait_gdk(GDK_GL_DRAWABLE(f->conf->glwindow));
    }
     
    /* gtk_drawing_area sends configure_event when it is realized. */
    static gboolean configure_event (GtkWidget *widget,GdkEventConfigure *event,gpointer data)
    {
    	fenetre *f=(fenetre *)data;
     
    	if (f->conf->glwindow==NULL)
    		return FALSE;
     
    	/*** OpenGL BEGIN ***/
     
    	if (!gdk_gl_drawable_gl_begin(GDK_GL_DRAWABLE(f->conf->glwindow),f->conf->glcontext))
    		return FALSE;
     
    	glViewport(0, 0,widget->allocation.width, widget->allocation.height);
     
    	gdk_gl_drawable_gl_end(GDK_GL_DRAWABLE(f->conf->glwindow));
     
    	/*** OpenGL END ***/
     
    	return TRUE;
    }
     
    static void unrealize (GtkWidget *widget,gpointer data)
    {
    	fenetre *f=(fenetre *)data;
     
    	if (f->conf->glcontext != NULL)
    		{
    			g_object_unref (G_OBJECT(f->conf->glcontext));
    			f->conf->glcontext = NULL;
    		}
     
    	if (f->conf->glwindow != NULL)
    		{
    			g_object_unref (G_OBJECT(f->conf->glwindow));
    			f->conf->glwindow = NULL;
    		}
     
    	if (f->conf->glconfig != NULL)
    		{
    			g_object_unref(G_OBJECT(f->conf->glconfig));
    			f->conf->glconfig=NULL;
    		}
    }
     
    void creation_fenetre(fenetre *f)
    {
    	GtkWidget *vbox, *bouton;
     
    	/* Fenetre principale, on param les couleurs (colormap) de la fenetre openGL et mise à jour des enfant */
    	f->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    	gtk_window_set_title (GTK_WINDOW (f->win), "low-level");
    	gtk_widget_set_colormap(f->win,gdk_gl_config_get_colormap(f->conf->glconfig));
    	gtk_container_set_reallocate_redraws(GTK_CONTAINER(f->win),TRUE);
    	g_signal_connect(G_OBJECT(f->win),"delete_event",G_CALLBACK (gtk_main_quit), NULL);
     
    	/* vbox pour remplir la fenêtre */
    	vbox = gtk_vbox_new (FALSE, 0);
    	gtk_container_add(GTK_CONTAINER(f->win),vbox);
     
    	/* drawing-area (OpenGL) */
    	f->zone_gl= gtk_drawing_area_new ();
    	gtk_widget_set_size_request(f->zone_gl, 200, 200);
    	gtk_widget_set_colormap (f->zone_gl,gdk_gl_config_get_colormap (f->conf->glconfig));
    	gtk_widget_set_double_buffered(f->zone_gl,TRUE);
    	gtk_box_pack_start (GTK_BOX(vbox),f->zone_gl, TRUE, TRUE, 0);
    	g_signal_connect_after(G_OBJECT(f->zone_gl),"realize",G_CALLBACK(realize), f);
    	g_signal_connect(G_OBJECT(f->zone_gl),"expose_event",G_CALLBACK(expose_event), f);
    	g_signal_connect(G_OBJECT(f->zone_gl),"size_allocate",G_CALLBACK(size_allocate), f);
    	g_signal_connect(G_OBJECT(f->zone_gl),"configure_event",G_CALLBACK(configure_event), f);
    	g_signal_connect(G_OBJECT(f->zone_gl),"unrealize",G_CALLBACK(unrealize), f);
     
    	bouton=gtk_button_new_with_label("Quitter");
    	gtk_box_pack_start (GTK_BOX(vbox),bouton, TRUE, TRUE, 0);
    	g_signal_connect(GTK_OBJECT(bouton),"clicked",G_CALLBACK(gtk_main_quit),NULL);
     
    	/* Affichage de la fenêtre */
    	gtk_widget_show_all(f->win);
    }
     
    void init_var(config *c, fenetre *f)
    {
    	int i;
    	int gdk_gl_conf[]={GDK_GL_DOUBLEBUFFER,GDK_GL_RGBA,GDK_GL_RED_SIZE,1,
    					   GDK_GL_GREEN_SIZE,1,GDK_GL_BLUE_SIZE,1,GDK_GL_DEPTH_SIZE,12,GDK_GL_ATTRIB_LIST_NONE};
     
    	c->nb_argt=11;
    	for(i=0;i<c->nb_argt;i++)
    		c->config_attributes[i]=gdk_gl_conf[i];
    	c->glconfig=NULL;
    	c->glwindow=NULL;
    	c->glcontext=NULL;
    	f->conf=c;
    }
     
    int main(int argc,char **argv)
    {
    	fenetre f;
    	config c;
    	GtkWidget *vbox, *bouton;
     
    	/* Initialisation */
    	init_var(&c,&f);
     
    	/* Init GTK et GdkGLExt */
    	gtk_init (&argc, &argv);
    	gdk_gl_init (&argc, &argv);
     
    	/* Try double-buffered visual */
    	c.glconfig=gdk_gl_config_new(&(c.config_attributes[0]));
    	if (c.glconfig==NULL)
        {
          g_print ("Pas de dble buffer\n");
          /* Try single-buffered visual */
          c.glconfig=gdk_gl_config_new (&(c.config_attributes[1]));
          if (c.glconfig==NULL)
            {
              g_print ("Pas d'openGL\n");
              exit (1);
            }
        }
     
    	/* création de la fentre+zone_OpenGL+interface */
    	creation_fenetre(&f);
     
    	/* Destroy the GLX context explicitly when application is terminated. */
    	gtk_quit_add_destroy(gtk_main_level()+1,GTK_OBJECT(f.zone_gl));
     
    	gtk_main ();
     
    	return 0;
    }
    le code original est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    /*
     * low-level.c:
     * Low-level GdkGLExt example. This program uses only gdkgl stuff.
     *
     * written by Naofumi Yasufuku  <naofumi@users.sourceforge.net>
     */
     
    #include <stdlib.h>
     
    #include <gtk/gtk.h>
     
    #include <gdk/gdkgl.h>
     
    #ifdef G_OS_WIN32
    #define WIN32_LEAN_AND_MEAN 1
    #include <windows.h>
    #endif
     
    #include <GL/gl.h>
    #include <GL/glu.h>
     
    static GdkGLConfig *glconfig = NULL;
    static GdkGLWindow *glwindow = NULL;
    static GdkGLContext *glcontext = NULL;
     
    static const int config_attributes[] = {
      GDK_GL_DOUBLEBUFFER,
      GDK_GL_RGBA,
      GDK_GL_RED_SIZE,        1,
      GDK_GL_GREEN_SIZE,      1,
      GDK_GL_BLUE_SIZE,       1,
      GDK_GL_DEPTH_SIZE,      12,
      GDK_GL_ATTRIB_LIST_NONE
    };
     
    static void
    realize (GtkWidget *widget,
             gpointer   data)
    {
      GLUquadricObj *qobj;
      static GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0};
      static GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
     
      /*
       * Create GdkGLWindow for widget->window.
       */
     
      glwindow = gdk_gl_window_new (glconfig,
                                    widget->window,
                                    NULL);
     
      /* Set a background of "None" on window to avoid AIX X server crash */
      gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
     
      /*
       * Create OpenGL rendering context.
       */
     
      if (glcontext == NULL)
        {
          glcontext = gdk_gl_context_new (GDK_GL_DRAWABLE (glwindow),
                                          NULL,
                                          TRUE,
                                          GDK_GL_RGBA_TYPE);
          if (glcontext == NULL)
            {
              g_print ("Connot create the OpenGL rendering context\n");
              exit (1);
            }
     
          g_print ("The OpenGL rendering context is created\n");
        }
     
      /*** OpenGL BEGIN ***/
     
      if (!gdk_gl_drawable_gl_begin (GDK_GL_DRAWABLE (glwindow), glcontext))
        return;
     
      qobj = gluNewQuadric ();
      gluQuadricDrawStyle (qobj, GLU_FILL);
      glNewList (1, GL_COMPILE);
      gluSphere (qobj, 1.0, 20, 20);
      glEndList ();
     
      glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
      glLightfv (GL_LIGHT0, GL_POSITION, light_position);
      glEnable (GL_LIGHTING);
      glEnable (GL_LIGHT0);
      glEnable (GL_DEPTH_TEST);
     
      glClearColor (1.0, 1.0, 1.0, 1.0);
      glClearDepth (1.0);
     
      glViewport (0, 0,
    	      widget->allocation.width, widget->allocation.height);
     
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity ();
      gluPerspective (40.0, 1.0, 1.0, 10.0);
     
      glMatrixMode (GL_MODELVIEW);
      glLoadIdentity ();
      gluLookAt (0.0, 0.0, 3.0,
    	     0.0, 0.0, 0.0,
    	     0.0, 1.0, 0.0);
      glTranslatef (0.0, 0.0, -3.0);
     
      gdk_gl_drawable_gl_end (GDK_GL_DRAWABLE (glwindow));
     
      /*** OpenGL END ***/
    }
     
    static void
    size_allocate (GtkWidget     *widget,
                   GtkAllocation *allocation,
                   gpointer       data)
    {
      /*  Synchronize OpenGL rendering pipeline on resizing X window. */
      if (glwindow != NULL)
        gdk_gl_drawable_wait_gdk (GDK_GL_DRAWABLE (glwindow));
    }
     
    static gboolean
    configure_event (GtkWidget         *widget,
                     GdkEventConfigure *event,
                     gpointer           data)
    {
      /* gtk_drawing_area sends configure_event when it is realized. */
      if (glwindow == NULL)
        return FALSE;
     
      /*** OpenGL BEGIN ***/
     
      if (!gdk_gl_drawable_gl_begin (GDK_GL_DRAWABLE (glwindow), glcontext))
        return FALSE;
     
      glViewport (0, 0,
    	      widget->allocation.width, widget->allocation.height);
     
      gdk_gl_drawable_gl_end (GDK_GL_DRAWABLE (glwindow));
     
      /*** OpenGL END ***/
     
      return TRUE;
    }
     
    static gboolean
    expose_event (GtkWidget      *widget,
                  GdkEventExpose *event,
                  gpointer        data)
    {
      /*** OpenGL BEGIN ***/
     
      if (!gdk_gl_drawable_gl_begin (GDK_GL_DRAWABLE (glwindow), glcontext))
        return FALSE;
     
      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
      glCallList (1);
     
      if (gdk_gl_drawable_is_double_buffered (GDK_GL_DRAWABLE (glwindow)))
        gdk_gl_drawable_swap_buffers (GDK_GL_DRAWABLE (glwindow));
      else
        glFlush ();
     
      gdk_gl_drawable_gl_end (GDK_GL_DRAWABLE (glwindow));
     
      /*** OpenGL END ***/
     
      return TRUE;
    }
     
    static void
    unrealize (GtkWidget *widget,
               gpointer   data)
    {
      if (glcontext != NULL)
        {
          g_object_unref (G_OBJECT (glcontext));
          glcontext = NULL;
        }
     
      if (glwindow != NULL)
        {
          g_object_unref (G_OBJECT (glwindow));
          glwindow = NULL;
        }
     
      if (glconfig != NULL)
        {
          g_object_unref (G_OBJECT (glconfig));
          glconfig = NULL;
        }
    }
     
    static void
    print_gl_config_attrib (GdkGLConfig *glconfig,
                            const gchar *attrib_str,
                            int          attrib,
                            gboolean     is_boolean)
    {
      int value;
     
      g_print ("%s = ", attrib_str);
      if (gdk_gl_config_get_attrib (glconfig, attrib, &value))
        {
          if (is_boolean)
            g_print ("%s\n", value == TRUE ? "TRUE" : "FALSE");
          else
            g_print ("%d\n", value);
        }
      else
        g_print ("*** Cannot get %s attribute value\n", attrib_str);
    }
     
    static void
    examine_gl_config_attrib (GdkGLConfig *glconfig)
    {
      g_print ("\nOpenGL visual configurations :\n\n");
     
      g_print ("gdk_gl_config_is_rgba (glconfig) = %s\n",
               gdk_gl_config_is_rgba (glconfig) ? "TRUE" : "FALSE");
      g_print ("gdk_gl_config_is_double_buffered (glconfig) = %s\n",
               gdk_gl_config_is_double_buffered (glconfig) ? "TRUE" : "FALSE");
      g_print ("gdk_gl_config_is_stereo (glconfig) = %s\n",
               gdk_gl_config_is_stereo (glconfig) ? "TRUE" : "FALSE");
      g_print ("gdk_gl_config_has_alpha (glconfig) = %s\n",
               gdk_gl_config_has_alpha (glconfig) ? "TRUE" : "FALSE");
      g_print ("gdk_gl_config_has_depth_buffer (glconfig) = %s\n",
               gdk_gl_config_has_depth_buffer (glconfig) ? "TRUE" : "FALSE");
      g_print ("gdk_gl_config_has_stencil_buffer (glconfig) = %s\n",
               gdk_gl_config_has_stencil_buffer (glconfig) ? "TRUE" : "FALSE");
      g_print ("gdk_gl_config_has_accum_buffer (glconfig) = %s\n",
               gdk_gl_config_has_accum_buffer (glconfig) ? "TRUE" : "FALSE");
     
      g_print ("\n");
     
      print_gl_config_attrib (glconfig, "GDK_GL_USE_GL",           GDK_GL_USE_GL,           TRUE);
      print_gl_config_attrib (glconfig, "GDK_GL_BUFFER_SIZE",      GDK_GL_BUFFER_SIZE,      FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_LEVEL",            GDK_GL_LEVEL,            FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_RGBA",             GDK_GL_RGBA,             TRUE);
      print_gl_config_attrib (glconfig, "GDK_GL_DOUBLEBUFFER",     GDK_GL_DOUBLEBUFFER,     TRUE);
      print_gl_config_attrib (glconfig, "GDK_GL_STEREO",           GDK_GL_STEREO,           TRUE);
      print_gl_config_attrib (glconfig, "GDK_GL_AUX_BUFFERS",      GDK_GL_AUX_BUFFERS,      FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_RED_SIZE",         GDK_GL_RED_SIZE,         FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_GREEN_SIZE",       GDK_GL_GREEN_SIZE,       FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_BLUE_SIZE",        GDK_GL_BLUE_SIZE,        FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_ALPHA_SIZE",       GDK_GL_ALPHA_SIZE,       FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_DEPTH_SIZE",       GDK_GL_DEPTH_SIZE,       FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_STENCIL_SIZE",     GDK_GL_STENCIL_SIZE,     FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_RED_SIZE",   GDK_GL_ACCUM_RED_SIZE,   FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_GREEN_SIZE", GDK_GL_ACCUM_GREEN_SIZE, FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_BLUE_SIZE",  GDK_GL_ACCUM_BLUE_SIZE,  FALSE);
      print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_ALPHA_SIZE", GDK_GL_ACCUM_ALPHA_SIZE, FALSE);
     
      g_print ("\n");
    }
     
    int
    main (int   argc,
          char *argv[])
    {
      gint major, minor;
     
      GtkWidget *window;
      GtkWidget *vbox;
      GtkWidget *drawing_area;
      GtkWidget *button;
     
      /*
       * Init GTK.
       */
     
      gtk_init (&argc, &argv);
     
      /*
       * Init GdkGLExt.
       */
     
      gdk_gl_init (&argc, &argv);
     
      /*
       * Query OpenGL extension version.
       */
     
      gdk_gl_query_version (&major, &minor);
      g_print ("\nOpenGL extension version - %d.%d\n",
               major, minor);
     
      /*
       * Configure OpenGL-capable visual.
       */
     
      /* Try double-buffered visual */
      glconfig = gdk_gl_config_new (&config_attributes[0]);
      if (glconfig == NULL)
        {
          g_print ("*** Cannot find the double-buffered visual.\n");
          g_print ("*** Trying single-buffered visual.\n");
     
          /* Try single-buffered visual */
          glconfig = gdk_gl_config_new (&config_attributes[1]);
          if (glconfig == NULL)
            {
              g_print ("*** No appropriate OpenGL-capable visual found.\n");
              exit (1);
            }
        }
     
      examine_gl_config_attrib (glconfig);
     
      /*
       * Top-level window.
       */
     
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title (GTK_WINDOW (window), "low-level");
     
      /*
       * If window manager doesn't watch the WM_COLORMAP_WINDOWS property on
       * the top-level window, we have to set OpenGL window's colormap to the
       * top-level window.
       */
      gtk_widget_set_colormap (window,
                               gdk_gl_config_get_colormap (glconfig));
     
      /* Get automatically redrawn if any of their children changed allocation. */
      gtk_container_set_reallocate_redraws (GTK_CONTAINER (window), TRUE);
     
      g_signal_connect (G_OBJECT (window), "delete_event",
                        G_CALLBACK (gtk_main_quit), NULL);
     
      /*
       * VBox.
       */
     
      vbox = gtk_vbox_new (FALSE, 0);
      gtk_container_add (GTK_CONTAINER (window), vbox);
      gtk_widget_show (vbox);
     
      /*
       * Drawing area for drawing OpenGL scene.
       */
     
      drawing_area = gtk_drawing_area_new ();
      gtk_widget_set_size_request (drawing_area, 200, 200);
     
      /* Set OpenGL-capable colormap. */
      gtk_widget_set_colormap (drawing_area,
                               gdk_gl_config_get_colormap (glconfig));
     
      /* Disable backing store feature of the widget. */
      gtk_widget_set_double_buffered (drawing_area, FALSE);
     
      g_signal_connect_after (G_OBJECT (drawing_area), "realize",
                              G_CALLBACK (realize), NULL);
      g_signal_connect (G_OBJECT (drawing_area), "size_allocate",
                        G_CALLBACK (size_allocate), NULL);
      g_signal_connect (G_OBJECT (drawing_area), "configure_event",
    		    G_CALLBACK (configure_event), NULL);
      g_signal_connect (G_OBJECT (drawing_area), "expose_event",
    		    G_CALLBACK (expose_event), NULL);
      g_signal_connect (G_OBJECT (drawing_area), "unrealize",
    		    G_CALLBACK (unrealize), NULL);
     
      gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
     
      gtk_widget_show (drawing_area);
     
      /*
       * Simple quit button.
       */
     
      button = gtk_button_new_with_label ("Quit");
     
      g_signal_connect (G_OBJECT (button), "clicked",
                        G_CALLBACK (gtk_main_quit), NULL);
     
      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
     
      gtk_widget_show (button);
     
      /*
       * Show window.
       */
     
      gtk_widget_show (window);
     
      /*
       * Main loop.
       */
     
      /* Destroy the GLX context explicitly when application is terminated. */
      gtk_quit_add_destroy (gtk_main_level () + 1,
    			GTK_OBJECT (drawing_area));
     
      gtk_main ();
     
      return 0;
    }
    EDIT
    j'ai trouvé : c'est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    gtk_widget_set_double_buffered(f->zone_gl,FALSE);
    et non
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    gtk_widget_set_double_buffered(f->zone_gl,TRUE);

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. OpenGL et GTK+
    Par mister3957 dans le forum OpenGL
    Réponses: 0
    Dernier message: 06/02/2010, 17h32
  2. opengl + interface GTK
    Par lefrere dans le forum OpenGL
    Réponses: 2
    Dernier message: 09/01/2009, 17h08
  3. [Linux] OpenGL et GTK
    Par pot dans le forum OpenGL
    Réponses: 8
    Dernier message: 14/04/2005, 19h10
  4. GTK et OPENGL avec gtkglarea
    Par Vincent|Dev dans le forum OpenGL
    Réponses: 1
    Dernier message: 09/02/2005, 13h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo