150 likes | 289 Vues
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
E N D
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.
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
Reference materials • The Red book • http://www.glprogramming.com/red/ • The website • http://www.opengl.org/
Setup the environment in Visual Studio • http://csf11.acs.uwosh.edu/cs371/visualstudio/
Includes • #include <GL/glut.h> • Put it before stdlib.h
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.
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.
“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
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))
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);
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)
Homework 1 • User input • Backface culling • View-frustum culling