Exemple #1
0
/* We need to set up our state when we realize the GtkGLArea widget */
static void
realize (GtkWidget *widget)
{
  const char *vertex_path, *fragment_path;
  GdkGLContext *context;

  gtk_gl_area_make_current (GTK_GL_AREA (widget));

  if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
    return;

  context = gtk_gl_area_get_context (GTK_GL_AREA (widget));

  if (gdk_gl_context_get_use_es (context))
    {
      vertex_path = "/glarea/glarea-gles.vs.glsl";
      fragment_path = "/glarea/glarea-gles.fs.glsl";
    }
  else
    {
      vertex_path = "/glarea/glarea-gl.vs.glsl";
      fragment_path = "/glarea/glarea-gl.fs.glsl";
    }

  init_buffers (&position_buffer, NULL);
  init_shaders (vertex_path, fragment_path, &program, &mvp_location);
}
Exemple #2
0
/* We should tear down the state when unrealizing */
static void
unrealize (GtkWidget *widget)
{
  gtk_gl_area_make_current (GTK_GL_AREA (widget));

  if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
    return;

  glDeleteBuffers (1, &position_buffer);
  glDeleteProgram (program);
}
Exemple #3
0
/* When widget is exposed it's contents are redrawn. */
gint draw(GtkWidget *widget, GdkEventExpose *event)
{
  /* Draw only last expose. */
  if (event->count > 0)
    return TRUE;

  if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    game_render();

  /* Swap backbuffer to front */
  gtk_gl_area_swapbuffers(GTK_GL_AREA(widget));

  return TRUE;
}
Exemple #4
0
int
main(int argc, char *argv[])
{
        srand(time(NULL));
        mk_points(points, n_points);

        gtk_init(&argc, &argv);

        GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


        /* set up GL window */
        GtkWidget *gl_area = gtk_gl_area_new();
        gtk_gl_area_set_has_depth_buffer(GTK_GL_AREA(gl_area), TRUE);

        g_signal_connect(gl_area, "create-context",
                         G_CALLBACK(create_context), NULL);
        g_signal_connect(gl_area, "realize", G_CALLBACK(realize), NULL);
        g_signal_connect(gl_area, "render", G_CALLBACK(render), NULL);
        g_signal_connect(gl_area, "resize", G_CALLBACK(resize), NULL);
        g_signal_connect(gl_area, "unrealize", G_CALLBACK(unrealize), NULL);

        gtk_container_add(GTK_CONTAINER(window), gl_area);


        gtk_widget_show_all(window);

        gtk_main();
}
Exemple #5
0
void
gl_window_change_orientation(GtkGLArea *glarea, o_enum orientation)
{
  gl_window_info *info;
  GdkRectangle area;

  info = gtk_object_get_data(GTK_OBJECT(glarea), "info");

  if (gtk_gl_area_make_current(GTK_GL_AREA(glarea))){
    //if changing to 3d or texture orientation
    if(orientation == ORIENTATION_3D ||
       orientation == ORIENTATION_TEXTURE ){

      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

      glShadeModel(GL_SMOOTH);
      glClearColor(0.2, 0.5, 0.7, 1.0);
      glClearDepth(1);
    }else{
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glClearColor(0.6, 0.6, 0.6, 1);
    }
  }

  info->orientation = orientation;

  area.x = 0;
  area.y = 0;
  area.width  = GTK_WIDGET (glarea)->allocation.width;
  area.height = GTK_WIDGET (glarea)->allocation.height;

  //orientation changed, redraw
  gtk_widget_draw(GTK_WIDGET (glarea), &area);
}
Exemple #6
0
int reshape (GtkWidget *widget, GdkEventConfigure *event) 
{
	if (gtk_gl_area_make_current (GTK_GL_AREA(widget))) {
		glViewport(0,0, widget->allocation.width, widget->allocation.height);
	}
	return TRUE;
}
Exemple #7
0
static void
realize(GtkWidget *widget, gpointer user_data)
{
        gtk_gl_area_make_current(GTK_GL_AREA(widget));

        glDebugMessageCallback(debug, NULL);

        char *str = pk_io_read_file("data/vs.glsl");
        programs[0] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &str);
        free(str);

        str = pk_io_read_file("data/fs.glsl");
        programs[1] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &str);
        free(str);


        /* set up pipeline for rendering fullscreen quad */
        glCreateProgramPipelines(1, &pipeline);
        glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT, programs[0]);
        glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, programs[1]);
        glBindProgramPipeline(pipeline);


        glCreateVertexArrays(1, &vao);
        glBindVertexArray(vao);
}
Exemple #8
0
static void
toggle_alpha (GtkWidget *checkbutton,
              GtkWidget *gears)
{
  gtk_gl_area_set_has_alpha (GTK_GL_AREA (gears),
                             gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbutton)));
}
Exemple #9
0
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                                uint32_t backing_id,
                                bool backing_y_0_top,
                                uint32_t backing_width,
                                uint32_t backing_height,
                                uint32_t x, uint32_t y,
                                uint32_t w, uint32_t h)
{
    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);

    vc->gfx.x = x;
    vc->gfx.y = y;
    vc->gfx.w = w;
    vc->gfx.h = h;
    vc->gfx.tex_id = backing_id;
    vc->gfx.y0_top = backing_y_0_top;

    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));

    if (vc->gfx.tex_id == 0 || vc->gfx.w == 0 || vc->gfx.h == 0) {
        gtk_gl_area_set_scanout_mode(vc, false);
        return;
    }

    gtk_gl_area_set_scanout_mode(vc, true);
    if (!vc->gfx.fbo_id) {
        glGenFramebuffers(1, &vc->gfx.fbo_id);
    }

    glBindFramebuffer(GL_FRAMEBUFFER_EXT, vc->gfx.fbo_id);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                              GL_TEXTURE_2D, vc->gfx.tex_id, 0);
}
Exemple #10
0
void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
                          uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);

    gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
}
Exemple #11
0
/* When widget is exposed it's contents are redrawn. */
gint draw(GtkWidget *widget, GdkEventExpose *event)
{
  /* Draw only last expose. */
  if (event->count > 0) {
    return TRUE;
  }

  if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) {
    int i,j;

    /* clear screen */
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);

    /* Draw some text */
    glColor3f(1,1,1);
    for (i=1; i<5; i++) {
      glRasterPos2f(10, widget->allocation.height-i*fontheight);
      for (j=' '; j<='Z'; j++) {
	glCallList(fontbase+j);
      }
    }

    /* show font name */
    glColor3f(1,1,0);
    glRasterPos2f(10,5);
    glListBase(fontbase);
    glCallLists(strlen(fontname), GL_UNSIGNED_BYTE, fontname);

    gdk_gl_wait_gl();

  }
  return TRUE;
}
Exemple #12
0
void gd_gl_area_switch(DisplayChangeListener *dcl,
                       DisplaySurface *surface)
{
    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
    bool resized = true;

    trace_gd_switch(vc->label, surface_width(surface), surface_height(surface));

    if (vc->gfx.ds &&
        surface_width(vc->gfx.ds) == surface_width(surface) &&
        surface_height(vc->gfx.ds) == surface_height(surface)) {
        resized = false;
    }

    if (vc->gfx.gls) {
        gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
        surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
        surface_gl_create_texture(vc->gfx.gls, surface);
    }
    vc->gfx.ds = surface;

    if (resized) {
        gd_update_windowsize(vc);
    }
}
Exemple #13
0
gint init(GtkWidget *widget)
{
  if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) {
    GdkFont *font;

    /* set viewport */
    glViewport(0,0, widget->allocation.width, widget->allocation.height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,widget->allocation.width, 0,widget->allocation.height, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    /* generate font display lists */
    fontbase = glGenLists( 128 );
    font = gdk_font_load(fontname);
    if (!font) {
      g_print("Can't load font '%s'\n", fontname);
      gtk_exit(1);
    }

    gdk_gl_use_gdk_font(font, 0, 128, fontbase);
    fontheight = font->ascent+font->descent;
    gdk_font_unref(font);

  }
  return TRUE;
}
Exemple #14
0
// flip GL buffers
void graph3d_gtk::flip(void)
{ 
  /* Swap backbuffer to front */
  if(graphics && p_area && gtk_gl_rendering(p_area)) {
    gtk_gl_area_swapbuffers(GTK_GL_AREA(p_area));
  }
}
Exemple #15
0
void
gl_window_orient_window(GtkGLArea *glarea)
{
  gl_window_info *info = gtk_object_get_data(GTK_OBJECT(glarea), "info");
  GLfloat median;
  float m[4][4];

  if (gtk_gl_area_make_current(GTK_GL_AREA(glarea))){

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);

    if(info->orientation == ORIENTATION_3D ||
       info->orientation == ORIENTATION_TEXTURE ){

      glMatrixMode(GL_PROJECTION);
      glFrustum( -0.0005 * info->aspect_ratio, 0.0005 * info->aspect_ratio,
		 -0.0005 , 0.0005,
		 0.001, 1000
		 );

    }else{
      if(info->x_median >= info->y_median)
	median = info->x_median;
      else
	median = info->y_median;


      glOrtho(-1 * info->x_median, info->x_median,      // left, right
	      -1 * info->y_median, info->y_median,      // bottom, top
	      median * -3, median * 3                   // near, far
	      );
    }

    switch(info->orientation)
      {

      case ORIENTATION_FRONT:	break;
      case ORIENTATION_3D:
      case ORIENTATION_TEXTURE:
	glMatrixMode(GL_MODELVIEW);
	glTranslatef(0,0,-1 * info->zoom);

	build_rotmatrix(m, info->quat);
	glMultMatrixf(&m[0][0]);
	break;
      case ORIENTATION_TOP:	glRotatef(-90, 1,0,0);	break;
      case ORIENTATION_BOTTOM:	glRotatef( 90, 1,0,0);	break;
      case ORIENTATION_LEFT:	glRotatef(90, 0,1,0);	break;
      case ORIENTATION_RIGHT:	glRotatef(-90, 0,1,0);	break;
      case ORIENTATION_BACK:	glRotatef(180, 0,1,0);	break;
      default: break;
      }

  }/*if(gtk_gl_area_make_current(glarea))*/
}
static gboolean
queue_render_cb(gpointer udata)
{
    if (udata) //Might have been destroyed
        gtk_gl_area_queue_render(GTK_GL_AREA(udata));

    return FALSE;
}
Exemple #17
0
int draw (GtkWidget *widget, GdkEventExpose *event) 
{
	if (event->count > 0) return TRUE;

	if (gtk_gl_area_make_current (GTK_GL_AREA(widget))) {
	  glClearColor(0,0,0,1);
	  glClear(GL_COLOR_BUFFER_BIT);
	  glColor3f(0,0.2,0.8);
	  glBegin(GL_TRIANGLES);
	  glVertex2f(10,10);
	  glVertex2f(10,90);
	  glVertex2f(90,90);
	  glEnd();
	  gtk_gl_area_swap_buffers (GTK_GL_AREA(widget));
	}
	return TRUE;
}
Exemple #18
0
static void
opengl_cb(gpointer udata)
{
    GtPlayerMpv* self = GT_PLAYER_MPV(udata);
    GtPlayerMpvPrivate* priv = gt_player_mpv_get_instance_private(self);

    gtk_gl_area_queue_render(GTK_GL_AREA(priv->opengl_area));
}
Exemple #19
0
/* When glarea widget size changes, viewport size is set to match the new size */
gint reshape(GtkWidget *widget, GdkEventConfigure *event)
{
  /* OpenGL functions can be called only if make_current returns true */
  if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    {
      glViewport(0,0, widget->allocation.width, widget->allocation.height);
    }
  return TRUE;
}
Exemple #20
0
gint draw(GtkWidget *glarea, GdkEventExpose *event) {
  if(gtk_gl_area_make_current(GTK_GL_AREA(glarea))) {
    mainwin->redraw();

    return TRUE;
  } else {
    // could not set context
    return FALSE;
  }
}
Exemple #21
0
static void
unrealize(GtkWidget *widget, gpointer user_data)
{
        gtk_gl_area_make_current(GTK_GL_AREA(widget));

        glDeleteProgram(programs[0]);
        glDeleteProgram(programs[1]);
        glDeleteProgramPipelines(1, &pipeline);
        glDeleteVertexArrays(1, &vao);
}
Exemple #22
0
gint switch_fullscreen(GtkWidget *gl_area)
{
  static GtkWidget *fullscreenwidget = NULL;

  if (!fullscreenwidget)
    {
      /* Grab keyboard and pointer so that user does not wander off the game
	 window while in fullscreen mode.
      */
      if (gdk_keyboard_grab(gl_area->window, FALSE, GDK_CURRENT_TIME) == 0)
	{
	  if (gdk_pointer_grab(gl_area->window, FALSE, 0, NULL, NULL, GDK_CURRENT_TIME) == 0)
	    {
	      gtk_widget_grab_focus(gl_area);
	      if (gtk_gl_area_make_current(GTK_GL_AREA(gl_area)))
		{
		  if (XMesaSetFXmode((XMESA_FX_FULLSCREEN)))
		    {
		      fullscreenwidget = gl_area;
		      return TRUE;
		    }
		}
	      gdk_pointer_ungrab(GDK_CURRENT_TIME);
	    }
	  gdk_keyboard_ungrab(GDK_CURRENT_TIME);
	}
      return FALSE;
    }

  if (fullscreenwidget == gl_area)
    {
      if (gtk_gl_area_make_current(GTK_GL_AREA(gl_area)))
	XMesaSetFXmode(XMESA_FX_WINDOW);

      gdk_keyboard_ungrab(GDK_CURRENT_TIME);
      gdk_pointer_ungrab(GDK_CURRENT_TIME);
      fullscreenwidget = NULL;
      return TRUE;
    }

  return FALSE;
}
Exemple #23
0
static gboolean reshape( GtkWidget *widget, GdkEvent *event, gpointer native_data ) {
#ifndef _WIN32
	if ( !gtk_gl_area_make_current(GTK_GL_AREA(widget)) )
		return TRUE;
	
	//printf( "reshape!\n" );
#endif
	_chisel_native_openglview_reshape_callback( (native_handle)widget );

	return TRUE;
}
Exemple #24
0
static void
finalise(GObject* obj)
{
    GtPlayerMpv* self = GT_PLAYER_MPV(obj);
    GtPlayerMpvPrivate* priv = gt_player_mpv_get_instance_private(self);

    gtk_gl_area_make_current(GTK_GL_AREA(priv->opengl_area));
    mpv_opengl_cb_uninit_gl(priv->mpv_opengl);

    G_OBJECT_CLASS(gt_player_mpv_parent_class)->finalize(obj);
}
Exemple #25
0
gint initialize(GtkWidget *glarea, gpointer data) {
  if(gtk_gl_area_make_current(GTK_GL_AREA(glarea))) {
    GLfloat light_ambient[] = {0.5, 0.5, 0.5, 1.0};
    GLfloat light_diffuse[] = {0.75, 0.75, 0.75, 1.0};
    GLfloat light_position[] = {400, 400, 400, 1.0};

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_CULL_FACE);

    glClearColor(0, 0, 0, 0);
    glClearDepth(1.0);
    glDepthFunc(GL_LESS);
    glShadeModel(GL_SMOOTH);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    glViewport(0, 0, glarea->allocation.width, glarea->allocation.height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (double) glarea->allocation.width / (double) glarea->allocation.height, 3.0, 2500.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gtk_gl_area_swapbuffers(GTK_GL_AREA(glarea));

    return TRUE;
  } else {
    // could not set context
    return FALSE;
  }
}
Exemple #26
0
int init (GtkWidget *widget)
{
	if (gtk_gl_area_make_current (GTK_GL_AREA(widget))) {
	  glViewport(0,0, widget->allocation.width, widget->allocation.height);
	  glMatrixMode(GL_PROJECTION);
	  glLoadIdentity();
	  glOrtho(0,100, 100,0, -1,1);
	  glMatrixMode(GL_MODELVIEW);
	  glLoadIdentity();
	}
	return TRUE;
}
Exemple #27
0
void gd_gl_area_update(DisplayChangeListener *dcl,
                   int x, int y, int w, int h)
{
    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);

    if (!vc->gfx.gls || !vc->gfx.ds) {
        return;
    }

    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
    surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
    vc->gfx.glupdates++;
}
gboolean draw(GtkWidget *widget, cairo_t *cr)
{
	if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
	{
	      glViewport(0,0, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height (widget));

		/* draw a triangle */
	      glClearColor(0,0,0,1);
	      glClear(GL_COLOR_BUFFER_BIT);
	      glColor3f(1,1,1);
	      glBegin(GL_TRIANGLES);
	      glVertex2f(10,10);
	      glVertex2f(10,90);
	      glVertex2f(90,90);
	      glEnd();

		/* refresh-draw ! */
	      gtk_gl_area_swap_buffers (GTK_GL_AREA(widget));
	}

	return TRUE;
}
gint init (GtkWidget *widget)
{
      gtk_gl_area_make_current (GTK_GL_AREA(widget));
      glViewport(0,0, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height (widget));

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0,100, 100,0, -1,1);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();

      return TRUE;
}
Exemple #30
0
static void
gtk_gears_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
{
  GtkGLArea *glarea = GTK_GL_AREA (widget);

  GTK_WIDGET_CLASS (gtk_gears_parent_class)->size_allocate (widget, allocation);

  if (gtk_widget_get_realized (widget))
    {
      gtk_gl_area_make_current (glarea);
      reshape (allocation->width, allocation->height);
    }
}