Re: gtkglextmm help



I write this source code and work:

g++ main2.cc `pkg-config --cflags --libs gtkglextmm-x11-1.2`

It seems that the samples from here are bad¿?¿?
http://gtkglext.sourceforge.net/reference/gtkglextmm/examples.html

#include <iostream>
#include <cstdlib>
#include <gtkmm.h>
#include <GL/glu.h>
#include <gtkglmm.h>

#include <math.h>

float boxv[][3] = {
   { -0.5, -0.5, -0.5 },
   {  0.5, -0.5, -0.5 },
   {  0.5,  0.5, -0.5 },
   { -0.5,  0.5, -0.5 },
   { -0.5, -0.5,  0.5 },
   {  0.5, -0.5,  0.5 },
   {  0.5,  0.5,  0.5 },
   { -0.5,  0.5,  0.5 }
};
#define ALPHA 0.5

static float ang = 30.;


class glsample : public Gtk::GL::DrawingArea{
   public:
       glsample();
       virtual ~glsample();

   protected:
       virtual void on_realize();
       virtual bool on_configure_event(GdkEventConfigure* event);
       virtual bool on_expose_event(GdkEventExpose* event);
};


glsample::glsample(){

   Glib::RefPtr<Gdk::GL::Config> glconfig;

glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | Gdk::GL::MODE_DEPTH | Gdk::GL::MODE_DOUBLE);

   set_gl_capability(glconfig);

}

glsample::~glsample(){
}

void glsample::on_realize(){
   Gtk::GL::DrawingArea::on_realize();

   //get gl::window
   Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();

   glwindow->gl_begin(get_gl_context());
glwindow->gl_begin(get_gl_context());
   glClearColor(1.0, 0.0, 0.0, 1.0);
   glMatrixMode(GL_PROJECTION);
   glOrtho(-0.5, 0.5, -0.5, 0.5, -0.1, 0.1);
   glColor3f(1.0f, 0.0f, 0.0f);
glDisable(GL_DEPTH_TEST);

   glwindow->gl_end();
}

bool glsample::on_configure_event(GdkEventConfigure* event){

   //get gl::window
   Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();

   glwindow->gl_begin(get_gl_context());
glViewport(0, 0, GLsizei(get_width()), GLsizei(get_height()));

   glwindow->gl_end();

   return true;
}

bool glsample::on_expose_event(GdkEventExpose* event){

   //get gl::window
   Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();

   glwindow->gl_begin(get_gl_context());

   glClear(GL_COLOR_BUFFER_BIT);

   glwindow->swap_buffers();
  glBegin (GL_TRIANGLES);
                       glIndexi (0);
                       glColor3f (1.0f, 0.0f, 0.0f);
                       glVertex2i (0, 1);
                       glIndexi (0);
                       glColor3f (0.0f, 1.0f, 0.0f);
                       glVertex2i (-1, -1);
                       glIndexi (0);
                       glColor3f (0.0f, 0.0f, 1.0f);
                       glVertex2i (1, -1);
               glEnd ();
   // Error detection.
   GLenum error = glGetError();
   if(error != GL_NO_ERROR)
   {
       std::cerr << "\n OpenGL error: " << gluErrorString(error);
       std::cerr.flush();
   }
   //main loop
   glwindow->gl_end();
   glwindow->swap_buffers ();

   return true;
}

int main(int argc, char *argv[]){
   Gtk::Main init (argc, argv);
   Gtk::GL::init (argc, argv);

   Gtk::Window window;
   window.set_title ("Widget Demo");

   glsample drawing;
   window.add (drawing);

   window.show_all ();

   Gtk::Main::run (window);

   return EXIT_SUCCESS;

}


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