Пример #1
0
int
init_opengl_gdk_3Demu( GdkDrawable * drawable) {
  GdkGLConfig *glconfig;

  /* create the off screen pixmap */
  target_pixmap = gdk_pixmap_new ( drawable, 256, 192, -1);

  if ( target_pixmap == NULL) {
      g_print ("*** Failed to create pixmap.\n");
      return 0;
  }

  glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGBA   |
                                        GDK_GL_MODE_DEPTH  |
                                        GDK_GL_MODE_STENCIL |
                                        GDK_GL_MODE_SINGLE));
  if (glconfig == NULL)
    {
      g_print ("*** No appropriate OpenGL-capable visual found.\n");
      return 0;
    }

  /*
   * Set OpenGL-capability to the pixmap
   */

  gldrawable = GDK_GL_DRAWABLE (gdk_pixmap_set_gl_capability (target_pixmap,
                                                              glconfig,
                                                              NULL));

  if ( gldrawable == NULL) {
    g_print ("Failed to create the GdkGLPixmap\n");
    return 0;
  }

  glcontext = gdk_gl_context_new (gldrawable,
                                  NULL,
                                  FALSE,
                                  GDK_GL_RGBA_TYPE);
  if (glcontext == NULL)
    {
      g_print ("Connot create the OpenGL rendering context\n");
      return 0;
    }


	oglrender_init = _oglrender_init;
	oglrender_beginOpenGL = _oglrender_beginOpenGL;
	oglrender_endOpenGL = _oglrender_endOpenGL;


  return 1;
}
Пример #2
0
	/// Returns a "global" (to the document) gdkgl context that can be used to share display lists
	GdkGLContext* gdkgl_share_list()
	{
		if(!m_gdkgl_share_list)
		{
			GdkGLConfig* const config = gdk_gl_config_new_by_mode(
				static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH));
			return_val_if_fail(config, 0);

      GdkPixmap* const pixmap = gdk_pixmap_new(0, 8, 8, gdk_gl_config_get_depth(config));
			return_val_if_fail(pixmap, 0);

			GdkGLPixmap* const glpixmap = gdk_pixmap_set_gl_capability(pixmap, config, 0);
			return_val_if_fail(glpixmap, 0);

			GdkGLContext* const context = gdk_gl_context_new(
				gdk_pixmap_get_gl_drawable(pixmap), 0, true, GDK_GL_RGBA_TYPE);
			return_val_if_fail(context, 0);

			m_gdkgl_share_list = context;
		}

		return m_gdkgl_share_list;
	}
Пример #3
0
static gboolean
configure_event (GtkWidget         *widget,
                 GdkEventConfigure *event,
                 gpointer           data)
{
  GdkGLDrawable *gldrawable;
  static gboolean is_initialized = FALSE;

  /*
   * Create an OpenGL off-screen rendering area.
   */

  if (pixmap != NULL)
    g_object_unref (G_OBJECT (pixmap));

  pixmap = gdk_pixmap_new (widget->window,
			   widget->allocation.width,
			   widget->allocation.height,
                           -1);

  /*
   * Set OpenGL-capability to the pixmap
   */

  gldrawable = GDK_GL_DRAWABLE (gdk_pixmap_set_gl_capability (pixmap,
                                                              glconfig,
                                                              NULL));

  /*
   * Create OpenGL rendering context (not direct).
   */

  if (glcontext == NULL)
    {
      glcontext = gdk_gl_context_new (gldrawable,
                                      NULL,
                                      FALSE,
                                      GDK_GL_RGBA_TYPE);
      if (glcontext == NULL)
        {
          g_print ("Connot create the OpenGL rendering context\n");
          if (gtk_main_level () != 0)
            gtk_main_quit ();
          return TRUE;
        }

      g_print ("The OpenGL rendering context is created\n");
    }

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
    goto NO_GL;

  if (!is_initialized)
    {
      init ();
      is_initialized = TRUE;
    }

  glViewport (0, 0,
              widget->allocation.width, widget->allocation.height);

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  /* Sync. */
  gdk_gl_drawable_wait_gl (gldrawable);

  /* GDK rendering. */
  gdk_draw_rectangle (GDK_DRAWABLE (gldrawable),
		      widget->style->black_gc,
		      TRUE,
		      widget->allocation.width/10,
		      widget->allocation.height/10,
		      widget->allocation.width*8/10,
		      widget->allocation.height*8/10);

  /* Sync. */
  gdk_gl_drawable_wait_gdk (gldrawable);

  glCallList (1);

  glFlush ();

  gdk_gl_drawable_gl_end (gldrawable);
  /*** OpenGL END ***/

 NO_GL:

  return TRUE;
}
Пример #4
0
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 ***/
}