computer graphics
Skip this Video
Download Presentation
computer graphics

Loading in 2 Seconds...

play fullscreen
1 / 20

computer graphics - PowerPoint PPT Presentation

  • Uploaded on

computer graphics. TA: Nouf Al-Harbi [email protected] . 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.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'computer graphics' - edie

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
computer graphics lab 3

Computer graphicslab 3

Introduction to OpenGL

lab 3 objectives
Lab 3 objectives
  • By the end of this lab, you will be able to :
    • Using Keyboard Interaction functions
    • Using Mouse Interaction functions
Programming ExampleDraw white triangle, Make theses changes and commands based on the user interaction
part 1
Part 1

Interaction with keyboard ..

interaction with keyboard
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
1 glutkeyboardfunc
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.
2 glutspecialfunc
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_F10
  • GLUT_KEY_F11
  • GLUT_KEY_F12
Example ..

In main function

part 2
Part 2

Interaction with Mouse ..

A- Mouse click

B- Mouse motion

a mouse click glutmousefunc
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:
    • 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.
Example ..

In main function

b mouse motion
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.
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.
active motion example
Active Motion Example ..

In main function

other functions glutidlefunc
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.
other functions glutswapbuffers
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);

Materials of this lab are prepared using: