Greg Ercolano wrote:
>       Maybe show us your FLTK2 translated sphere.cxx file.

   I decided to take a shot at translating this example to FLTK2.

   I'm not sure if it's right because I get the same error you do,
   with or without the glutInit() call, and no matter where I put it in main().

   With this code I'm trying to use FLTK2 to completely handle the
   windows, and calling fltk::run().

   I could probably make it work if I made it more like the fractal.cxx
   program where the fltk widgets are in an FLTK window, and the glut stuff
   in a separate window. Might try that next.

   In this case I created foo.cxx in the FLTK2 test directory
   and used a modified version of the glpuzzle build flags
   (by commenting out .SILENT in the makeinclude and rebuilding it,
   then changing all instances of "glpuzzle" -> "foo")

g++ -I.. -I../fltk/compat -O2 -Wall -Wunused -I/usr/include/freetype2 
-Wno-non-virtual-dtor -c foo.cxx
g++ foo.o ../lib/libfltk2_glut.a -L../lib -lfltk2_gl -lfltk2 -lGLU -lGL -lX11 
-lXi -lXinerama -lXft -lpthread -lm -lXext -lsupc++ -lglut -o foo

   Here's my first shot at translating to FLTK2.
   It builds with no errors, but dies with the glutInit() error
   at runtime. (A window does briefly open).

---

#ifdef _WIN32
#include <windows.h>
#endif
#include <math.h>
#include <fltk/glut.h>  // changed for fltk
#include <fltk/DoubleBufferWindow.h>
#include <fltk/GlWindow.h>
#include <fltk/run.h>
//
// Render a simple opengl shaded sphere with a single side light -- erco 
11/28/08
// translated to fltk2 -- erco 03/14/11
//
//     NOTE: Glut needed *only* for glutSolidSphere()
//
class MyGlWindow : public fltk::GlWindow {
public:
    // RESHAPE THE VIEWPORT
    void Reshape(GLfloat W, GLfloat H) {
        // (REFERENCE: SGI light.c DEMO)
        GLfloat ratio = W / H;
        glViewport(0, 0, (GLsizei)W, (GLsizei)H);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-1.5*ratio, 1.5*ratio, -1.5, 1.5, -10.0, 10.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    void draw() {
        if (!valid()) {
            valid(1);
            Reshape(w(), h());
            // (REFERENCE: SGI 'light.c' EXAMPLE)
            GLfloat mat_ambient[]    = { 1.0, 1.0, 1.0, 1.0 };  // RGBA
            GLfloat mat_diffuse[]    = { 1.0, 1.0, 1.0, 1.0 };  // RGBA
            GLfloat mat_specular[]   = { 1.0, 1.0, 1.0, 1.0 };  // RGBA
            GLfloat light_position[] = { 5.0, 5.0, 0.0, 0.0 };  // XYZ
            glClearColor(0.0, 0.0, 0.4, 0.0);                   // bg color
            glShadeModel(GL_SMOOTH);
            //
            glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
            glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
            glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
            glMaterialf(GL_FRONT,  GL_SHININESS, 20.0);
            glLightfv(GL_LIGHT0, GL_POSITION, light_position);
            //
            glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
            glEnable(GL_DEPTH_TEST);
        }
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
            glColor3f(0.5, 0.5, 0.5);
            glutSolidSphere(0.5, 30, 30);
        glPopMatrix();
    }
    // CTOR
    MyGlWindow(int X,int Y,int W,int H,const char*L=0) : 
fltk::GlWindow(X,Y,W,H,L) {
    }
};

int main(int argc, char *argv[]) {
  fltk::DoubleBufferWindow dwin(640, 480, "sphere");
  dwin.begin();
    MyGlWindow mygl(10, 10, dwin.w()-20, dwin.h()-20);
  dwin.end();
  dwin.resizable(&mygl);
  dwin.show();
  fprintf(stderr, "CALLING GLUT INIT\n");
  glutInit(&argc,argv);
  return(fltk::run());
}
_______________________________________________
fltk-opengl mailing list
fltk-opengl@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-opengl

Reply via email to