I now have events when I press right arrow.
(I forgot a win->begin();)

but the event is of type
FL_SHORTCUT = 12
and not of type
FL_KEYBOARD = 8

What is the trick?

Loic,




> Loic wrote:
>       Might have to do with making sure you put win->begin();
>       and win->end() around your definition of the menubar,
>       so it's clear where it's getting parented.
>
>       There should be nothing special about the menu bar wrt to
>       keyboard event handling that I'm aware of.
>
>       FWIW, I added an Fl_Window and MenuBar to the example
>       I posted earlier, along with a handle() method that prints events
>       in the GL window subclass.
>
>       Seems to work normally for me; menubar and GL window appear within
>       the outer Fl_Window, and events are printed (eg. hitting right arrow)
>       and the menubar is shown.
>
>
>
> #include <stdio.h>
> #include <math.h>
> #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 spinning cube with checker texturemap -- erco/loic 03/17/09
> //
> #define WIN_W 400             // window width
> #define WIN_H 400             // window height
> #define TEX_W 64              // texturemap width
> #define TEX_H 64              // texturemap height
> #define FPS   (1.0/24.0)      // frames per second playback
> //
> // OpenGL class to show texturemapped cube
> //
> class MyGlWindow : public Fl_Gl_Window {
>   double spin;
>   GLuint TexID;
>   // TIMER CALLBACK
>   //    Handles rotation the object
>   //
>   static void Timer_CB(void *userdata) {
>     MyGlWindow *mygl = (MyGlWindow*)userdata;
>     mygl->spin += 2.0;        // spin
>     mygl->redraw();
>     Fl::repeat_timeout(FPS, Timer_CB, userdata);
>   }
> public:
>   // CTOR
>   MyGlWindow(int x,int y,int w,int h,const char *l=0) : 
> Fl_Gl_Window(x,y,w,h,l) {
>     spin = 0.0;
>     Fl::add_timeout(FPS, Timer_CB, (void*)this);       // 24fps timer
>   }
>   // PERSPECTIVE VIEW
>   //    Same as gluPerspective()..
>   //
>   void Perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble 
> zFar) {
>     GLdouble xmin, xmax, ymin, ymax;
>     ymax = zNear * tan(fovy * M_PI / 360.0);
>     ymin = -ymax;
>     xmin = ymin * aspect;
>     xmax = ymax * aspect;
>     glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
>   }
>   // RESHAPED VIEWPORT
>   //     OpenGL stuff to do whenever window changes size
>   //
>   void ReshapeViewport() {
>     // Viewport
>     glViewport(0, 0, w(), h());
>     // Projection
>     glMatrixMode(GL_PROJECTION);
>     glLoadIdentity();
>     GLfloat ratio = w() / h();
>     Perspective(30.0, 1.0*ratio, 1.0, 30.0);
>     glTranslatef(0.0, 0.0, -8.0);
>     // Model view
>     glMatrixMode(GL_MODELVIEW);
>     glLoadIdentity();
>   }
>   // OPENGL INITIALIZATION
>   //    OpenGL stuff to do *only once* on startup.
>   //
>   void GlInit() {
>     // Make sure we only do this once
>     static int first_time = 1;
>     if ( first_time ) {
>       first_time = 0;
>       // Texture Map Init
>       GLubyte img[TEX_W][TEX_H][3];           // after glTexImage2D(), array 
> is no longer needed
>       glGenTextures(1, &TexID);
>       glBindTexture(GL_TEXTURE_2D, TexID);
>       for (int x=0; x<TEX_W; x++) {
>       for (int y=0; y<TEX_H; y++) {
>         GLubyte c = ((x&16)^(y&16)) ? 255 : 0;                                
> // checkerboard
>         //GLubyte c = ((x&16)^(y&16)) ? ((x%16)<<4) : (((x%16)^15)<<4);       
> // basket weave
>         img[x][y][0] = c;
>         img[x][y][1] = c;
>         img[x][y][2] = c;
>       }
>       }
>       glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
>       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEX_W, TEX_H, 0, GL_RGB, 
> GL_UNSIGNED_BYTE, &img[0][0][0]);
>       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
>       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
>       glEnable(GL_TEXTURE_2D);
>       // Misc OpenGL settings
>       glShadeModel(GL_FLAT);
>       glEnable(GL_DEPTH_TEST);
>       glDepthFunc(GL_LEQUAL);
>     }
>   }
>   // FLTK DRAW
>   //    Called by FLTK to draw the scene.
>   //
>   void draw() {
>     // Initialize/handle reshaped viewport
>     if ( !valid() ) {
>       valid(1);
>       GlInit();
>       ReshapeViewport();
>     }
>     // Clear
>     glClearColor(.5,.5,.5, 0.0);
>     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>     // Setup model matrix
>     glLoadIdentity();
>     glRotatef(spin, 0.5, 1.0, 0.0);   // show all sides of cube
>     // Draw cube with texture assigned to each face
>     glBegin(GL_QUADS);
>       // Front Face
>       glColor3f(1.0, 0.0, 0.0);       // red
>         glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0,  1.0);         // Top 
> Left Of The Texture and Quad
>         glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0,  1.0);         // Top 
> Right Of The Texture and Quad
>         glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0,  1.0);         // 
> Bottom Right Of The Texture and Quad
>         glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0,  1.0);         // 
> Bottom Left Of The Texture and Quad
>       // Back Face
>       glColor3f(0.0, 1.0, 1.0);       // cyn
>         glTexCoord2f(0.0, 1.0); glVertex3f( 1.0,  1.0, -1.0);         // Top 
> Left Of The Texture and Quad
>         glTexCoord2f(1.0, 1.0); glVertex3f(-1.0,  1.0, -1.0);         // Top 
> Right Of The Texture and Quad
>         glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);         // 
> Bottom Right Of The Texture and Quad
>         glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, -1.0);         // 
> Bottom Left Of The Texture and Quad
>       // Top Face
>       glColor3f(0.0, 1.0, 0.0);       // grn
>         glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0, -1.0);         // Top 
> Left Of The Texture and Quad
>         glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0, -1.0);         // Top 
> Right Of The Texture and Quad
>         glTexCoord2f(1.0, 0.0); glVertex3f( 1.0,  1.0,  1.0);         // 
> Bottom Right Of The Texture and Quad
>         glTexCoord2f(0.0, 0.0); glVertex3f(-1.0,  1.0,  1.0);         // 
> Bottom Left Of The Texture and Quad
>       // Bottom Face
>       glColor3f(1.0, 0.0, 1.0);       // mag
>         glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, -1.0, -1.0);         // Top 
> Left Of The Texture and Quad
>         glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, -1.0, -1.0);         // Top 
> Right Of The Texture and Quad
>         glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0,  1.0);         // 
> Bottom Right Of The Texture and Quad
>         glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0,  1.0);         // 
> Bottom Left Of The Texture and Quad
>       // Right face
>       glColor3f(0.0, 0.0, 1.0);       // blu
>         glTexCoord2f(0.0, 1.0); glVertex3f( 1.0,  1.0,  1.0);         // Top 
> Left Of The Texture and Quad
>         glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0, -1.0);         // Top 
> Right Of The Texture and Quad
>         glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0);         // 
> Bottom Right Of The Texture and Quad
>         glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0,  1.0);         // 
> Bottom Left Of The Texture and Quad
>       // Left Face
>       glColor3f(1.0, 1.0, 0.0);       // yel
>         glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0, -1.0);         // Top 
> Left Of The Texture and Quad
>         glTexCoord2f(1.0, 1.0); glVertex3f(-1.0,  1.0,  1.0);         // Top 
> Right Of The Texture and Quad
>         glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0,  1.0);         // 
> Bottom Right Of The Texture and Quad
>         glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);         // 
> Bottom Left Of The Texture and Quad
>     glEnd();
>     // DEBUG: CHECK FOR ERRORS
>     GLenum err = glGetError();
>     if ( err != GL_NO_ERROR ) {
>        fprintf(stderr, "GLGETERROR=%d\n", (int)err);
>     }
>   }
>   int handle(int e) {
>     printf("EVENT=%d\n",e);
>     return(Fl_Gl_Window::handle(e));
>   }
> };
> int main(int argc, char *argv[]) {
>   Fl_Window *win = new Fl_Window(WIN_W, WIN_H);
>   Fl_Menu_Bar *bar = new Fl_Menu_Bar(0,0,WIN_W,25);
>   bar->add("File/New");
>   bar->add("File/Save");
>   bar->add("File/Save As");
>   bar->add("File/Quit");
>   MyGlWindow* mygl = new MyGlWindow(35, 35, WIN_W-45, WIN_H-45, "Texture 
> Test");
>   mygl->end();
>   win->end();
>   mygl->resizable(mygl);
>   mygl->show();
>   win->resizable(win);
>   win->show();
>   return(Fl::run());
> }

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

Reply via email to