260 likes | 561 Views
FLTK and OpenGL. Jyun-Ming Chen. Content. Review inter-widget communication “ Double.c ” -based examples Idle, timer, … numerous events Fluid-based implementation Viewer examples. Value can be controlled by the text widget and the slider Demonstrate inter-widget communications. v.
E N D
FLTK and OpenGL Jyun-Ming Chen Topics in Computer Graphics
Content • Review inter-widget communication • “Double.c”-based examples • Idle, timer, … numerous events • Fluid-based implementation • Viewer examples
Value can be controlled by the text widget and the slider Demonstrate inter-widget communications v value 13 Review: Widget Talk Design
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. Using OpenGL in FLTK reshape
Class design Private double angle; Private double speed; Public draw(); Public handle(); Public toggleMotion(); Other issues: Speed control Time-based animation “Callback” Reshape Display Mouse Keyboard Timer Idle Double.c by Fl_Gl_Window
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); Animation Class method of Fl
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
Create main() Create a function Step 1
Select main Create a Window inside main() Step 2
A subclass of Fl_Gl_Window Must define draw() Include them in the directory Class Double_Win Later …
Add the class Double_Win into the window First, create a group Add these… Step 3
Use timeout “fl_spin” to animate Spin_on: records the spin status Toggle Motion
Add a button for toggleMotion First, create a button Add these… Step 4
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.
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