3D Programming with OpenGL

Post on 28-Mar-2016

233 views 3 download

Tags:

description

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

Transcript of 3D Programming with OpenGL

What is OpenGL?

Applications

Main functions

Demo

Referencer

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

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

Modeling(Creating 3D Geometry)

Vertex

Vertex

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

CubeSphereTorus

Platonic solids

CubeSphere

Teapot

Torus

Platonic solids

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

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

(0,0) (1,0)

(1,1)(0,1)

(0,0) (1,0)

(0,1) (1,1)

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

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

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

Using onlySimple geometrical objects

Colors

Textures

Transformations

You can build complex programsExample

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

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

CVS Viewer

Solar system simulator*

Lego builder

3D Curves

H3 viewer

KnotPlot

Google Sketchup

Orbiter

Google Earth

* Selected features only :-)

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/

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.