1 / 20

computer graphics

computer graphics. TA: Nouf Al-Harbi nouf200@hotmail.com . Computer graphics lab 3. Introduction to OpenGL. Lab 3 objectives. By the end of this lab, you will be able to : Using Keyboard Interaction functions Using Mouse Interaction functions.

edie
Download Presentation

computer graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. computer graphics TA: Nouf Al-Harbi nouf200@hotmail.com

  2. Computer graphicslab 3 Introduction to OpenGL

  3. Lab 3 objectives • By the end of this lab, you will be able to : • Using Keyboard Interaction functions • Using Mouse Interaction functions

  4. Programming ExampleDraw white triangle, Make theses changes and commands based on the user interaction

  5. Part 1 Interaction with keyboard ..

  6. Interaction with keyboard • GLUT allows us to build applications that detect keyboard input using either the “normal” keys, or the special keys like F1 and Up. • We must notify GLUT which function(s) will perform the required processing when a key is pressed. • GLUT provides two functions to register callbacks for keyboard events that occur when you press a key

  7. 1- glutKeyboardFunc • he function used as an argument to glutKeyboardFunc needs to have three arguments. • The first provides the ASCII code of the key pressed • the remaining two arguments provide the mouse position when the key is pressed. • The mouse position is relative to the top left corner of the client area of the window.

  8. 2- glutSpecialFunc • The GLUT_KEY_* are predefined constants in glut.h. • GLUT_KEY_F1 • GLUT_KEY_F2 • GLUT_KEY_F3 • GLUT_KEY_F4 • GLUT_KEY_F5 • GLUT_KEY_F6 • GLUT_KEY_F7 • GLUT_KEY_F8 • GLUT_KEY_F9 • GLUT_KEY_F10 • GLUT_KEY_F11 • GLUT_KEY_F12 • GLUT_KEY_LEFT • GLUT_KEY_RIGHT • GLUT_KEY_UP • GLUT_KEY_DOWN • GLUT_KEY_PAGE_UP • GLUT_KEY_PAGE_DOWN • GLUT_KEY_HOME • GLUT_KEY_END • GLUT_KEY_INSERT

  9. Example .. In main function

  10. Ascii code for characters ..

  11. Part 2 Interaction with Mouse .. A- Mouse click B- Mouse motion

  12. A- Mouse Click: glutMouseFunc • the function that will handle the mouse click events must have four parameters • The first relates to which button was pressed, or released: • GLUT_LEFT_BUTTON • GLUT_MIDDLE_BUTTON • GLUT_RIGHT_BUTTON • The second argument relates to the state of the button (pressed or released) • GLUT_DOWN • GLUT_UP • The remaining two parameters provide the (x,y) coordinates of the mouse relatively to the upper left corner of the client area of the window.

  13. Example .. In main function

  14. B- Mouse Motion • There are two types of motion that GLUT handles: • active and passive motion. • Active motion occurs when the mouse is moved and a button is pressed. • Passive motion is when the mouse is moving but no buttons are pressed. • As usual you must register with GLUT the function that will be responsible for handling the motion events.

  15. The parameters for the motion processing function are the (x,y) coordinates of the mouse relatively to the upper left corner of the window’s client area.

  16. Passive Motion Example .. In main function

  17. Active Motion Example .. In main function

  18. Other functions .. glutIdleFunc • we must tell GLUT that when the application is idle, the render function should be called. • so a GLUT program can perform background processing tasks or continuous animation when window system events are not being received. • GLUT provides a function, glutIdleFunc, that lets you register a callback function to be called when the application is idle. • void glutIdleFunc(void (*func)(void)); • func– The name of the function that will be called whenever the application is idle.

  19. Other functions .. glutSwapBuffers • void glutSwapBuffers(void); • glutSwapBuffersswaps the buffers of the current window if double buffered. • We should tell the GLUT that we used double buffers • glutInitDisplayMode(GLUT_DOUBLE);

  20. REFERENCES: Materials of this lab are prepared using: Lighthouse3d: http://www.lighthouse3d.com/opengl/glut/index.php?1

More Related