OpenGL Review - PowerPoint PPT Presentation

About This Presentation
Title:

OpenGL Review

Description:

OpenGL (Open Graphics Library) is a standard specification defining a cross-language cross-platform API for writing applications that produce 2D and 3D computer ... – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 16
Provided by: Zhimi4
Learn more at: http://www.cs.unc.edu
Category:

less

Transcript and Presenter's Notes

Title: OpenGL Review


1
OpenGL Review
2
What is OpenGL?
  • 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.

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 ltGL/glut.hgt
  • Put it before stdlib.h

7
GLUTWindow 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
Write a Comment
User Comments (0)
About PowerShow.com