15

“OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and

Embed Size (px)

Citation preview

“OpenGL (Open Graphics Library) 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 For example, set the color, all subsequent

drawing will be in this color until you change the color.

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

The Red book http://www.glprogramming.com/red/

The website http://www.opengl.org/

http://csf11.acs.uwosh.edu/cs371/visualstudio/

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

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.

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.

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

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))

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);

Backface Culling void glCullFace(GLenum mode); glEnable(GL_CULL_FACE); Cull faces that are facing back based on

vertex normalsView frustum culling

http://www.lighthouse3d.com/opengl/viewfrustum/

Big models (PLY)

User inputBackface cullingView-frustum culling