示例#1
0
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;
}
示例#2
0
static GdkGLContext *
_gdk_win32_gl_window_impl_create_gl_context (GdkGLWindow  *glwindow,
                                             GdkGLContext *share_list,
                                             gboolean      direct,
                                             int           render_type)
{
  GdkGLContext *glcontext;
  GdkGLContextImpl *impl;

  glcontext = g_object_new(GDK_TYPE_WIN32_GL_CONTEXT, NULL);

  g_return_val_if_fail(glcontext != NULL, NULL);

  impl = _gdk_win32_gl_context_impl_new(glcontext,
                                        GDK_GL_DRAWABLE (glwindow),
                                        share_list,
                                        direct,
                                        render_type);
  if (impl == NULL)
    g_object_unref(glcontext);

  g_return_val_if_fail(impl != NULL, NULL);

  return glcontext;
}
示例#3
0
static gboolean expose( GtkWidget* da, GdkEventConfigure* event, gpointer user_data )
{
	GdkGLContext *GLcontext = gtk_widget_get_gl_context( da );
	GdkGLDrawable* GLdrawable = GDK_GL_DRAWABLE( gtk_widget_get_gl_window( da ) );

	if( !gdk_gl_drawable_gl_begin( GLdrawable, GLcontext ) )
        g_assert_not_reached();

	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glPushMatrix();
	glShadeModel( GL_FLAT );

    glCallList( dl_index );
	render();

	glPopMatrix();

	if( gdk_gl_drawable_is_double_buffered( GLdrawable) )
        gdk_gl_drawable_swap_buffers( GLdrawable );
    else
        glFlush();

    gdk_gl_drawable_gl_end( GLdrawable );
    return TRUE;
}
示例#4
0
文件: gtkglext.c 项目: ifreedom/lgob
static int lglext_drawable_swap_buffers(lua_State* L)
{
	luaL_checktype(L, 1, LUA_TUSERDATA);

	Object* obj = lua_touserdata(L, 1);
	gdk_gl_drawable_swap_buffers(GDK_GL_DRAWABLE(obj->pointer));

	return 0;
}
示例#5
0
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));
}
示例#6
0
static void realize_sub( GtkWidget* w )
{
    GdkGLContext* glContext = gtk_widget_get_gl_context( w );
    GdkGLDrawable* glDrawable = GDK_GL_DRAWABLE( gtk_widget_get_gl_window( w ) );

	if( !gdk_gl_drawable_gl_begin( glDrawable, glContext ) )
        g_assert_not_reached();

    InitGL();
    gdk_gl_drawable_gl_end( glDrawable );
}
示例#7
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;
}
示例#8
0
static gboolean configure( GtkWidget* da, GdkEventConfigure* event, gpointer user_data )
{
	GdkGLContext *GLcontext = gtk_widget_get_gl_context( da );
	GdkGLDrawable *GLdrawable = GDK_GL_DRAWABLE( gtk_widget_get_gl_window( da ) );

	if( !gdk_gl_drawable_gl_begin( GLdrawable, GLcontext ) )
        g_assert_not_reached();

    InitGL();
    gdk_gl_drawable_gl_end( GLdrawable );
    return TRUE;
}
示例#9
0
文件: gtkglext.c 项目: ifreedom/lgob
static int lglext_drawable_gl_begin(lua_State* L)
{
	luaL_checktype(L, 1, LUA_TUSERDATA);
	luaL_checktype(L, 2, LUA_TUSERDATA);

	Object* obj1 = lua_touserdata(L, 1);
	Object* obj2 = lua_touserdata(L, 2);
	gboolean res = gdk_gl_drawable_gl_begin(GDK_GL_DRAWABLE(obj1->pointer),
		GDK_GL_CONTEXT(obj2->pointer));

	lua_pushboolean(L, res);

	return 1;
}
示例#10
0
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;
}
示例#11
0
static void realize_main( GtkWidget* w )
{
    GdkGLContext* glContext = gtk_widget_get_gl_context( w );
    GdkGLDrawable* glDrawable = GDK_GL_DRAWABLE( gtk_widget_get_gl_window( w ) );

	if( !gdk_gl_drawable_gl_begin( glDrawable, glContext ) )
        g_assert_not_reached();

    TextureMgr::GetInstance().LoadTGA( "leaf.tga" );
    TextureMgr::GetInstance().LoadTGA( "tree.tga" );
    TextureMgr::GetInstance().LoadTGA( "sky.tga" );
    TextureMgr::GetInstance().LoadTGA( "grass.tga" );

    InitGL();
    gdk_gl_drawable_gl_end( glDrawable );
}
示例#12
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;
}
示例#13
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 ***/
}