Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring 2010Topics in Computer Graphics FLTK and OpenGL Jyun-Ming Chen.

Similar presentations


Presentation on theme: "Spring 2010Topics in Computer Graphics FLTK and OpenGL Jyun-Ming Chen."— Presentation transcript:

1 Spring 2010Topics in Computer Graphics FLTK and OpenGL Jyun-Ming Chen

2 Content Review inter-widget communication “ Double.c ” -based examples Idle, timer, … numerous events Fluid-based implementation Viewer examples

3 Review: Widget Talk Value can be controlled by the text widget and the slider Demonstrate inter- widget communications 13 value v Design

4 WidgetTalk

5 Handle()

6 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

7 Double.c by Fl_Gl_Window 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

8 Animation 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); Class method of Fl

9 Summary: OpenGL Using Fluid (or Fl_Group)

10 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

11 Creating a Double.c in FLTK

12 Step 1 Create main() Create a function

13 Step 2 Select main Create a Window inside main()

14 Class Double_Win A subclass of Fl_Gl_Window Must define draw() Include them in the directory Later …

15 Step 3 Add the class Double_Win into the window First, create a group Add these…

16 Toggle Motion Use timeout “ fl_spin ” to animate Spin_on: records the spin status

17 Step 4 Add a button for toggleMotion First, create a button Add these…

18 Finally, Save the fluid file Generate the codes Compile and run!

19 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

20 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));

21 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.

22 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.

23 Other Examples

24 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

25 OBJ Chooser Use Fl_File_Chooser, ViewerGLM and Fluid

26 Texture Experiment Using plain Viewer Testing wrap and filters


Download ppt "Spring 2010Topics in Computer Graphics FLTK and OpenGL Jyun-Ming Chen."

Similar presentations


Ads by Google