Computer graphics
Download
1 / 20

computer graphics - PowerPoint PPT Presentation


  • 110 Views
  • 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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
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_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


Example
Example ..

In main function


Ascii code for characters
Ascii code for characters ..


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:

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


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


    Passive motion example
    Passive Motion Example ..

    In main function


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


    References
    REFERENCES:

    Materials of this lab are prepared using:

    Lighthouse3d: http://www.lighthouse3d.com/opengl/glut/index.php?1


    ad