KEMBAR78
Lecture 6 introduction to open gl and glut | PPTX
Shahid Mahmood
 Introduction to OpenGL
 Supporting Libraries
 Initially, Silicon Graphics Inc. Developed a
system called “Graphics Library, GL”
 In 1992, a variation of GL, called OpenGL was
announced
 OpenGL was designed to be platform-
independent – to run across a wide range of
computer hardware, not just on Silicon
Graphics machines
 Soon, OpenGL was accepted as a standard
computer graphics programming , due to its
power and portability
 As we know, OpenGL is not a programming
language, it’s the specification of an
Application Programming Interface (API)
 It defines a set functions for creating
computer graphics
 OpenGL provides 3D geometric
objects, such as lines, polygons,
triangle meshes, spheres, cubes,
quadric surfaces, and curves
 It provides 3D modeling
transformations and viewing
functions to create views of 3D
scenes, using the idea of virtual
camera
 OpenGL supports high-quality rendering of
scenes, including hidden-surface removal,
multiple light sources, transparency, textures,
blending, fog
 It provides display lists for creating graphics
caches and hierarchical models. It also supports
the interactive picking of objects
 It supports the manipulation of images as pixels,
enabling frame-buffer effects such as anti-
aliasing, motion blur, etc.
 OpenGL is itself is only concerned
with graphics rendering – OpenGL
functions always start with “gl”
 To extend OpenGL’s functionality,
two libraries have been developed,
OpenGL Utility Library (GLU), and the
OpenGL Utility Toolkit (GLUT)
 GLU provides functions to draw
more complex primitives, such as
curves and surfaces, it also help
specify 3D views of scenes
 All GLU functions names start with
“glu”
 GLUT provides the facilities for interaction
that OpenGL lacks
 It provides windows management functions,
handling input events from the mouse and
keyboard
 It also provides basic functions for creating
Graphical User Interfaces (GUIs).
 All GLUT functions names start with “glut”
 Since OpenGL has been designed to be device-independent,
it is not concerned with the exact makes and model of the
graphics display and interaction hardware it uses, instead its
functions refer to windows and events
 An OpenGL window is a rectangular area on a physical display
screen into which OpenGL draws graphics
 An OpenGL event occurs when the operates an input device
 To respond to the input event, the application must provide a
function known as a callback function to handle the event
OpenGL automatically calls the application’s function, passing it
with event data
 OpenGL does not draw its graphics
directly to the window
 Instead draws into a data structure (an
array of pixels) inside OpenGL called
the frame-buffer, or simply buffer
 Periodically, OpenGL copies the pixels
in the frame buffer into the window.
GLUT, GLEW Includes
Create GLUT Window
Register callback
functions
User Initializations
Initialize GLUT
GLUT main loop
 Open window
◦ Configure display mode,
Window position/size
 Register input callback
Function (GLUT)
◦ Render, resize, input: keyboard,
mouse, etc
 User Initialization
◦ Set background color, clear
Color, etc
◦ Generate points to be drawn
◦ Initialize shader stuff
◦ Intitalize GLEW, Register GLUT callbacks, glutMainLoop()
GLUT, GLEW Includes
Create GLUT Window
Register callback
functions
User Initializations
Initialize GLUT
GLUT main loop
 GLUT is used to create and open window
◦ glutInit(&argc, argv); // Initializes GLUT
◦ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 Sets display mode (e.ge single frame-buffer with RGB
colors)
◦ glutInitWindowsSize(640, 480);
 Sets window size (Width x Height) in pixels
◦ glutInitPosition (100, 150);
 Sets location of upper left corner of window
glutCreateWindow(“Window title”);
open window with title “Window title”
 Void main(int argc, char** argv) {
 // initialize toolkit, set display mode and create
window
glutInit(&argc, argv); // initialize toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow(“Window title”);
…
 Register callback functions,
 Do user initialization
 Wait in glutMainLoop for events
 …
}
 OpenGL programs are event-driven
 Sequential program
◦ Start program at main()
◦ Perform actions 1, 2, 3 … N
◦ End
 Event-driven program
◦ Start at main()
◦ Initialize
◦ Wait in infinite loop
 Wait till defined event occurs
 Event occurs => take defined actions
 Program only responds to events
 Do nothing until event occurs
◦ Mouse clicks
◦ Keyboard stroke
◦ Window resize
 Programmer defines
◦ Events that program should respond to
◦ Actions to be taken when event occurs
◦ Wait in infinite loop
 System (window)
◦ Receives event, maintains event queue
 Programmer registers callback
functions (event handler)
 Callback function called when event
occurs
 Example: Programmer
◦ Declare function onMouseClick, to be called on mouse click
◦ Register the function glutMouseFunc(onMouseClick);
 When OS receives mouse click, calls
callback function onMouseClick
 Register callbacks for all events your
program will react to
 No registered callback = no action
 If no registered keyboard callback
function, hitting keyboard keys
generates no response.
 GLUT callback functions in skeleton
 glutDisplayFunc(myDisplay) // image
to be drawn initially
 glutReshapeFunc(myReshape) //
called when window is reshaped
 glutMouseFunc(myReshape) // called
when mouse button is pressed

Lecture 6 introduction to open gl and glut

  • 1.
  • 2.
     Introduction toOpenGL  Supporting Libraries
  • 3.
     Initially, SiliconGraphics Inc. Developed a system called “Graphics Library, GL”  In 1992, a variation of GL, called OpenGL was announced  OpenGL was designed to be platform- independent – to run across a wide range of computer hardware, not just on Silicon Graphics machines
  • 4.
     Soon, OpenGLwas accepted as a standard computer graphics programming , due to its power and portability  As we know, OpenGL is not a programming language, it’s the specification of an Application Programming Interface (API)  It defines a set functions for creating computer graphics
  • 5.
     OpenGL provides3D geometric objects, such as lines, polygons, triangle meshes, spheres, cubes, quadric surfaces, and curves  It provides 3D modeling transformations and viewing functions to create views of 3D scenes, using the idea of virtual camera
  • 6.
     OpenGL supportshigh-quality rendering of scenes, including hidden-surface removal, multiple light sources, transparency, textures, blending, fog  It provides display lists for creating graphics caches and hierarchical models. It also supports the interactive picking of objects  It supports the manipulation of images as pixels, enabling frame-buffer effects such as anti- aliasing, motion blur, etc.
  • 7.
     OpenGL isitself is only concerned with graphics rendering – OpenGL functions always start with “gl”  To extend OpenGL’s functionality, two libraries have been developed, OpenGL Utility Library (GLU), and the OpenGL Utility Toolkit (GLUT)
  • 8.
     GLU providesfunctions to draw more complex primitives, such as curves and surfaces, it also help specify 3D views of scenes  All GLU functions names start with “glu”
  • 9.
     GLUT providesthe facilities for interaction that OpenGL lacks  It provides windows management functions, handling input events from the mouse and keyboard  It also provides basic functions for creating Graphical User Interfaces (GUIs).  All GLUT functions names start with “glut”
  • 10.
     Since OpenGLhas been designed to be device-independent, it is not concerned with the exact makes and model of the graphics display and interaction hardware it uses, instead its functions refer to windows and events  An OpenGL window is a rectangular area on a physical display screen into which OpenGL draws graphics  An OpenGL event occurs when the operates an input device  To respond to the input event, the application must provide a function known as a callback function to handle the event OpenGL automatically calls the application’s function, passing it with event data
  • 11.
     OpenGL doesnot draw its graphics directly to the window  Instead draws into a data structure (an array of pixels) inside OpenGL called the frame-buffer, or simply buffer  Periodically, OpenGL copies the pixels in the frame buffer into the window.
  • 12.
    GLUT, GLEW Includes CreateGLUT Window Register callback functions User Initializations Initialize GLUT GLUT main loop
  • 13.
     Open window ◦Configure display mode, Window position/size  Register input callback Function (GLUT) ◦ Render, resize, input: keyboard, mouse, etc  User Initialization ◦ Set background color, clear Color, etc ◦ Generate points to be drawn ◦ Initialize shader stuff ◦ Intitalize GLEW, Register GLUT callbacks, glutMainLoop() GLUT, GLEW Includes Create GLUT Window Register callback functions User Initializations Initialize GLUT GLUT main loop
  • 14.
     GLUT isused to create and open window ◦ glutInit(&argc, argv); // Initializes GLUT ◦ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);  Sets display mode (e.ge single frame-buffer with RGB colors) ◦ glutInitWindowsSize(640, 480);  Sets window size (Width x Height) in pixels ◦ glutInitPosition (100, 150);  Sets location of upper left corner of window glutCreateWindow(“Window title”); open window with title “Window title”
  • 15.
     Void main(intargc, char** argv) {  // initialize toolkit, set display mode and create window glutInit(&argc, argv); // initialize toolkit glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(100, 150); glutCreateWindow(“Window title”); …
  • 16.
     Register callbackfunctions,  Do user initialization  Wait in glutMainLoop for events  … }
  • 17.
     OpenGL programsare event-driven  Sequential program ◦ Start program at main() ◦ Perform actions 1, 2, 3 … N ◦ End  Event-driven program ◦ Start at main() ◦ Initialize ◦ Wait in infinite loop  Wait till defined event occurs  Event occurs => take defined actions
  • 18.
     Program onlyresponds to events  Do nothing until event occurs ◦ Mouse clicks ◦ Keyboard stroke ◦ Window resize  Programmer defines ◦ Events that program should respond to ◦ Actions to be taken when event occurs ◦ Wait in infinite loop  System (window) ◦ Receives event, maintains event queue
  • 19.
     Programmer registerscallback functions (event handler)  Callback function called when event occurs  Example: Programmer ◦ Declare function onMouseClick, to be called on mouse click ◦ Register the function glutMouseFunc(onMouseClick);  When OS receives mouse click, calls callback function onMouseClick
  • 20.
     Register callbacksfor all events your program will react to  No registered callback = no action  If no registered keyboard callback function, hitting keyboard keys generates no response.
  • 21.
     GLUT callbackfunctions in skeleton  glutDisplayFunc(myDisplay) // image to be drawn initially  glutReshapeFunc(myReshape) // called when window is reshaped  glutMouseFunc(myReshape) // called when mouse button is pressed