Beispiel #1
0
/***
 *** The "draw" signal handler. All the OpenGL re-drawing should
 *** be done here. This is repeatedly called as the painting routine
 *** every time the 'draw' event is signalled.
 ***/
static gboolean
draw (GtkWidget *widget,
      cairo_t   *cr,
      gpointer   data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
    return FALSE;

  glClear (GL_COLOR_BUFFER_BIT);

  glPushMatrix ();
    glRotatef (spin, 0.0, 0.0, 1.0);
    glColor3f (1.0, 1.0, 1.0);
    glRectf (-25.0, -25.0, 25.0, 25.0);
  glPopMatrix ();

  /* Swap buffers */
  if (gdk_gl_drawable_is_double_buffered (gldrawable))
    gdk_gl_drawable_swap_buffers (gldrawable);
  else
    glFlush ();

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

  return TRUE;
}
Beispiel #2
0
static gboolean
darxen_splash_darea_expose(GtkWidget *widget, GdkEventExpose *event)
{
	GdkGLContext *glcontext;
	GdkGLDrawable *gldrawable;

	glcontext = gtk_widget_get_gl_context(widget);
	gldrawable = gtk_widget_get_gl_drawable(widget);

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
		return TRUE;

	glClear(GL_COLOR_BUFFER_BIT);


	darxen_splash_darea_draw();


	/* This code was fun, but no
	int i;
	for (i = 190; i > 4; i -= 10)
	{
		int x = g_random_int_range(0, 300 - i);
		int y = g_random_int_range(0, 200 - i);
		glColor4d(g_random_double_range(0.2, 1.0),g_random_double_range(0.2, 1.0),g_random_double_range(0.3, 1.0),g_random_double_range(0.5, 1.0));
		glRecti(x, y, i, i);
	}
	*/

	gdk_gl_drawable_swap_buffers(gldrawable);

	gdk_gl_drawable_gl_end(gldrawable);

	return FALSE;
}
Beispiel #3
0
gboolean
on_drawingarea1_expose_event (GtkWidget       *widget,
                              GdkEventExpose  *event,
                              gpointer         user_data)
{
    GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

    /*** OpenGL BEGIN ***/
    if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
        return FALSE;

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glCallList (1);

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

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

    return FALSE;
}
Beispiel #4
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;
}
Beispiel #5
0
bool Render::on_expose_event(GdkEventExpose* event)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context (get_widget());
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (get_widget());

  if (!gldrawable || !gdk_gl_drawable_gl_begin (gldrawable, glcontext))
    return false;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  glLoadIdentity();
  glTranslatef (0.0, 0.0, -2.0 * m_zoom);
  glMultMatrixf (m_transform.M);
  CenterView();
  glPushMatrix();
  glColor3f(0.75f,0.75f,1.0f);

  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  Gtk::TreeModel::iterator iter = m_selection->get_selected();

  m_view->Draw (iter);

  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;
}
static gboolean redraw(GtkWidget *drawing_area, GdkEventExpose *event,
                       gpointer user_data)
{
	GdkGLContext *gl_ctx = gtk_widget_get_gl_context(drawing_area);
	GdkGLDrawable *gl_dbl = gtk_widget_get_gl_drawable(drawing_area);

	UNUSED(event);
	UNUSED(user_data);

	if (!gdk_gl_drawable_gl_begin(gl_dbl, gl_ctx)) {
		printf("Can't start drawable :(\n");
		exit(1);
	}

	/* Do drawing stuff */

	if (redraw_func)
	        redraw_func();

	/* Finish up */
	if (gdk_gl_drawable_is_double_buffered(gl_dbl))
		gdk_gl_drawable_swap_buffers(gl_dbl);
	else
		glFlush();

	gdk_gl_drawable_gl_end(gl_dbl);

	return TRUE;
}
Beispiel #7
0
gboolean on_expose(GtkWidget *drawing, GdkEventExpose *event, gpointer _)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1,1, -1,1, 10,-10);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0, 0, -5);

	glEnable(GL_COLOR_MATERIAL);
	glDisable(GL_TEXTURE_2D);
	glColor3f(1.0, 1.0, 1.0);

	/* Create vertexes */
	double verts[20][3];
	for (int i = 0; i < G_N_ELEMENTS(verts); i++) {
		float ang = 2*G_PI * i / G_N_ELEMENTS(verts);
		verts[i][0] = sin(ang) * (i%2+0.5) * 0.6;
		verts[i][1] = cos(ang) * (i%2+0.5) * 0.6;
		verts[i][2] = 0;
	}

	/* Draw raw polygon */
	glColor4f(0.5, 0.0, 0.0, 1.0);
	GLUtesselator *tess = gluNewTess();
	gluTessCallback(tess, GLU_TESS_BEGIN,  glBegin);
	gluTessCallback(tess, GLU_TESS_VERTEX, glVertex3dv);
	gluTessCallback(tess, GLU_TESS_END,    glEnd);
	gluTessBeginPolygon(tess, NULL);
	gluTessBeginContour(tess);
	for (int i = 0; i < G_N_ELEMENTS(verts); i++)
		gluTessVertex(tess, verts[i], verts[i]);
	gluTessEndContour(tess);
	gluTessEndPolygon(tess);
	gluDeleteTess(tess);

	/* Draw tesselated polygon */
	//glColor4f(0.0, 0.0, 0.5, 1.0);
	//glBegin(GL_POLYGON);
	//for (int i = 0; i < G_N_ELEMENTS(verts); i++)
	//	glVertex3dv(verts[i]);
	//glEnd();

	/* Draw outline */
	glColor4f(0.8, 0.8, 0.8, 1.0);
	glBegin(GL_LINE_LOOP);
	for (int i = 0; i < G_N_ELEMENTS(verts); i++)
		glVertex3dv(verts[i]);
	glEnd();

	/* Flush */
	GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current();
	if (gdk_gl_drawable_is_double_buffered(gldrawable))
		gdk_gl_drawable_swap_buffers(gldrawable);
	else
		glFlush();
	return FALSE;
}
Beispiel #8
0
static gboolean display (GtkWidget* widget, GdkEventExpose *event)
{
	GdkGLContext* glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable* aldrawable = gtk_widget_get_gl_drawable (widget);

	gdk_gl_drawable_gl_begin (gldrawable, glcontext);

	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
	gluLookAt (0.0, 30.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glPushMatrix ();
	glRotatef (angle, 0.0, 1.0, 0.0);
	glEnable (GL_COLOR_MATERIAL);
	glColor3f (0.9, 0.5, 0.2);
	gdk_gl_draw_teapot (TRUE, 25.0);
	glDisable (GL_COLOR_MATERIAL);
	glPopMatrix ();

	gdk_gl_drawable_swap_buffers (gldrawable);

	gdk_gl_drawable_gl_end (gldrawable);

	return TRUE;
}
Beispiel #9
0
static gboolean
expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
{
	GdkGLContext *glcontext = gtk_widget_get_gl_context (da);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (da);

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
	{
		g_assert_not_reached ();
	}

	/* draw in here */
	openglrender();

	/* end */


	if (gdk_gl_drawable_is_double_buffered (gldrawable))
		gdk_gl_drawable_swap_buffers (gldrawable);

	else
		glFlush ();

	gdk_gl_drawable_gl_end (gldrawable);

	return TRUE;
}
Beispiel #10
0
static gboolean cb_draw_ext(GtkWidget *widget, GdkEventExpose *e, void *_object)
{
	/* recuperation du contexte et de la surface de notre widget */
	GdkGLContext *context;
	GdkGLDrawable *surface;

	//fprintf(stderr, "cb_draw_ext: %p\n", THIS);
	
	if (!gtk_widget_is_gl_capable(widget))
	{
		fprintf(stderr, "not capable!\n");
		return TRUE;
	}
	
	context = gtk_widget_get_gl_context(widget);
	surface = gtk_widget_get_gl_drawable(widget);

	/* activation du contexte */
	if(gdk_gl_drawable_gl_begin(surface, context))
	{
		//draw(); // dessin Opengl
		init_control(THIS);
		GB.Raise(THIS, EVENT_Draw, 0);
		gdk_gl_drawable_swap_buffers(surface); // permutation tampons
		gdk_gl_drawable_gl_end(surface); // désactivation du contexte
	}

	return TRUE;
}
Beispiel #11
0
gboolean cb_glext2d_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
	GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

	if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
		return FALSE;
	}

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	// view transformation
	glLoadIdentity();
	glTranslatef(trans_x, trans_y, -10.0);
	glScalef(view_scale, view_scale, view_scale);

	// render 2d scene
	viz->handler.render_2d_scene();

	if (gdk_gl_drawable_is_double_buffered(gldrawable)) {
		gdk_gl_drawable_swap_buffers(gldrawable);
	} else {
		glFlush();
	}

	gdk_gl_drawable_gl_end(gldrawable);

	return TRUE;
}
Beispiel #12
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;
}
Beispiel #13
0
static gboolean _chisel_native_openglview_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer native_data ) {
	if ( GTK_WIDGET_REALIZED(widget) ) {
		assert( gtk_widget_is_gl_capable( widget ) );
		
		GdkGLContext *glcontext = gtk_widget_get_gl_context( widget );
		GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable( widget );
		
		assert( gdk_gl_drawable_gl_begin( gldrawable, glcontext ) );
		
		Rect rect;
		rect.origin.x = event->area.x;
		rect.origin.y = event->area.y;
		rect.size.width = event->area.width;
		rect.size.height = event->area.height;
		printf( "expose!\n" );
		//_chisel_native_view_draw_rect_callback( (native_handle)widget, rect );
		
		glViewport (0, 0,
                widget->allocation.width, widget->allocation.height); 
		
		glClearColor( 0.0f, 0.0f, 1.0f, 1.0f );
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
		
		if (gdk_gl_drawable_is_double_buffered (gldrawable))
			gdk_gl_drawable_swap_buffers (gldrawable);
		else
			glFlush ();

	
		gdk_gl_drawable_gl_end( gldrawable );
	}
	
	return TRUE;
}
static gboolean expose(GtkWidget* widget, GdkEventExpose* e, gpointer data)
{
	struct program *p = (struct program *)data;
	GdkGLContext* context = gtk_widget_get_gl_context(widget);
	GdkGLDrawable* drawable = gtk_widget_get_gl_drawable(widget);
	(void)e;

	p->draw.width = widget->allocation.width;
	p->draw.height = widget->allocation.height;

	if (!gdk_gl_drawable_gl_begin(drawable, context))
		return FALSE;

	if (p->viewed.type == TYPE_TEXTURE)
		texture_draw(p);
	else
		draw_tri(p);

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

	gdk_gl_drawable_gl_end(drawable);

	return TRUE;
}
Beispiel #15
0
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;
}
Beispiel #16
0
//virtual
void
RenderArea::swapBuffers() {
    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (GTK_WIDGET(gobj()));
    if (gdk_gl_drawable_is_double_buffered (gldrawable)) {
        gdk_gl_drawable_swap_buffers (gldrawable);
    } else {
        glFlush ();
    }
}
Beispiel #17
0
void CGLDrawingArea::GTK_FlushBufferGL()
/***************************************/
{
    GtkWidget*     widget     = reinterpret_cast<GtkWidget*>(gobj());
    GdkGLDrawable* gldrawable = gtk_widget_get_gl_drawable (widget);
    if (gdk_gl_drawable_is_double_buffered (gldrawable))
        gdk_gl_drawable_swap_buffers (gldrawable);
    else
        glFlush();
}
Beispiel #18
0
void
GtkGlExtGlue::render()
{
//    GNASH_REPORT_FUNCTION;
    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (_drawing_area);
    if (gdk_gl_drawable_is_double_buffered (gldrawable)) {
        gdk_gl_drawable_swap_buffers (gldrawable);
    } else {
      glFlush();
    }
}
Beispiel #19
0
void GLBase::glSwapBuffers()
{
	if (drw == NULL)
	{
		printf("Error, glSwapBuffers() called outside of glBegin()/glEnd() block!\n");
		return;
	}
	if (gdk_gl_drawable_is_double_buffered(drw) == TRUE)
		gdk_gl_drawable_swap_buffers(drw);
	else
		glFlush();
}
Beispiel #20
0
gint glarea_init (GtkWidget* widget, gpointer data) {

//	printf ("GLAREA_INIT - Realize Event\n");

  	gl_preview_struct *gl_hf = (gl_preview_struct *) data;

	GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

  /*** OpenGL BEGIN ***/
	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) {
		my_msg(_("Not able to display the Open GL preview"),WARNING);
		return FALSE;
	}
	
	glClearColor(0.0,0.0,0.0,1.0);
	glEnable(GL_DEPTH_TEST);
	glPolygonMode(GL_FRONT, GL_FILL);
//	glDisable(GL_CULL_FACE);

	set_perspective (gl_hf->cameras[gl_hf->current_camera_id]);

//	Lights
	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);

	glLightfv(GL_LIGHT0, GL_DIFFUSE, l0dif);
	glLightfv(GL_LIGHT0, GL_SPECULAR, l0dif);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, l1dif);
	glLightfv(GL_LIGHT1, GL_SPECULAR, l1dif);
	
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;

//	Materials
	glMaterialfv(GL_FRONT, GL_SPECULAR, mspec);
	glMaterialf(GL_FRONT, GL_SHININESS, mshiny);

	glShadeModel (GL_SMOOTH);

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

	gdk_gl_drawable_gl_end (gldrawable);
	
	return TRUE;

}
Beispiel #21
0
static gboolean
draw(GtkWidget *widget,
     cairo_t   *cr,
     gpointer   data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

  GLfloat m[4][4];
  mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info");

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

  /* basic initialization */
  if (info->do_init == TRUE) {
    initgl();
    info->do_init = FALSE;
  }

  /* view */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(info->zoom, VIEW_ASPECT, 1,100);
  glMatrixMode(GL_MODELVIEW);

  /* draw object */
  glClearColor(.3,.4,.6,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();
  glTranslatef(0,0,-30);
  add_quats(info->dquat, info->quat, info->quat);
  build_rotmatrix(m,info->quat);
  glMultMatrixf(&m[0][0]);

  lw_object_show(info->lwobject);

  /* swap backbuffer to front */
  if (gdk_gl_drawable_is_double_buffered(gldrawable))
    gdk_gl_drawable_swap_buffers(gldrawable);
  else
    glFlush();

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

 NO_GL:

  return TRUE;
}
Beispiel #22
0
/*************
 * Callbacks *
 *************/
static gboolean on_expose(GritsTester *tester, GdkEventExpose *event, gpointer _)
{
	g_debug("GritsTester: on_expose");

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearDepth(1.0);
	glEnable(GL_BLEND);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//glDisable(GL_DEPTH_TEST);
	//glBlendFunc(GL_SRC_ALPHA, GL_ONE);

	/* Lighting */
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	float light_ambient[]  = {0.1f, 0.1f, 0.1f, 1.0f};
	float light_diffuse[]  = {0.6f, 0.6f, 0.8f, 1.0f};
	float light_position[] = {-40.0f, 80.0f, 40.0f, 1.0f};
	glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glPopMatrix();

	glColor4f(1.0f, 1.0f, 1.0f, 0.5f);

	/* Draw */
	gdk_gl_draw_cube(FALSE, 2);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	for (GList *cur = tester->objects; cur; cur = cur->next)
		grits_object_draw(cur->data, NULL);
	if (tester->wireframe) {
		glDisable(GL_LIGHTING);
		glEnable(GL_POLYGON_OFFSET_LINE);
		glPolygonOffset(-1,0);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		for (GList *cur = tester->objects; cur; cur = cur->next)
			grits_object_draw(cur->data, NULL);
	}

	/* Flush */
	GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current();
	gdk_gl_drawable_swap_buffers(gldrawable);
	return FALSE;
}
static gboolean on_expose_listing (GtkWidget *pWidget, GdkEventExpose *pExpose, CDListing *pListing)
{
	if (g_bUseOpenGL && pListing->container.glContext)
	{
		GdkGLContext *pGlContext = gtk_widget_get_gl_context (pWidget);
		GdkGLDrawable *pGlDrawable = gtk_widget_get_gl_drawable (pWidget);
		if (!gdk_gl_drawable_gl_begin (pGlDrawable, pGlContext))
			return FALSE;
		
		if (pExpose->area.x + pExpose->area.y != 0)
		{
			glEnable (GL_SCISSOR_TEST);
			glScissor ((int) pExpose->area.x,
				(int) (pListing->container.bIsHorizontal ? pListing->container.iHeight : pListing->container.iWidth) -
					pExpose->area.y - pExpose->area.height,  // lower left corner of the scissor box.
				(int) pExpose->area.width,
				(int) pExpose->area.height);
		}
		
		cairo_dock_notify_on_container (CAIRO_CONTAINER (pListing), CAIRO_DOCK_RENDER_DEFAULT_CONTAINER, pListing, NULL);
		
		glDisable (GL_SCISSOR_TEST);
		
		if (gdk_gl_drawable_is_double_buffered (pGlDrawable))
			gdk_gl_drawable_swap_buffers (pGlDrawable);
		else
			glFlush ();
		gdk_gl_drawable_gl_end (pGlDrawable);
	}
	else
	{
		cairo_t *pCairoContext;
		if (pExpose->area.x > 0 || pExpose->area.y > 0)
		{
			double fColor[4] = {0., 0., 0., 0.};
			pCairoContext = cairo_dock_create_drawing_context_on_area (CAIRO_CONTAINER (pListing), &pExpose->area, fColor);
		}
		else
		{
			pCairoContext = cairo_dock_create_drawing_context (CAIRO_CONTAINER (pListing));
		}
		
		cairo_dock_notify_on_container (CAIRO_CONTAINER (pListing), CAIRO_DOCK_RENDER_DEFAULT_CONTAINER, pListing, pCairoContext);
		
		cairo_destroy (pCairoContext);
	}
	return FALSE;
}
/*
 * The "expose_event" signal handler for drawingarea1. All OpenGL re-drawing should be done here.
 * This is called every time the expose/draw event is signalled.
 *
 */
gboolean SludgeGLApplication::on_drawingarea1_expose_event(GtkWidget *theWidget, GdkEventExpose *theEvent)
{
	GdkGLContext *glContext;
	GdkGLDrawable *glDrawable;

	// Don't continue if we get fed a dud window type.
	if (theWidget->window == NULL)
	{
		return FALSE;
	}

	/*
	 * Lock rendering mutex if it's not busy - otherwise exit.
	 * This prevents the renderer being spammed by drawing requests if the rendering takes longer than the feed/timer process.
	 */
	if (!g_mutex_trylock(theRender_mutex))
		return FALSE;

	glContext = gtk_widget_get_gl_context (theWidget);
	glDrawable = gtk_widget_get_gl_drawable (theWidget);

	// Signal to gdk the start OpenGL operations.
	if (!gdk_gl_drawable_gl_begin (glDrawable, glContext))
	{
		g_mutex_unlock(theRender_mutex);
		return FALSE;
	}

	drawRect();

	/*
	 * Swap rendering buffers out (an auto glFlush is issued after) if we previously managed to initialise
	 * it as a double-buffered context, otherwise issue a standard glFlush call to signal we've finished
	 * OpenGL rendering.
	 */
	if (gdk_gl_drawable_is_double_buffered (glDrawable))
		gdk_gl_drawable_swap_buffers (glDrawable);
	else
		glFlush ();

	// Signal to gdk we're done with OpenGL operations.
	gdk_gl_drawable_gl_end (glDrawable);

	// Release the rendering mutex.
	g_mutex_unlock(theRender_mutex);

	return FALSE;
}
Beispiel #25
0
static void 
on_expose (GtkWidget *widget)
{
    GdkGLContext *gl_context = gtk_widget_get_gl_context (widget);
    GdkGLDrawable *gl_drawable = gtk_widget_get_gl_drawable (widget);

    g_return_if_fail (gl_context != NULL && gl_drawable != NULL);
    g_return_if_fail (gdk_gl_drawable_gl_begin (gl_drawable, gl_context));

    /* Clear */
    glClear (GL_COLOR_BUFFER_BIT);

    draw_background_gradient ();

    glPushMatrix ();

    /* Rotation */
    if (start_time != 0) {
        gint64 time_passed = get_time () - start_time;
        glRotatef (sin (time_passed / 1200000.0) * 45.0, 0.0, 1.0, 0.0);
    }

    /* Update textures */
    if (buffer != NULL) {
        update_textures_from_buffer ();
        gst_buffer_unref (buffer);
        buffer = NULL;
    }

    /* Reflection */
    draw_video_plane (0.0, -2.0, 0.3, 0.0, TRUE);

    /* Main video */
    draw_video_plane (0.0, 0.0, 1.0, 1.0, FALSE);

    /* Reset textures */
    _glActiveTextureARB (GL_TEXTURE0_ARB); glDisable (GL_TEXTURE_RECTANGLE_ARB);
    _glActiveTextureARB (GL_TEXTURE1_ARB); glDisable (GL_TEXTURE_RECTANGLE_ARB);
    _glActiveTextureARB (GL_TEXTURE2_ARB); glDisable (GL_TEXTURE_RECTANGLE_ARB);

    glPopMatrix ();

    gdk_gl_drawable_swap_buffers (gl_drawable);
    gdk_gl_drawable_gl_end (gl_drawable);

    gtk_widget_queue_draw (widget);
}
Beispiel #26
0
void renderOpenGLFromBlocks(struct OpenGL* ogl, int width, int height,
		int destWidth, int destHeight, int upx, int upy, int upwidth,
		int upheight) {

	if (!ogl->blocktextureids)
		return;

	printf("updating blocks\n");
	configure_window(ogl, destWidth, destHeight);
	gdk_gl_drawable_gl_begin(ogl->drawable, ogl->context);

	int x, y;
	int bw = width / 32;
	int bh = 8;
	glEnable(GL_TEXTURE_2D);
	for (y = 0; y < height / bh; y++) {
		for (x = 0; x < width / bw; x++) {
			int block = y * 32 + x;
			if (block >= ogl->nblocks)
				printf("bad block %d %d -> %d\n", x, y, block);
			else
				glBindTexture(GL_TEXTURE_2D, ogl->blocktextureids[block]);

			glBegin(GL_QUADS);
			glTexCoord2i(0, 0);
			glVertex2f(x * bw, y * bh);

			glTexCoord2i(1, 0);
			glVertex2f(x * bw + bw, y * bh);

			glTexCoord2i(1, 1);
			glVertex2f(x * bw + bw, y * bh + bh);

			glTexCoord2i(0, 1);
			glVertex2f(x * bw, y * bh + bh);
			glEnd();

		}
	}

	gdk_gl_drawable_swap_buffers(ogl->drawable);

	gdk_gl_drawable_gl_end(ogl->drawable);

}
Beispiel #27
0
void yui_gl_draw(YuiGl * glxarea) {
#ifdef HAVE_LIBGTKGLEXT
	GdkGLContext *glcontext = gtk_widget_get_gl_context (GTK_WIDGET(glxarea));
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (GTK_WIDGET(glxarea));

	if (!gdk_gl_drawable_make_current (gldrawable, glcontext)) {
		g_print("Cannot set gl drawable current\n");
		return;
	}

	gdk_gl_drawable_swap_buffers(gldrawable);
#else
	int buf_width, buf_height;
	GdkPixbuf * pixbuf, * scaledpixbuf;

	VIDCore->GetGlSize( &buf_width, &buf_height );
	glxarea->pixels_width = GTK_WIDGET(glxarea)->allocation.width;
	glxarea->pixels_height = GTK_WIDGET(glxarea)->allocation.height;
	glxarea->pixels_rowstride = glxarea->pixels_width * 4;
	glxarea->pixels_rowstride += (glxarea->pixels_rowstride % 4)? (4 - (glxarea->pixels_rowstride % 4)): 0;

	if (dispbuffer == NULL) return;

	pixbuf = gdk_pixbuf_new_from_data((const guchar *) dispbuffer, GDK_COLORSPACE_RGB, TRUE, 8,
			buf_width, buf_height, buf_width*4, NULL, NULL);

	if (( glxarea->pixels_width < buf_width + X_NOSCALE )&&( glxarea->pixels_height < buf_height + Y_NOSCALE )) {

	  gdk_draw_pixbuf(GTK_WIDGET(glxarea)->window, NULL, pixbuf, 0, 0,
			  (glxarea->pixels_width-buf_width)/2, (glxarea->pixels_height-buf_height)/2,
			  buf_width, buf_height, GDK_RGB_DITHER_NONE, 0, 0);
	} else {

	  scaledpixbuf = gdk_pixbuf_scale_simple(pixbuf, 
						 glxarea->pixels_width, glxarea->pixels_height, GDK_INTERP_NEAREST );
	  gdk_draw_pixbuf(GTK_WIDGET(glxarea)->window, NULL, 
			  scaledpixbuf, 0, 0, 0, 0, glxarea->pixels_width, glxarea->pixels_height, 
			  GDK_RGB_DITHER_NONE, 0, 0);
	  g_object_unref(scaledpixbuf);
	}
	g_object_unref(pixbuf);
#endif
	glxarea->is_init = 1;
}
Beispiel #28
0
static gboolean
expose_event(GtkWidget * widget, GdkEventExpose * UNUSED(eventDetails), const GraphData * gd)
{
    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

    if (!gdk_gl_drawable_gl_begin(gldrawable, gtk_widget_get_gl_context(widget)))
        return TRUE;
    CheckOpenglError();

    glClear(GL_COLOR_BUFFER_BIT);

    DrawGraph(gd);

    gdk_gl_drawable_swap_buffers(gldrawable);

    gdk_gl_drawable_gl_end(gldrawable);

    return TRUE;
}
static gboolean
expose_event (GtkWidget      *widget,
              GdkEventExpose *event,
              gpointer        data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

  /* brass */
  static GLfloat ambient[4]  = { 0.329412, 0.223529, 0.027451, 1.0 };
  static GLfloat diffuse[4]  = { 0.780392, 0.568627, 0.113725, 1.0 };
  static GLfloat specular[4] = { 0.992157, 0.941176, 0.807843, 1.0 };
  static GLfloat shininess   = 0.21794872 * 128.0;

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
    return FALSE;

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glLoadIdentity ();
  glTranslatef (0.0, 0.0, -10.0);

  glPushMatrix ();
    glTranslatef (0.0, pos_y, 0.0);
    glRotatef (angle, 0.0, 1.0, 0.0);
    glMaterialfv (GL_FRONT, GL_AMBIENT, ambient);
    glMaterialfv (GL_FRONT, GL_DIFFUSE, diffuse);
    glMaterialfv (GL_FRONT, GL_SPECULAR, specular);
    glMaterialf (GL_FRONT, GL_SHININESS, shininess);
    gdk_gl_draw_torus (TRUE, 0.3, 0.6, 30, 30);
  glPopMatrix ();

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

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

  return TRUE;
}
static gboolean
expose_event_preview3d(GtkWidget * widget, GdkEventExpose * UNUSED(eventDetails), Material * pMat)
{
    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

    if (!gdk_gl_drawable_gl_begin(gldrawable, gtk_widget_get_gl_context(widget)))
        return TRUE;

    CheckOpenglError();

    SetupLight();
    Draw(pMat);

    gdk_gl_drawable_swap_buffers(gldrawable);

    gdk_gl_drawable_gl_end(gldrawable);

    return TRUE;
}