Download
basic program with opengl and glut n.
Skip this Video
Loading SlideShow in 5 Seconds..
Basic Program with OpenGL and GLUT PowerPoint Presentation
Download Presentation
Basic Program with OpenGL and GLUT

Basic Program with OpenGL and GLUT

209 Views Download Presentation
Download Presentation

Basic Program with OpenGL and GLUT

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Basic Program with OpenGL and GLUT

  2. Outline • Development Environment • What is GLUT? • Set up a GLUT Project • OverviewofGLUTPrograms • A Basic Program Example • Some GLUTFunctions • API Documentation

  3. Development Environment IDE OS Library GLUT (includes OpenGL andGLU) Windows 10 Windows 8 Windows 7 Visual Studio 2013Community version

  4. What is GLUT? (1 / 2) • OpenGL Utility Toolkit (GLUT) • Window system independent toolkit • Simple windowing API for OpenGL • Functions start with a prefix of “glut” • (e.g., glutInit, glutMainLoop)

  5. What is GLUT? (2 / 2) • What can GLUT do? • Initializing and creating window • Handling window and input events • Drawing preset 3D objects • Running the program

  6. Set up a GLUT Project (1 / 9) Project include dll lib glut.h gl.h (glut.h) glu.h (glut.h) glut32.lib glut32.dll

  7. Set up a GLUT Project (2 / 9)

  8. Set up a GLUT Project (3 / 9)

  9. Set up a GLUT Project (4 / 9)

  10. Set up a GLUT Project (5 / 9)

  11. Set up a GLUT Project (6 / 9)

  12. Set up a GLUT Project (7 / 9)

  13. Set up a GLUT Project (8 / 9)

  14. Set up a GLUT Project (9 / 9)

  15. Overview of GLUT Programs GLUT Point to Call Callback functions Initialization Set function pointers while(true){ if(funcBool){ funcBool = false; (*funcPtr)(…); } } Main loop

  16. A Basic Program Example (1 / 3)

  17. A Basic Program Example (2 / 3)

  18. A Basic Program Example (3 / 3)

  19. Some GLUT Functions • This section includes the following: • Initialization and window • Callback Registration • Geometric Object Rendering • Beginning Event Processing

  20. Initialization and Window (1 / 3) • voidglutInit(int *argcp, char **argv); • Initializing the GLUT library • Should be called before any GLUT functions • voidglutInitDisplayMode(unsigned intmode); • Specify a display mode for windows created • Color: GLUT_RGBA, GLUT_RGB or GLUT_INDEX • Framebuffer:GLUT_SINGLEor GLUT_DOUBLE • Buffer: GLUT_DEPTH, GLUT_STENCIL and GLUT_ACCUM

  21. Initialization and Window (2 / 3) • voidglutInitWindowSize(int width, int height); • Set the initial window size • voidglutInitWindowPosition(int x, int y); • Set the initial window position • The actual position is left to the window system to determine • intglutCreateWindow(char *name); • Create and open a window with previous settings

  22. Initialization and Window (3 / 3) • voidglutPostRedisplay(void); • Mark the current window as needing to be redisplayed • The window‘s display callback will be called • voidglutSwapBuffers(void); • Swap the buffers of the current window if double buffered • An implicit glFlushis done by glutSwapBuffers

  23. Callback Registration (1 / 5) • voidglutDisplayFunc(void (*func)(void)); • Put whatever you want to render in the callback • The callback is called when the window need to be redisplayed • Call glutPostRedisplay() to trigger the callback • voidglutReshapeFunc(void (*func)(int width, int height)); • The callback is called when a window is created, resized or moved • Always call glViewport() to resize your viewport

  24. Callback Registration (2 / 5) • voidglutKeyboardFunc(void (*func)(unsigned char key, intx, int y)); • Each key press generating a keyboard callback • key: The ASCII character generated by the pressed key • x and y: The mouse location in window relative coordinates when the key was pressed

  25. Callback Registration (3 / 5) • voidglutMouseFunc(void (*func)(int button, int state, intx, int y)); • Each press and each release mouse button in a window generates a mouse callback • button: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON • state: GLUT_UP or GLUT_DOWN • xand y: The mouse location in window relative coordinates when the mouse button state changed

  26. Callback Registration (4 / 5) • voidglutMotionFunc(void (*func)(int x, int y)); • The callback is called when the mouse moves within the window while any mouse buttons are pressed • x and y: the mouse location in window relative coordinates • voidglutPassiveMotionFunc(void(*func)(int x, int y)); • The callback is called when the mouse moves within the window while no mouse buttons are pressed • x and y: the mouse location in window relative coordinates

  27. Callback Registration (5 / 5) • voidglutIdleFunc(void (*func)(void)); • Perform background processing tasks or continuous animation when window system events are not being received • The idle callback is continuously called when events are not being received

  28. Geometric Object Rendering • Provide many objects such as sphere, cube, cone, torus • All objects have wireframe and solid versions • voidglutSolidCube(GLdouble size); • voidglutWireTeapot(GLdouble size);

  29. Beginning Event Processing • voidglutMainLoop(void); • Enter the GLUT event processing loop • Once called, this routine will never return while(true){ if(funcBool){ funcBool = false; (*funcPtr)(…); } } Callback functions Call

  30. API Documentation (1 / 2) • OpenGL 2.1 Reference Pages • OpenGL and GLU • This course use legacy OpenGL (1.0 – 2.1)

  31. API Documentation (2 / 2) • GLUT API Version 3 • For GLUT 3.x

  32. Thanks for listening! Any questions?