surface rendering with opengl cs460 project by rui yu 11/30/03

13
Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Post on 24-Jan-2016

245 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Surface Rendering With OpenGLCS460 Project

by Rui Yu

11/30/03

Page 2: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Two aspects

• Windowing system or user interfaceUse MFC

Create a window

Viewport is the client area of the window

Capture mouse move events in the client area

Add buttons on a tools bar

• OpenGL commandsUse gl,glu fuctions

Viewing pipeline

Surface rendering

Page 3: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Viewing pipeline

ChoosePixelFormat // Define pixel formatwglCreateContext //Create rendering context.

glMatrixMode(GL_MODELVIEW);glRotatef //rotateglScalef //scale

glMatrixMode(GL_PROJECTION)glOrtho(-1,1,-1,1,-1,1); //Parellel projection

glViewport(0, 0, cx, cy);

glBegin(GL_LINES); //or GL_POLYGON and etc. glVertex3d glVertex3d glEnd;

SwapBuffers;

3D modeling coordinates

3D world coordinates

Modeling transformation

Clipping & projection

2D device coordinates

Transform into viewport

Page 4: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Example:

•Pixel Format: DOUBLE BUFFER, RGBA, DRAW_TO_WINDOW

•View volume:

Page 5: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

draw points

position of cursor is unprojectedto a 3d vertex. Here shows its

model coordinates

Screen Shots (1)-draw 3D points interactively

Page 6: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Screen Shots (2)-draw 3D bezier surface with zoom and rotation

draw thesurface

Rotate Zoomin

Zoomout

Drag of mouse definesrotation angle and

direction as shown here

This is a bezier surfacewith control points defined

on a cylinder

Page 7: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Shading

The Mathematics of Lighting:vertex color = global ambient light * ambient material +

i attenuation factor *Ii * [ ambient light *ambient material + (max { 1 x n , 0 } ) * diffuse light * diffuse material + (max {s x n ,0} )*shininess * specular light * specular material ]

l : the unit vector that points from the vertex to the light position n: the unit normal vector at the vertex.

Default Lighting Value:Global Ambient Light: {0.2, 0.2, 0.2, 1.0 };

Page 8: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Table2: Default Values for glMaterial()

Parameter Name Default Value Meaning

GL_AMBIENT (0.2, 0.2, 0.2, 1.0) ambient color of material

GL_DIFFUSE (0.8, 0.8, 0.8, 1.0) diffuse color of material

GL_SPECULAR (0.0, 0.0, 0.0, 1.0) specular color of material

GL_SHININESS 0.0 specular exponent

Table1: Default Values for glLight0()

Parameter Name Default Value Meaning

GL_AMBIENT (0.0, 0.0, 0.0, 1.0) ambient RGBA intensity of light

GL_DIFFUSE (1.0, 1.0, 1.0, 1.0) diffuse RGBA intensity of light

GL_SPECULAR (1.0, 1.0, 1.0, 1.0) specular RGBA intensity of light

GL_POSITION (0.0, 0.0, 1.0, 0.0) (x, y, z, w) position of light

Page 9: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Screen Shots (3)-Change light intensity and material property (1)

Back of surface is dark asambient light of light0 is 0. Onlyglobal ambient(0.2) works here.

Opens a dialogue tochange default values.

Page 10: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Screen Shots (4)-Change light intensity and material property (2)

After increase the ambientlight, the back of the

surface becomes brighter

Page 11: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Screen Shots (5)-Drag control points of bezier surface and texture mapping (1)

Bezier surface with 16control points initially on a

plane

old and new postion of thecontrol point

enable movecontrol points

drag a control point withmouse

show controlpoints

Page 12: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

Screen Shots (6)-Drag control points of bezier surface and texture mapping (2)

shade texturemapping

The surface drawn bymoving control points

Page 13: Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03

bibliography

• Msdnhttp://www.msdn.com

• OpenGL Programming Guide or 'The Red Book’ from Silicon Graphics, Inc

• Guide to OpenGL on Windows from Silicon Graphicshttp://www.opengl.org/developers/documentation/overviews.html

• OpenGL Win32 Tutorialhttp://www.nullterminator.net/opengl32.htmlhttp://www.opengl.org/developers/code/tutorials.html

• Basic Curves And Surfaces Modeler by Sharjith http://www.codeproject.com/useritems/cadsurf.asp