FLTK + OpenGL
Download
Report
Transcript FLTK + OpenGL
FLTK and OpenGL
Jyun-Ming Chen
Spring 2010
Topics in Computer Graphics
Content
Review inter-widget communication
“Double.c”-based examples
Idle, timer, … numerous events
Fluid-based implementation
Viewer examples
Review: Widget Talk
Value can be
controlled by the
text widget and the
slider
Demonstrate interwidget
communications
Design
v
value 13
WidgetTalk
Handle()
Using OpenGL in FLTK
Subclass
Fl_Gl_Window
Draw(): display
callback
Redraw():
PostRedisplay
Handle(): mouse/kbd
event handler
Valid(): off when
FLTK creates a new
context for this
window, or when the
window resizes; on
after draw() is called.
reshape
Double.c by Fl_Gl_Window
Class design
Private double angle;
Private double speed;
Public draw();
Public handle();
Public toggleMotion();
“Callback”
Other issues:
Speed control
Time-based animation
Reshape
Display
Mouse
Keyboard
Timer
Idle
Animation
Class method of Fl
Idle function
add_idle(void (*cb)(void*), void* = 0);
void remove_idle(void (*cb)(void*), void* = 0);
Timer function: one-shot timeout callback
Fl::add_timeout (double t, // seconds
Fl_Timeout_Handler,void* = 0);
void remove_timeout(Fl_Timeout_Handler, void* = 0);
void repeat_timeout(double t, Fl_Timeout_Handler,void*
= 0);
Summary: OpenGL Using Fluid
(or Fl_Group)
First example: shape
First, simple application with no
animation!
Create Shape_Win class with
these method
Set_sides
Draw()
Generate interface with fluid:
A double_win and a slider
Callback of the slider: set the sides
and calls redraw
Creating a Double.c
in FLTK
Step 1
Create main()
Create a
function
Step 2
Select main
Create a Window
inside main()
Class Double_Win
A subclass of
Fl_Gl_Window
Must define draw()
Include them in the
directory
Later …
Step 3
First,
create a
group
Add the class
Double_Win into the
window
Add these…
Toggle Motion
Use timeout “fl_spin”
to animate
Spin_on: records the
spin status
Step 4
First, create
a button
Add a button for
toggleMotion
Add these…
Finally,
Save the fluid file
Generate the codes
Compile and run!
Flaux – my addition to FLTK
Glm.c: OBJ reader
Glutshapes.c: the glut primitives
Glutteapot.c: the Utah teapot
Viewer: the class of spherical viewer
Viewer Methods
Void center (float*c);
Void center (const float c[3]);
Float extent();
Void extent (float e);
Float fovY();
Void fovY(float f);
Void set_content (void (*fun)(void));
Color & depth buffers are already cleared
No need to “swapbuffer”… taken care of by FLTK
Void set_glinit(void(void (*fun)(void));
About Viewer
Design philosophy
Only a simple prototype, illustrating how camera
control is done by an event handler
As to the displaying content, simply handed out to
a content function call
If additional control (by GUI)is demanded (e.g.,
turn on/off lights, animation, etc.), one needs to
customize the draw( ) with additional public
methods to be called from other widgets.
MD2chooser is a good example.
Shapes
Sphere, cone, cube, torus
Dodecahedron, octahedron, icosahedron,
tetrahedron
Teapot
About FL/glut.h
I do not wish to mix GLUT with FLTK. Hence,
all shapes routines are extracted out of glut
library and make them in an aux library.
Other Examples
OBJ_Viewer
Version 0: straight modification from
viewer
Version 1: ViewerGLM
augmented Viewer with: pmodel and
set_objmodel ()
Version 2: Derive OBJ_Viewer from
Viewer
OBJ Chooser
Use Fl_File_Chooser, ViewerGLM and
Fluid
Texture Experiment
Using plain Viewer
Testing wrap and filters