18
OpenGL and Projections David E. Johnson

OpenGL and Projections

  • Upload
    fauna

  • View
    37

  • Download
    0

Embed Size (px)

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

Citation preview

Page 1: OpenGL and Projections

OpenGL and Projections

David E. Johnson

Page 2: OpenGL and Projections

Goals

• Quick overview of OpenGL

• Some derivation of projections and transformations

Page 3: OpenGL and Projections

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

Page 4: OpenGL and Projections

• 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!

Page 5: OpenGL and Projections

Basic Pipeline

Page 6: OpenGL and Projections

Basic Pipeline

Page 7: OpenGL and Projections

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.

Page 8: OpenGL and Projections

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

Page 9: OpenGL and Projections

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

Page 10: OpenGL and Projections

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 loopreturn 0;

}

Page 11: OpenGL and Projections

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?

Page 12: OpenGL and Projections

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

Page 13: OpenGL and Projections

Moving Camera Back

default frames

frames after translation by –d d > 0

Page 14: OpenGL and Projections

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

Page 15: OpenGL and Projections

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

Page 16: OpenGL and Projections

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

Page 17: OpenGL and Projections

gluLookAtglLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)

Page 18: OpenGL and Projections

Projections

• See notes