buffers textures and more rendering paul taylor & barry la trobe university 2009
TRANSCRIPT
Buffers Textures and more Rendering
Paul Taylor & BarryLa Trobe University 2009
Clearing up the OpenGL Perspective Functions
OpenGL uses a Right Handed Coordinate SystemThis means that the Z axis is positive out of the screen
Unfortunately for our heads the OpenGl functionsglOrtho(left, right, bottom, top, near, far)AndGluPerspective(…)glFrustrum(…) All take znear and zfar in positive values as the forward distance from the COP(Center of Projection) 0,0,0
What it all means is that remembering Z is negative into the screen:To create an Orthogonal Clipping Box that goes from z = -1 (1 unit infront of you) back to z=-10 (10 units infront of you) means calling glOrtho(left, right, bottom, top, 1.0f, 10.0f)
Your OpenGL Objects
• Basically your OpenGL Objects should still have a central point of 0,0,0 in Object Coordinates
• Your Render Function should translate all Objects into the MODELVIEW Matrix using a Translation Matrix that pushes the objects backwards and into the clipping Plane
• glTranslatef(x,y,-5.0f) // Middle of a z=0-10 clipping Box
Normal
• A Normal is a Vector is a Perpendicular vector to the Surface, Pixel or Vertex it relates to
• They are extremely useful for many, many reasons in Graphics
• They are easily calculated by the Cross Product of 2 non-parallel sides of a polygon
http://mathworld.wolfram.com/NormalVector.html
Unit Vector
• A Unit vector is exactly 1 unit long!Any Vector can be tuned into a Unit vector by dividing all
components of the vector by its MagnitudeNormal V = x/|v| + y / |v| + z / |v|Where |v|2 = (x2 + y2 + z2)Unit Vectors are very useful as they are non scalar, and
results from operations will always continue to be unit length
In the Matrix world the Dot Product of 2 Unit Vectors is equal to their cosine
Single Face Rendering
www.freakyzoo.com/2Headed%20Turtle.html
Finishing off your Basic Polygons
• Clockwise Polygons• Counter-Clockwise Polygons• Polygon Normals– RHS Polygons– LHS Polygons
• Z-Positive is typically the Polygon Normal (In Object Coordinates)
So Far our Polygons have been 2-faced
Front Back
So Far our Polygons have been 2-faced
Front Back
This is the front and back view of a 1 faced Polygon
Front Back
• To make rendering more efficient we should only consider the front faces of polygons
• This reduces the rendering load very quickly when you consider a complex 3D scene
http://www-graphics.stanford.edu/courses/cs348b-competition/cs348b-05/forest/index.html
Fast Culling
http://www.soc.staffs.ac.uk/pal2/QMT/Formula/astc.gif
Remember the Dot Product of 2 Vectors is the Cosine Angle
Combining the Polygon Normal and the Viewport DirectionIf A.B < 0 Polygon is facing away
Basic Texturing
• There are 2 types of Buffer in you video card*• Color and Depth Buffers• Only Color Buffers can be drawn to your output
device• So far we have been using 3 Buffers– A Front Buffer– A Back Buffer– A Depth Buffer (Z Buffer)* According to OpenGL
Buffers and Formats
• A Buffer is an X x Y array of Values where X and Y are the resolution of the screen– In this course typically Values will be 32bit floats
• Bits Pixels and Bitplanes– Firstly in OpenGL a Bitmap is an X x Y array (or
image) with a 1 bit depth!• Bit Block Transfers (BitBlt) are covered in other subjects
so we’ll skip them
Pixel Maps
These are much more like what most would consider a ‘Bitmap’ (Windows Type)– An array X x Y of Pixels
Here is a 24bit Image / Texture declarationGlubyte stupidImage[512][512][3]To create a 32bit version we just need to extend
the depth to 4 bytes.
Using the Images / Textures in OpenGL
Texture MapsBump Maps
Normal MapsEnvironment Maps(Reflection Maps)
www.zanir.szm.sk/dx10-19.htmlwww.bencloward.com/tutorials_normal_maps12.shtml
http://www.lavaproductions.com/ChurchStone1Bump.jpg
Texture Formats
• 1D, 2D or 3D Textures can be used• Typically you will only be using 2D Textures, as
a 3D Texture can create an incredible load on the graphic Processing (And Video / Hardware Memory Use)
Texture Mapping
• In OpenGl Texture Coordinates range [0.0f->1.0f]
These are known as the Parametric Surface Coordinates and commonly reffered to as UV Coordinates
www.codersger.de/mags/cscene/CS8/CS8-02.html
Theoretically….
OpenGL Takes the XYZ Coordinates of a Vertex, then uses the related U,V coordinates of the Texture to apply it to the Object in World Coordinates. This object is then rendered to the Screen Buffer
Actually the Texture is NOT mapped onto the object up until writing the Pixel Buffer (After Perspective Transformation)
For Simple Objects
• Cubes (Squares / Rectangles)• Triangles• Cylinders• Spheres (less simple)
www-evasion.imag.fr/.../sgi_html/ch07.html
UV Mapping For Complex Objects
www.highend3d.com/.../texturing/248-2.html
The End (for now)
Mip Maps
Texturing Odd shaped Geometry
Using Intermediate Objects
Using UV Maps
Aliasing
• Aliasing is when the data representing your 3D world becomes corrupted with artifacts