Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive.

Similar presentations


Presentation on theme: "Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive."— Presentation transcript:

1 Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive Computer Graphics – A Top Down Approach with OpenGL, Addison Wesley, 2001

2 Fundamentals of Computer Graphics2 Input & Interaction Till now – no interaction 1.Introduction of devices for interaction 2.how devices “appear” in your program 3.client-server network & client-server graphics 4.development of a painting program First attempt: - 37 years! Project Sketchpad – Sutherland Different approach will be taken – we will use API, but OpenGL does not support it directly – due to portability of the renderer, interaction with OS etc.

3 Fundamentals of Computer Graphics3 Input Devices Two possible ways to see input devices: as a physical device – keyboard, mouse, trackball, etc. as a logical device – from a programmer perspective – with specified functionality, in graphics more complex the separation of physical and logical levels enable us to make programs more flexible, independent from the actual physical device

4 Fundamentals of Computer Graphics4 Physical Input Devices Physical input devices: pointing device – allows to indicate position & send signals/interrupts to the computer – relative/absolute positioning keyboard device – almost physical keyboard – returns character codes to a program

5 Fundamentals of Computer Graphics5 Physical Input Devices Absolute positioning: data tablets light pen joystick – variable-sensitivity device & haptic device spaceball – up-down, left-right, front-back & 3 independent twists

6 Fundamentals of Computer Graphics6 Logical Input Devices Some APIs (PHIGS, GKS, Direct xx) supports 6 classes of logical input devices – OpenGL does not take this approach String – logical device providing ASCII strings – keyboard Locator – provides a position in world coordinates – usually implemented via pointing device – mouse, trackball. OpenGL provides similar but conversion from screen coordinates to world coordinates must be made by a user Pick – returns identifier of an object – in OpenGL process called selection can be used to accomplish picking

7 Fundamentals of Computer Graphics7 Logical Input Devices Choice – allows the user to select on of a discrete number of options – in OpenGL various widgets provided by the window system can be used; widget is a graphical interactive device provided by window system or a toolkit (menu with n selections etc.) Dial – provides analog input to the user program – slidebars etc. Stroke – device returns an array of locations – different implementations – usually: mouse button down, transfer data to an array with different positions, release button – ends the transfer

8 Fundamentals of Computer Graphics8 Input Devices & Modes Two entities: a measure process – is what the device returns to the user program (string from a keyboard) a device trigger – is a physical input on the device which user can signal the computer (return – end of the process) Modes: request – value is returned on a request sample mode – actual value is given (no buffering) request_locator ( device_id, &measure); /* usual form */ sample_locator (device_id, &measure);

9 Fundamentals of Computer Graphics9 Input Devices & Modes Request versus Sample modes Generally sample & request modes are not sufficient for Human-Computer-Interface (HCI)

10 Fundamentals of Computer Graphics10 Input Devices & Modes Event mode working in environment with multiple input devices – each has its own trigger and running measure process each time when the device is triggered – the event is generated, the measure with the process identifier is placed in an event queue. The program can examine the front event in the queue and decides what to do – this is used for GKS, PHIGS etc.

11 Fundamentals of Computer Graphics11 Input Devices & Modes - Callback Callback another approach – association of a callback function with a specific type of event – mostly used in windowing system and client/server environments int main (...) {....glutMouseFunc(mouse); glutDisplayFunc(...);..}............ void mouse_callback_func(int button, int state, int x, int y) { if button ==GLUT_LEFT_BUTTON && state==GLUT_DOWN) drawSquare(x,y); /*users function*/ if button ==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) exit (); } /* window reshape principle */

12 Fundamentals of Computer Graphics12 Clients-Servers Our programs worked on single & isolated system so far, but it should also work in distributed computing and networks Distributed graphics, projection walls etc.

13 Fundamentals of Computer Graphics13 Display Lists Instructions are stored in a display memory – display file – display list Modes: - immediate – each element is processed and displayed - retained – objects are defined & stored in a display list on a server & redisplayed on the client request Display processor architecture Early graphics systems - 1960

14 Fundamentals of Computer Graphics14 Definition & Execution of Display Lists #define BOX 1 glNewList(Box, GL_COMPILE); /* sends to the server*/ glBegin(GL_POLYGON); glColor3f(1.0, 1.0, 1.0); glVertex2f(-1.0, -1.0); glVertex2f( 1.0, -1.0); glVertex2f( 1.0, 1.0); glVertex2f(-1.0, 1.0); glEnd( ); glEndList ( ); /* GL_COMPILE_AND_EXECUTE – immediate display */ Drawing – execution glCallList(BOX);

15 Fundamentals of Computer Graphics15 Display Lists & Transformations If model-view or projection matrices changed between execution of the display list – the drawn model will appear at different positions glMatrixModel(GL_PROJECTION); for (i=1; i<5; i++); { glLoadIdentity( ); gluOrtho2D(-2.0*i, 2.0*i, -2.0*i, 2.0*i ); glCallList(BOX); }

16 Fundamentals of Computer Graphics16 Display Lists & Push/Pop ! Color is changed whenever the list is executed Execution of the display list changes the state and attributes in general – may cause unexpected effects it is possible and recommended to store them in the stack at the beginning of the display list specification glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix( ); at the end of the display list specification glPopAttrib( ); glPopMatrix ( );

17 Fundamentals of Computer Graphics17 Characters, Fonts & Strings Study chapter 3.4.2 - 3.4.3 on your own

18 Fundamentals of Computer Graphics18 Programming Event Driven Input Pointing device: passive move event – mouse moved without pressing a button move event - mouse moved with a button pressed, or button released (some systems counts the pushing & releasing of a button as only a single event) glutMouseFunc(mouse_callback_func) /* registration */ void mouse_callback_func(int button, int state, int x, int y); { if (button==GLUT_LEFT_BUTTON && state==GLUT_DOWN) exit ( ); } /* the left button pressed will be omitted no action will be taken as no corresponding action is specified */

19 Fundamentals of Computer Graphics19 Programming Event Driven Input int main (int argc, char **argv); { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateWindow(“square”);/* create a window with name square */ myinit( ); glutReshapeFunc(myReshape); /* generated if window size changed*/ glutMouseFunc(mouse); /* activated if status or position of a mouse changed */ glutDisplayFunc(display); /* GLUT call back requires it strictly – in case of no action */ /* void display ( ) { } must be specified – empty function */ glutMainLoop( ); }

20 Fundamentals of Computer Graphics20 Programming Event Driven Input Keyboards events: glutKeyBoardFunc ( keyboard); /* registration */ void keyboard (unsigned char key, int x, int y); {if (key == ‘q’ || key == ‘Q’) exit ( ); /* exits the program */ } Special functions: glutPostDisplay ( ) /* if window iconified redrawing is postoned */ Multiple Window management: id = glutCreateWindow(“second window”); /* int id*/ glutSetWindow (id) ; /* sets the window into which object will be rendered */

21 Fundamentals of Computer Graphics21 Menus & Picking Study chapter 3.6 – 3.7 on your own

22 Fundamentals of Computer Graphics22 Menu Pop-up menus glutCreateMenu(demo_menu); glutAddmenuEntry(“quit”,1); glutAddmenuEntry(“increase square size”,2); glutAddmenuEntry(“decrease square size”,3); glutAttachmenu(GLUT_RIGHT_BUTTON); void demo_menu(int id); { if (id ==1) exit ( ); else if (id ==2) size = size * 2; else if (id ==3) size = size / 2; glutPostRedisplay( ); /* glutDisplayFunc is called-redisplay without menu */ }

23 Fundamentals of Computer Graphics23 Animation Study chapter 3.9 on your own

24 Fundamentals of Computer Graphics24 Animation For animation – double buffering glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Buffers: front – content visible on the display back – where the rendering is made to the display function must be added glutSwapBuffers ( );

25 Fundamentals of Computer Graphics25 Conclusion Study on your own: Chapter 3.4.2 – 3, text, strings & character drawing Chapter 3.8 – simple Paint Program, Chapter 3.9 – Animating Interactive Program Chapter 3.10 – Design of Interactive Programs Make some experiments with display list construction and discuss efficiency of its use for complex objects


Download ppt "Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive."

Similar presentations


Ads by Google