3d programming with opengl

28

Upload: morten-christensen

Post on 28-Mar-2016

258 views

Category:

Documents


3 download

DESCRIPTION

A talk on OpenGL 3D programming held on a couple of occations

TRANSCRIPT

Page 1: 3D Programming with OpenGL
Page 2: 3D Programming with OpenGL

What is OpenGL?

Applications

Main functions

Demo

Referencer

Page 3: 3D Programming with OpenGL

Simple, device independent 3D drawing and rendering API (~120 functions)

Silicon Graphics main sponsor

~1993 and still going strong

GLUT - adds device handling and utilityfunctions

Page 4: 3D Programming with OpenGL
Page 5: 3D Programming with OpenGL

Rendering(Creating, shading images from geometry, lighting, materials)

Modeling(Creating 3D Geometry)

Page 6: 3D Programming with OpenGL
Page 7: 3D Programming with OpenGL

Vertex

Page 8: 3D Programming with OpenGL

Vertex

Page 9: 3D Programming with OpenGL
Page 10: 3D Programming with OpenGL
Page 11: 3D Programming with OpenGL

Graphics CardCPU

Matrix and vector calculationsCoordinate transformationsTexture mappingDepth (z) buffer calculationsLighting and renderingPixel drawingDisplay buffer switching

Polygon definitionsDisplay list compilationsColour definitionsTexture loadingApplication logic:

loops, collision detection, user interactionmenus

Page 12: 3D Programming with OpenGL

CubeSphereTorus

Platonic solids

Page 13: 3D Programming with OpenGL

CubeSphere

Teapot

Torus

Platonic solids

Page 14: 3D Programming with OpenGL

glBegin(GL_*); *(POINTS, LINES, TRIANGLES, QUADS)

glVertex3f(0, 0, 0);glVertex3f(2, 0, 0);glVertex3f(1, 2, 0);...

glEnd();

OpenGL spells

V1 V2

V3

glVertex*();glVertex2f(a,b);glVertex3f(a,b,c);glVertex4f(a,b,c,d);

Page 15: 3D Programming with OpenGL

glColor3f(1, 0, 0); //RGBglVertex3f(0, 0, 0);glVertex3f(2, 0, 0);glVertex3f(1, 1, 0);

glColor3f (1, 0, 0);glVertex3f(0, 0, 0);

glColor3f (0, 1, 0); glVertex3f(2, 0, 0);

glColor3f (0, 0, 1); glVertex3f (1, 1, 0);

Auto Blending

Single Color

Page 16: 3D Programming with OpenGL
Page 17: 3D Programming with OpenGL

(0,0) (1,0)

(1,1)(0,1)

(0,0) (1,0)

(0,1) (1,1)

Page 18: 3D Programming with OpenGL

glTexCoord2f (0.4, 0.1);glVertex3f (0, 0, 0);

glTexCoord2f (0.5, 1.0);glVertex3f (1, 1.0, 0);

glTexCoord2f (1.0, 0.0);glVertex3f (0, 0, 2);

Page 19: 3D Programming with OpenGL

GLfloat amb[] = { 0.1, 0.1, 0.1, 1.0 };GLfloat diff[] = { 1.0, 1.0, 1.0, 1.0 };GLfloat spec[] = { 1.0, 1.0, 1.0, 1.0 };GLfloat pos[] = { 20, 20, 20, 0 };

glLightfv(GL_LIGHT0, GL_AMBIENT, amb);glLightfv(GL_LIGHT0, GL_DIFFUSE, diff);glLightfv(GL_LIGHT0, GL_SPECULAR, spec);glLightfv(GL_LIGHT0, GL_POSITION, pos);

Page 20: 3D Programming with OpenGL

glTranslatef(x, y, z);glRotatef(x, y, z);glScalef(x, y, z);glPushMatrix();glPopMatrix();

Page 21: 3D Programming with OpenGL

Using onlySimple geometrical objects

Colors

Textures

Transformations

You can build complex programsExample

Page 22: 3D Programming with OpenGL

Display lists

glNewList(LIST#, GL_COMPILE);glBegin(GL_QUADS);... add C/C++ codeglEnd();glEndList();

Vertex Arrays

Reduce number of function calls

Textures

Use of mipmaps for texturingfar away objects

Geometry

Specify clipping of distant objectsReduce polygon count for distand objects

Page 23: 3D Programming with OpenGL

OpenGL and GLUT are free

All major OS s (Windows, Linux, Mac,..)

Getting started on WindowsMS Visual C++ 2008 Express Edition (free!)

MS Platform SDK

OpenGL and GLUT installationhttp://www.hackorama.com/opengl/)

Google OpenGL tutorial

Page 24: 3D Programming with OpenGL

CVS Viewer

Solar system simulator*

Lego builder

3D Curves

H3 viewer

KnotPlot

Google Sketchup

Orbiter

Google Earth

* Selected features only :-)

Page 25: 3D Programming with OpenGL
Page 26: 3D Programming with OpenGL
Page 27: 3D Programming with OpenGL

Anonymous, OpenGl Reference Manual , Addison-Wesley

Mark Kilgard, GLUT Programming Interface

Tom McReynolds et.al., Advanced Graphics Programming usingOpenGL , Morgan Kaufmann Elsevier

Jackie Neider et.al., OpenGl Programming Guide , Addison-Wesley

Robert Withrow, OpenGL graphics Through Applications , Springer

Richard Wright et. al., OpenGl Superbible , Sams Publishing

http://www.opengl.org

http://ogle.eyebeamresearch.org/

http://nehe.gamedev.net/

Page 28: 3D Programming with OpenGL

This document was created with Win2PDF available at http://www.daneprairie.com.The unregistered version of Win2PDF is for evaluation or non-commercial use only.