openGL & FLTK

Hello all… :slight_smile:
I am using FLTK and I’m having a problem I cannot fix… I am trying to draw lines when dragging the mouse button. Here’s the code I have written in my handle(int) method…

case FL_PUSH:
switch (Fl::event_button()) {
case 3: // Right Mouse Button
if (key == FL_PUSH) {
glBegin(GL_LINES);
glVertex2d(old_x, old_y);
glVertex2d(old_x = Fl::event_x(), old_y = height - Fl::event_y());
glEnd();
}
return 1;
}

This method of writing code works well with just openGL. I cannot see what’s wrong with it… Please help~

Thank you

TS

Hi !

Well, as long as you just want to render the line it would work fine, but a better way to do this is to invalidate the contents of the window in the keyboard handler and let the normal “paint” code to the rendering.

The most common one is that the OpenGL context is not valid in the keyboard handler.

To be able to rendering anything you need an active rendering context (wglMakeCurrent on win32).

In fltk you do this by calling make_current() in your keyboard handler before you rendering anything.

Mikael

Thank you for your reply.
What I’m saying is that it does ~not~ render. It should work, yes, but for some reason, it isn’t.
I don’t really know what to do…
Anything else I can do?

Thank you