gtkGLmm problems....



Hello all.
    I am working on c++ wrapper for gtkGL widget.  I have finished the
class Gtk_GLContext.  It is derived from Gtk_DrawingArea, since gtkGL is
using drawing_area as it's gl_canvas. I have some problems with testing
it.  When I run the test program, all I get is an empty drawing area,
which is not being drawn into at all, and I get the following errors
into stderr:

** WARNING **: file gtkGLmain.c: line 67
(gtk_gl_swap_buffers_of_widget): "GTK_WIDGET_REALIZED (widget)"
idle callback called

It seems that the Gtk_GLContext widget is not being realized, so I have
to manually call context->realize();  Or, did I have to write a specific
realize_impl() function to be used by Gtk_GLContext?

I am including the source of the test prog.  Maybe someone would find
something that I don't see.


Thank you.
Marsel Osipov
#include "gtkGLmm.h"
#include "mesa-gears.h"
#include "mesa-gears.c"
#include <iostream.h>

class mywin : public Gtk_Window {
  Gtk_Button *button;
  Gtk_VBox vbox;
  Gtk_GLContext *context;

public:
  mywin();
  void realize_GL(Gtk_GLContext *);
};

static gint draw_idle_callback(Gtk_GLContext *);
static void size_allocate_callback(Gtk_GLContext *, gpointer);

static struct {
    GLint    gear1, gear2, gear3;
    GLfloat  view_rotx, view_roty, view_rotz;
    GLfloat  angle;

    gint idle_tag;
} Gears;


static gint
draw_idle_callback (Gtk_GLContext *widget)
{
  cout << "idle callback called" << endl;

  Gears.angle += 2.0;
  Gears.view_rotx += 0.15;
  Gears.view_roty += 0.5;
  Gears.view_rotz += 1.3;

  if(GTK_WIDGET_REALIZED(widget->gtkobject))
    {
      GTK_GL_WRAP_BEGIN (widget->context_of_widget())
	{
	  cout << "in draw_callback() " << endl;
	  mesa_gears_draw(Gears.gear1, Gears.gear2, Gears.gear3,
			  Gears.angle,
			  Gears.view_rotx, Gears.view_roty, Gears.view_rotz);
	}
      GTK_GL_WRAP_END;
    }

  widget->swap_buffers_of_widget();
 return TRUE;
}


void mywin::realize_GL(Gtk_GLContext *widget)
{
  cout << "resize_callback called" << endl;

  Gears.angle = 0.0;
  Gears.view_rotx = 20.0;
  Gears.view_rotx = 30.0;
  Gears.view_rotx = 0.0;

  if(GTK_WIDGET_REALIZED(widget->gtkobject))
    { 
      GTK_GL_WRAP_BEGIN (widget->context_of_widget())
	{
	  mesa_gears_init(&Gears.gear1, &Gears.gear2, &Gears.gear3);
	}
      GTK_GL_WRAP_END; 
    }
      Gears.idle_tag = gtk_idle_add(draw_idle_callback, widget);
//gtk_widget_queue_resize((GtkWidget*)widget); 
}

static void
size_allocate_callback (Gtk_GLContext *widget, 
			GtkAllocation *allocation)
{
  gint width, height;

  width = allocation->width;
  height = allocation->height;

if(GTK_WIDGET_REALIZED(widget))
  {  
    GTK_GL_WRAP_BEGIN (widget->context_of_widget())
      {
	mesa_gears_reshape(width, height);
      }
    GTK_GL_WRAP_END;
  }
}

mywin::mywin() : vbox(false, 1)
{
  button = new Gtk_Button("gktGLmm test");
  add(&vbox);


  context = new Gtk_GLContext;
  cout << "context created" << endl;
  
  vbox.show();
  //vbox.pack_start(button, FALSE, FALSE, 2);
  //button->show();

  //mistake could be in the connect function ....hm -> corrected
  connect(context->realize, this, &mywin::realize_GL, context);
  //connect(context->size_allocate, this, &size_allocate_callback, context);

  context->size(100, 200);
  vbox.pack_start(context);
  cout << "context packed" << endl;
  context->show();
  cout << "context show()" << endl;
  context->realize(); // hm.., widget is not being realized, until this call
}

main(int argc, char **argv)
{
  Gtk_Main vm(&argc, &argv);
  mywin win;
  
  //  win.set_usize(300, 200);
  win.show();
  vm.run();
  return(0);
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]