Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009
Clearing up the OpenGL Perspective Functions OpenGL uses a Right Handed Coordinate System This means that the Z axis is positive out of the screen Unfortunately for our heads the OpenGl functions glOrtho(left, right, bottom, top, near, far) And GluPerspective(…) 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
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 Magnitude Normal V = x/|v| + y / |v| + z / |v| Where |v| 2 = (x 2 + y 2 + z 2 ) 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
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 FrontBack
So Far our Polygons have been 2-faced FrontBack
This is the front and back view of a 1 faced Polygon FrontBack
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
Fast Culling Remember the Dot Product of 2 Vectors is the Cosine Angle Combining the Polygon Normal and the Viewport Direction If 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 declaration Glubyte 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 Maps Bump Maps Normal Maps Environment Maps (Reflection Maps) ctions.com/ChurchSto ne1Bump.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
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
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