Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Lecture 33

Similar presentations


Presentation on theme: "Computer Graphics Lecture 33"— Presentation transcript:

1 Computer Graphics Lecture 33

2 OpenGL Programming Taqdees A. Siddiqi cs602@vu.edu.pk

3 Many OpenGL functions are used specifically for drawing objects such as points, lines, polygons, and bitmaps.

4 Some functions control the way that some of this drawing occurs (such as those that enable antialiasing or texturing). Other functions are specifically concerned with framebuffer manipulation.

5 The topics discussed here describe how all of the OpenGL functions work together to create the OpenGL processing pipeline. Here we also take a closer look at the stages in which data is actually processed, and tie these stages to OpenGL functions.

6 The following diagram details the OpenGL processing pipeline
The following diagram details the OpenGL processing pipeline. For most of the pipeline, you can see three vertical arrows between the major stages.

7 These arrows represent vertices and the two primary types of data that can be associated with vertices: color values and texture coordinates.

8

9 Writing a program, using OpenGL, for any of the operating system we can use OpenGL Utility Library name glut.

10 glut is platform independent. glut can:
create window get keyboard input and run an event handler or message loop of application

11 Functions start with the prefix “gl” are the core OpenGL functions and those start with “glu” or “glut” are the OpenGL utility library functions.

12 Let’s write a program using “glut” and also OpenGL function to create graphics.

13 #include <GL/glut.h>
int main() { glutCreateWindow( "first graphics window" ); }

14 String argument in the window is used as window name.
glutCreateWindow creates a top-level window. String argument in the window is used as window name.

15 Implicitly, the current window is set to the newly created window.
Each created window has a unique associated OpenGL context.

16 window's display state is not actually acted upon until glutMainLoop is entered.
This means until glutMainLoop is called, rendering to a created window is ineffective.

17 The int value returned is a unique identifier for the window.
identifiers starts from one, identifier can be used for calling glutSetWindow.

18 Now we will use more features of glut library in a sample program provided you in the notes; here we will discuss them in details.

19 glutInitDisplayMode

20 glutInitDisplayMode sets the initial display mode.
void glutInitDisplayMode ( unsigned int mode); Display mode, normally the bitwise OR-ing of GLUT display mode bit masks.

21 Modes have values: GLUT_RGBA Bit mask to select an RGBA mode window. This is the default if neither GLUT_RGBA nor GLUT_INDEX are specified.

22 GLUT_RGB An alias for GLUT_RGBA.
GLUT_INDEX Bit mask to select a color index mode window. This overrides GLUT_RGBA.

23 GLUT_SINGLE Bit mask to select a single buffered window
GLUT_SINGLE Bit mask to select a single buffered window. This is the default. GLUT_DOUBLE Bit mask to select a double buffered window. This overrides GLUT_SINGLE if it is also specified.

24 GLUT_ACCUM Bit mask to select a window with an accumulation buffer.
GLUT_ALPHA Bit mask to select a window with an alpha component to the color buffer(s).

25 GLUT_DEPTH Bit mask to select a window with a depth buffer.
GLUT_STENCIL Bit mask to select a window with a stencil buffer.

26 GLUT_MULTISAMPLE Bit mask to select a window with multisampling support. If multisampling is not available, a non-multisampling window will automatically be chosen.

27 GLUT_STEREO Bit mask to select a stereo window.
GLUT_LUMINANCE Bit mask to select a window with a ``luminance'' color model.

28 glutReshapeWindow

29 glutReshapeWindow requests a change to the size.
void glutReshapeWindow(int width, int height); New width and height of window in pixels.

30 This requests a change in the size of the current window
This requests a change in the size of the current window. The width and height parameters are size extents in pixels. The width and height must be positive values.

31 The requests by glutReshapeWindow is executed after returning to the main event loop.
This allows multiple glutReshapeWindow, glutPositionWindow, and glutFullScreen requests with same window be coalesced.

32 glutKeyboardFunc

33 glutKeyboardFunc sets the keyboard callback for the current window.
void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)); func The new keyboard callback function.

34 glutKeyboardFunc sets the keyboard callback for the current window
glutKeyboardFunc sets the keyboard callback for the current window. When a user types into the window, each key press generating an ASCII character will generate a keyboard callback.

35 The x and y callback parameters indicate the mouse location in window relative coordinates when the key was pressed.

36 glutDisplayFunc

37 glutDisplayFunc sets the display callback for the current window.
void glutDisplayFunc(void (*func)(void)); func The new display callback function.

38 glutDisplayFunc sets the display callback for the current window
glutDisplayFunc sets the display callback for the current window. When GLUT determines that the normal plane for the window needs to be redisplayed, the display callback for the window is called.

39 GLUT determines when the display callback should be triggered based on the window's redisplay state. The redisplay state for a window can be either set explicitly by calling glutPostRedisplay or implicitly as the result of window damage reported by the window system.

40 glutReshapeFunc

41 glutReshapeFunc sets the reshape callback for the current window.
void glutReshapeFunc(void (*func)(int width, int height)); func The new reshape callback function.

42 glutReshapeFunc sets the reshape callback for the current window; triggered when a window is reshaped. Also triggered immediately before a window's first display callback after a window is created or whenever an overlay for the window is established.

43 The width and height parameters of the callback specify the new window size in pixels. Before the callback, the current window is set to the window that has been reshaped.

44 This default callback will simply call
glViewport(0,0,width,height) on the normal plane. If an overlay is established for the window, a single reshape callback is generated. If a top-level window is reshaped, subwindows are not reshaped.

45 glutIdleFunc

46 glutIdleFunc sets the global idle callback.
void glutIdleFunc(void (*func)(void));

47 glutIdleFunc sets the global idle callback to be func so a GLUT program can perform background processing tasks or continuous animation when window system events are not being received.

48 If enabled, the idle callback is continuously called when events are not being received.
Programs with multiple windows and/or menus should explicitly set the current window and/or current menu and not rely on its current setting.

49 In general, not more than a single frame of rendering should be done in an idle callback.
Passing NULL to glutIdleFunc disables the generation of the idle callback

50 glutMainLoop

51 glutMainLoop enters the GLUT event processing loop.
void glutMainLoop(void); glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program.

52 glutSwapBuffers

53 glutSwapBuffers swaps the buffers of the current window if double buffered.
void glutSwapBuffers(void); Performs a buffer swap on the layer in use for the current window.

54 Promotes the contents of the back buffer of the layer in use of the current window to become the contents of the front buffer. The contents of the back buffer then become undefined. The update typically takes place during the vertical retrace of the monitor.

55 An implicit glFlush is done by glutSwapBuffers before it returns
An implicit   glFlush is done by glutSwapBuffers before it returns. Subsequent OpenGL commands are not executed until the buffer exchange. If the layer in use is not double buffered, glutSwapBuffers has no effect.


Download ppt "Computer Graphics Lecture 33"

Similar presentations


Ads by Google