OpenGL and Projections - PowerPoint PPT Presentation

About This Presentation
Title:

OpenGL and Projections

Description:

OpenGL and Projections David E. Johnson Goals Quick overview of OpenGL Some derivation of projections and transformations OpenGL OpenGL is nothing more than a set of ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 19
Provided by: davidj76
Learn more at: https://my.eng.utah.edu
Category:

less

Transcript and Presenter's Notes

Title: OpenGL and Projections


1
OpenGL and Projections
  • David E. Johnson

2
Goals
  • Quick overview of OpenGL
  • Some derivation of projections and transformations

3
OpenGL
  • OpenGL is nothing more than a set of functions
    you call from your program
  • Most functions map to GPU hardware
  • Hides the details of the display adapter,
    operating system, etc.
  • Has grown to become a flexible general purpose
    compute platform

4
  • As a programmer, you need to
  • Specify the location/parameters of camera.
  • Specify the geometry (and appearance).
  • Specify the lights.
  • OpenGL will compute the resulting 2D image!

5
Basic Pipeline
6
Basic Pipeline
7
OpenGL Hierarchy
  • Several levels of abstraction are provided
  • GL
  • Lowest level vertex, matrix manipulation
  • glVertex3f(point.x, point.y, point.z)
  • GLU
  • Helper functions for shapes, transformations
  • gluPerspective( fovy, aspect, near, far )
  • GLUT
  • Highest level Window and interface management
  • glutSwapBuffers()
  • All fairly raw most people have their own point
    class which gets transformed to GL arrays as
    needed.

8
OpenGL Implementations
  • OpenGL is an API
  • include ltGL/gl.hgt
  • include ltGL/glu.hgt
  • include ltGL/glut.hgt
  • Windows, Linux, UNIX, etc. all provide a platform
    specific implementation.
  • Windows opengl32.lib glu32.lib glut32.lib
  • Linux -l GL -l GLU l GLUT

9
OpenGL Conventions
  • OpenGL is largely state based
  • Calls persist
  • This instead of having functions with 100s of
    options
  • Transformations live on stacks
  • Layers of transformations possible
  • Work is done on buffers (color, depth,)
  • Many functions have multiple forms
  • glVertex2f, glVertex3i, glVertex4dv, etc.
  • Number indicates number of arguments
  • Letters indicate type
  • f float, d double, v pointer, etc.
  • Programs tend to be event based

10
A simple GLUT program
  • // A simple OpenGL and glut program
  • include ltGL/gl.hgt
  • include ltGL/glut.hgt
  • void display()
  • glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT
    )
  • glFlush()
  • int main(int argc, char argv)
  • glutInit(argc, argv)
  • glutInitWindowSize(512,512)
  • glutInitDisplayMode(GLUT_RGB GLUT_DEPTH )
  • glutCreateWindow("The glut hello world
    program")
  • glutDisplayFunc(display)
  • glClearColor(0.0, 0.0, 0.0, 1.0)
  • glutMainLoop() // Infinite event loop

11
OpenGL Camera
  • Two things to specify
  • Physical location of camera in the scene
  • Where is the camera?
  • Which direction is it pointing?
  • What is the orientation of the camera?
  • Projection properties of the camera
  • Depth of field?
  • Field of view in the x and y directions?

12
The OpenGL Camera
  • Initially the object and camera frames are the
    same
  • Default model-view matrix is an identity
  • The camera is located at origin and points in the
    negative z direction
  • OpenGL also specifies a default view volume that
    is a cube with sides of length 2 centered at the
    origin
  • Default projection matrix is an identity

13
Moving Camera Back
frames after translation by d
d gt 0
  • default frames

14
Moving the Camera
  • We can move the camera to any desired position by
    a sequence of rotations and translations
  • Example side view
  • Rotate the camera
  • Move it away from origin
  • Model-view matrix C RT

15
OpenGL code
  • Remember that last transformation specified is
    first to be applied

glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRot
atef(90.0, 0.0, 1.0, 0.0) glTranslatef(0.0, 0.0,
-d)
16
The LookAt Function
  • The GLU library contains the function gluLookAt
    to form the required modelview matrix through a
    simple interface
  • Note the need for setting an up direction
  • Still need to initialize
  • Can concatenate with modeling transformations
  • Example isometric view of cube aligned with axes

glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluL
ookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0. 0.0)
17
gluLookAt
  • glLookAt(eyex, eyey, eyez, atx, aty, atz, upx,
    upy, upz)

18
Projections
  • See notes
Write a Comment
User Comments (0)
About PowerShow.com