1 / 18

OpenGL and Projections

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 functions you call from your program Most functions map to GPU hardware

fauna
Télécharger la présentation

OpenGL and Projections

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 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 <GL/gl.h> • #include <GL/glu.h> • #include <GL/glut.h> • 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 <GL/gl.h> #include <GL/glut.h> 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 return 0; }

  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 default frames frames after translation by –d d > 0

  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(); glRotatef(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(); gluLookAt(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

More Related