I used OpenGL for a while and now I wanted to use it in conjunction with FLTK. I subclassed Fl_Gl_Window
and implemented the draw method:
void MainWindow::draw()
{
if(!valid())
{
// Setup
glEnable(GL_DEPTH_TEST);
glViewport(0,0,w(),h()); // At runtime W()=800, h()=600
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w(),0,h(),1,1000);
}
gl_color(FL_BLUE);
gl_rect(0,0,w(),h());
}
I've read that in this way, there's not even the need to clear the color before drawing, and to swap the buffer (it's a double buffered window). Indeed I see that the window is by default black, without needing to call glClear
and glColor
. However, the rectangle doesn't get drawn and I get a totally black window.
This is how I instantiate the window:
int main(int argc, char **argv)
{
MainWindow* w= new MainWindow(50,100,width,height,"Test Window");
w->end();
w->show(argc,argv);
return Fl::run();
}
Probable causes of drawn object not showing on the screen:
attach()
-ed to the window object.