OpenGL in FLTK  .

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
GUI Programming Alex Feldmeier.
FLUID  The Fast Light User Interface Designer, or FLUID, is a graphical editor that is used to produce FLTK source code  Creates C++ code  Compile.fl.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
ICM Week 2. Structure - statements and blocks of code Any single statement ends with semicolon ; When we want to bunch a few statements together we use.
Cosc 4755 Phone programming: GUI Concepts & Threads.
Based on slides created by Edward Angel
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Bertrand Bellenot ROOT Users Workshop Mar ROOT GUI Builder Status & Plans ROOT & External GUI World MFC, FOX, Qt, PVSS… Snapshot of the Future.
GLWidget Description Jason Goffeney 3/8/2006. GLWidget The GLWidget class extends the Qt QGLWidget. The QGLWidget is a Qt Widget that happens to have.
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
FLTK Tutorial.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
Lecture 3 OpenGL.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Computer Graphics I, Fall 2010 Input and Interaction.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Adding a New Option to the Framework. Introduction This is intended as a step by step guide to adding a new action to the menu or toolbar. The order of.
FLTK. Objectives Install and Use FLTK Widgets ◦Callbacks Handling event ◦System events ◦Mouse events ◦Keyboard events.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Spring 2010Topics in Computer Graphics FLTK and OpenGL Jyun-Ming Chen.
Applications Development
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
CIS 3.5 Lecture 2.2 More programming with "Processing"
FLTK. Оконная система, DWM XWindows (Linux/UNIX) Windows DWM (Win Vista, 7, 8)
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Computer Graphics I, Fall 2010 Working with Callbacks.
University of New Mexico
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Changing a Word table format Changing a Word table format (1 of 5) 1. Double click the Word table you want to edit. 1.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Working with Callbacks
Introduction to JavaScript Events
Introduction to the Mouse
FLTK The Fast Light Toolkit
CSC461 Lecture 8: Input Devices
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
The User Interface Lecture 2 Mon, Aug 27, 2007.
Event Driven Programming
Computation as an Expressive Medium
Interfaces and Constructors
Working with Callbacks
Simple Windows Applications
More programming with "Processing"
Input and Interaction Ed Angel
Event Driven Programming Anatomy – Handle
University of New Mexico
Input and Interaction Ed Angel
Presentation transcript:

OpenGL in FLTK  

Timers Not 100% accurate (don't measure time with them) Single shot timeouts  void add_timeout(double t, Fl_Timeout_Handler, void* d) call a function in t seconds void remove_timeout(Fl_Timeout_Handler, void* d) cancels a timeout (harmless if timer already triggered) void repeat_timeout(double t, Fl_Timeout_Handler, void* d) call a function t seconds after the last timeout triggered can only be called from within a timer callback

Simple Timer Print "TICK" every second void callback(void*) {     printf("PUTS");     Fl::repeat_timeout(1.0, callback); } int main()     Fl::add_timeout(1.0, callback);     return Fl::run()

Add Timer to Move Out CustomWidget Goal: Have slider slide back and forth Use globals for all variables and widgets Make customWidget global Add variable to control direction Callback Setup repeat timer Move widget in specified direction Check if we have reached max or min and change direction Main Set initial direction Initial timer call

Idle Similar to GLUT add_idle(void (*cb)(void*), void *) function to call whenever nothing else is happening can have multiple callbacks remove_timout(void (*cb)(void*), void *) removes callback function if it exists

OpenGL Widget Create a subclass of Fl_Gl_Window #include <FL/Fl_Gl_Window.H> #include <FL/gl.h> Will include <GL/gl.h> Need to implement draw function in subclass Setup view port valid() will return false if needed Actual drawing

OpenGL Widget class OpenGLWindow : public Fl_Gl_Window { private:     void draw() {         if ( !valid() ) {              // initialization         }         // draw     }; public:     OpenGLWindow(int x, int y, int w, int h,                  const char* l = 0)         : Fl_Gl_Window(x, y, w, h, l) { }; };

3D Gasket in FLTK Put all code into subclass of Fl_Gl_Window Copy triangle, tetra, and divide_tetra functions Move colors into tetra and v into draw All reference to width are height need to be replaced with w() and h() Hard code number of sub divisions Create a window and place OpenGL widget in it

Widget to Control Sub Divisions Recommendation: make all widgets global OpenGL draw() now get value from slider widget divide_tetra(v[0], v[1], v[2], v[3],              divisions->value()); Add a slider (and label) for number of sub divisions     divisions = new Fl_Slider(100, 480, 540,                               20);     divisions->type(FL_HORIZONTAL);     divisions->range(1, 20);     divisions->step(1);

Widget to Control Sub Divisions Need to tell FLTK/OpenGL Widget to update call widget's redraw() Need to redraw when we change slider (callback)    void update(Fl_Widget*, void*) {     glwindow->redraw(); }     // when creating slider     divisions->callback(update);

Assignment 1 Part 3 in FLTK Will use toggle button instead of mouse clicks Timer instead of idle   Create toggle button and start timer spinning = new Fl_Button(545, 485, 90, 20,                          "Spinning"); spinning->type(FL_TOGGLE_BUTTON); Fl::add_timeout(1, timer, 0); spin = 0.0f;

Assignment 1 Part 3 in FLTK Update spin and redraw if necessary void timer(void*) {     Fl::repeat_timeout(0.02, timer);     if ( spinning->value() )     {         spin += 1.0f;         if ( spin > 360.0f )             spin -= 360.0f;         glwindow->redraw();     } }  

Assignment 1 Part 3 in FLTK Add spin to OpenGL widget extern float spin; Rotate before drawing (before glBegin) glLoadIdentity(); glRotatef(spin, 0.0f, 1.0f, 0.0f);

Events Implement int handle(int event) event is mouse click & drag, mouse wheel, keyboard presses & release, system events Return 1 if event use Event consumed Return 0 is unesed Event will continue to be passed around Additional helper functions Mouse: event_button() event_x()  Keyboard: event_key()

Spin Triangle with Mouse Goal: mouse drags will rotate object   Filter out only used event Pass rest to default handler No previous mouse position with drag event (only current) Initial click will seed last position Need to hold current state

Spin Triangle with Mouse Header:     int oldX, oldY;     float vRotation, hRotation;     int handle(int event);   Constructor:     vRotation = hRotation = 0.0f; Draw:     glRotatef(hRotation, 0.0f, 1.0f, 0.0f);     glRotatef(vRotation, 1.0f, 0.0f, 0.0f);

Spin Triangle with Mouse Handle switch ( event ) { case FL_DRAG:      hRotation += Fl::event_x() - oldX;      vRotation += Fl::event_y() - oldY;      redraw();  case FL_PUSH:      oldX = Fl::event_x();      oldY = Fl::event_y();      return 1;  default: return Fl_Gl_Window::handle(event);  }