Loic wrote:
> Hi,
> 
>> So, anyway... all the fltk widgets have to be children of a fltk
>> window, with the GL window used only for GL rendering and so forth.
>> I think this is discussed in the docs actually, although I can't see
>> it right now.
> 
> actually I tried with a FL_Window too, but the menu bar is not drawn 
> neither...

        The problem is likely in the code you have not included,
        as the code you have looks fine.

        My guess is your FROG_Displayer has its own draw() method,
        but is not calling the base class's draw() function;
        see the "<<<" in the below example

        In your case, what you should have is:

                FROG_Displayer should be a subclass of Fl_Window
                FROG_View_Screen should be a subclass of Fl_Gl_Window

        The following code example shows what you're trying to do,
        and should work.

        Compare this to code you have to see what's wrong. And if you
        have your own draw() method for the app window, make sure it's
        calling the base class's draw() function. For instance, if you
        comment out the "Fl_Window::draw();" call, the menubar won't draw,
        but the GL window may work OK.

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>

// Opengl widget
class FROG_View_Screen : public Fl_Gl_Window {
    void FixViewport(int W,int H) {
        glLoadIdentity();
        glViewport(0,0,W,H);
        glOrtho(-W,W,-H,H,-1,1);
    }
    void draw() {
        if (!valid()) {      // first time? init
            valid(1);
            FixViewport(w(), h());
        }
        // clear screen
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        // draw 'X'
        glColor3f(1.0, 1.0, 1.0);
        glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); glVertex2f(-w(),-h()); 
glEnd();
        glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), h()); 
glEnd();
    }
public:
    // CONSTRUCTOR
    FROG_View_Screen(int X,int Y,int W,int H,const char*L=0) : 
Fl_Gl_Window(X,Y,W,H,L) {
        end();
    }
};
// App window
class FROG_Displayer : public Fl_Window {
    Fl_Menu_Bar *menubar;
    FROG_View_Screen *ViewScreen;
public:
    // CONSTRUCTOR
    FROG_Displayer(int W,int H,const char*L=0) : Fl_Window(W,H,L) {
        menubar = new Fl_Menu_Bar(0,0,w(),20);
        menubar->add("&File/&Open Files");
        menubar->add("&File/&Save Configuration");
        ViewScreen = new FROG_View_Screen(0,20,w(),h()-20,"FROG 
Displayer_Main_Screen");
        ViewScreen->resizable(ViewScreen);
        end();
    }
    void draw() {               // if you define your own draw()..
        Fl_Window::draw();      // then you HAVE to call this. (***)
    }
};
int main() {
    FROG_Displayer win(500,300);
    win.resizable(win);
    win.show();
    return(Fl::run());
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to