1 / 15

OpenGL Review

OpenGL Review. What is OpenGL?. “ OpenGL ( Open G raphics L ibrary) is a standard specification defining a cross-language cross-platform API for writing applications that produce 2D and 3D computer graphics .” – from Wikipedia State machine

haru
Télécharger la présentation

OpenGL Review

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OpenGL Review

  2. What is OpenGL? • “OpenGL (Open Graphics Library) is a standard specification defining a cross-language cross-platformAPI for writing applications that produce 2D and 3D computer graphics.” – from Wikipedia • State machine • For example, set the color, all subsequent drawing will be in this color until you change the color.

  3. Other libraries • The OpenGL Utility Library (GLU) • Routines that accomplishes some tasks by calling low-level OpenGL commands • Provided as part of OpenGL implementation • Prefix: glu • The OpenGL Utility Toolkit (GLUT) • window system-independent toolkit • Prefix: glut

  4. Reference materials • The Red book • http://www.glprogramming.com/red/ • The website • http://www.opengl.org/

  5. Setup the environment in Visual Studio • http://csf11.acs.uwosh.edu/cs371/visualstudio/

  6. Includes • #include <GL/glut.h> • Put it before stdlib.h

  7. GLUT—Window management • glutInit(int *argc, char **argv) initializes. glutInit() should be called before any other GLUT routine. • glutInitDisplayMode(unsigned int mode) specifies whether to use an RGBA or color-index color model. For example, a window with double buffering, the RGBA color model, and a depth buffer: glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH). • glutInitWindowPosition(int x, int y) specifies the screen location for the upper-left corner of your window. • glutInitWindowSize(int width, int size) specifies the size, in pixels, of your window. • int glutCreateWindow(char *string) creates a window with an OpenGL context.

  8. The display callback • glutDisplayFunc(void (*func)(void)) .Whenever GLUT determines the contents of the window need to be redisplayed, the callback function registered by glutDisplayFunc() is executed. Therefore, you should put all the routines you need to redraw the scene in the display callback function. • If your program changes the contents of the window, sometimes you will have to call glutPostRedisplay(void), which gives glutMainLoop() a nudge to call the registered display callback at its next opportunity.

  9. “Hello world” demo • glutMainLoop() is the last to be called, and it is never exited once entered. • Things that only need to be done once should be called only once in init(). • More on GLUT • http://www.glprogramming.com/red/appendixd.html

  10. User input • Mouse input • Button clicking • void glutMouseFunc(void (*func)(int button, int state, int x, int y)) • Motion • glutMotionFunc( void (*func)(int x, int y)) • Keyboard input • Key pressing • void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)) • Window resizing • void glutReshapeFunc(void (*func)(int w, int h))

  11. Quick Demo

  12. Tranformation • Rotate • void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); • Translate • void glTranslatef (GLfloat x, GLfloat y, GLfloat z); • Scale • void glScalef(GLfloat x, GLfloat y, GLfloat z);

  13. Snowman demo

  14. Homework 1 • Backface Culling • void glCullFace(GLenum mode); • glEnable(GL_CULL_FACE); • Cull faces that are facing back based on vertex normals • View frustum culling • http://www.lighthouse3d.com/opengl/viewfrustum/ • Big models (PLY)

  15. Homework 1 • User input • Backface culling • View-frustum culling

More Related