Albrecht Schlosser wrote: > I still don't know more about glut, but reading the FLTK 1.3 (!) docs > about "Mixing GLUT and FLTK Code" > > <http://www.fltk.org/doc-1.3/glut.html#glut_mixing> > > your code seems to be faulty. I understand the docs so that you > shall not call glutInit() if (and only if?) you want to "make your > GLUT window a child of a Fl_Window". Then you must also show() your > main window *before* you add the glut subwindow (this is not correct > in your example code).
I still get an error about calling glutInit().. 1) Changed the code to use a GlutWindow(), 2) Define the glut window after show()ing the fltk window 3) Not calling glutInit() because it's a child of Fl_Window The FLTK2 docs for GlutWindow refer to docs in glut.h, but I don't see much there in the way of docs. New code below; feel free to tweak; it still gives the 'glutInit' runtime error "ERROR: Function <xxx> called without first calling 'glutInit'". I'm pretty sure glut's glutInit() must be setting a static flag that has to be set, or the rest of the lib won't work. So unless you set that, it's gonna bitch about glutInit() not being called. And I /think/ fltk's glutInit() eclipses the real glutInit(), so calling it doesn't make the error go away, cause you're calling the FLTK2 one, not glut's. And I don't think fltk2's glutInit() calls the real glut's (how can it when it eclipses it?). #ifdef _WIN32 #include <windows.h> #endif #include <math.h> #include <fltk/glut.h> // GlutWindow(), glutSolidSphere() #include <fltk/DoubleBufferWindow.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 // class MyGlutWindow : public fltk::GlutWindow { 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 MyGlutWindow(int X,int Y,int W,int H,const char*L=0) : fltk::GlutWindow(X,Y,W,H,L) { } }; int main(int argc, char **argv) { fltk::DoubleBufferWindow dwin(640, 480, "sphere"); dwin.resizable(dwin); // Call show() first dwin.show(); // Add glut window next dwin.begin(); MyGlutWindow myglut(10, 10, dwin.w()-20, dwin.h()-20); myglut.show(); dwin.end(); return(fltk::run()); } _______________________________________________ fltk-opengl mailing list fltk-opengl@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-opengl