pipeline and opengl overview - online€¦ · • a 3d scene is: – geometry (triangles, lines,...
TRANSCRIPT
![Page 1: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/1.jpg)
Overview of the Pipeline and OpenGL
![Page 2: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/2.jpg)
Allmänt
• Labkonto• Inpasseringskort
– aktiveras automatiskt till alla som är kursregistrerade som har CTH/GU-inpasseringskort
• Labgrupper – helst 2 o 2– Skriv upp er på lista här
• Kursregistreringslista
![Page 3: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/3.jpg)
Department of Computer Engineering
Skärmen består av massa pixlar
![Page 4: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/4.jpg)
Department of Computer Engineering
3D-Rendering• Objects are often made
of triangles• x,y,z- coordinate for
each vertex
Z
X
Y
![Page 5: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/5.jpg)
Department of Computer Engineering
State-of-the-Art Real-Time Rendering
2001
![Page 6: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/6.jpg)
Department of Computer EngineeringState-of-the-Art Real-Time Rendering
2001Z
X
Y
![Page 7: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/7.jpg)
Department of Computer Engineering
+ =
One application of texturing is to ”glue”images onto geometrical object
Textures
![Page 8: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/8.jpg)
Department of Computer Engineering
Texturing: Glue images ontogeometrical objects
• Purpose: more realism, and this is a cheap way to doit
+ =
![Page 9: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/9.jpg)
Department of Computer Engineering
Ljusberäkning per triangelhörnlight
Geometry
blue
red green
Rasterizer
![Page 10: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/10.jpg)
Ray Tracing and Geometric Optics
One way to form an image is tofollow rays of light from apoint source finding whichrays enter the lens of thecamera. However, each ray of light may have multiple interactions with objectsbefore being absorbed or going to infinity.
![Page 11: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/11.jpg)
Physical Approaches• Ray tracing: follow rays of light from center of
projection until they either are absorbed by objects or go off to infinity
–Can handle global effects• Multiple reflections• Translucent objects
–Slow–Must have whole data baseavailable at all times
• Radiosity: Energy based approach–Very slow
![Page 12: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/12.jpg)
The Graphics Rendering Pipeline
![Page 13: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/13.jpg)
Rendering Primitives• Use graphics hardware for real time…• These can render points, lines, triangles.• A surface is thus an approximation by a
number of such primitives.
![Page 14: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/14.jpg)
You say that you render a ”3D scene”, but what is it?
• First, of all to take a picture, it takes a camera – a virtual one.– Decides what should end up in the final image
• A 3D scene is:– Geometry (triangles, lines, points, and more)– Light sources– Material properties of geometry– Textures (images to glue onto the geometry)
• A triangle consists of 3 vertices– A vertex is 3D position, and may
include normals and more.
![Page 15: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/15.jpg)
Lecture 1: Real-time RenderingThe Graphics Rendering Pipeline
• The pipeline is the ”engine” that createsimages from 3D scenes
• Three conceptual stages of the pipeline:– Application (executed on the CPU)– Geometry– Rasterizer
Application Geometry Rasterizer
3Dsceneinput
Image
output
![Page 16: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/16.jpg)
The APPLICATION stage
• Executed on the CPU– Means that the programmer decides what
happens here• Examples:
– Collision detection– Speed-up techniques– Animation
• Most important task: send rendering primitives (e.g. triangles) to the graphicshardware
Application Geometry Rasterizer
![Page 17: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/17.jpg)
The GEOMETRY stage
• Task: ”geometrical” operations on the input data (e.g. triangles)
• Allows:– Move objects (matrix multiplication)– Move the camera (matrix multiplication)– Compute lighting at vertices of triangle– Project onto screen (3D to 2D)– Clipping (avoid triangles outside screen)– Map to window
Application Geometry Rasterizer
![Page 18: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/18.jpg)
The RASTERIZER stage• Main task: take output from GEOMETRY
and turn into visible pixels on screen
Application Geometry Rasterizer
Also, add textures and various other per-pixeloperationsAnd visibility is resolved here: sorts the primitives in the z-direction
![Page 19: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/19.jpg)
Rewind! Let’s take a closer look
• The programmer ”sends” down primtives to be rendered through the pipeline (using API calls)
• The geometry stage does per-vertexoperations
• The rasterizer stage does per-pixeloperations
• Next, scrutinize geometry and rasterizer
Application Geometry Rasterizer
![Page 20: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/20.jpg)
GEOMETRY - SummaryApplication Geometry Rasterizer
model space world space world space
compute lighting
camera space
projectionimage space
clip map to screen
![Page 21: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/21.jpg)
Virtual Camera• Defined by position, direction vector, up
vector, field of view, near and far plane.
pointdir
nearfar
fov(angle)
Create image of geometry inside gray regionUsed by OpenGL, DirectX, ray tracing, etc.
![Page 22: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/22.jpg)
GEOMETRY - The view transform• You can move the camera in the same
manner as objects• But apply inverse transform to objects, so
that camera looks down negative z-axis
z x
Application Geometry Rasterizer
![Page 23: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/23.jpg)
GEOMETRY - SummaryApplication Geometry Rasterizer
model space world space world space
compute lighting
camera space
projectionimage space
clip map to screen
![Page 24: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/24.jpg)
GEOMETRY - Lighting• Compute ”lighting” at vertices
Application Geometry Rasterizer
light
Geometry
blue
red green
Rasterizer
Try to mimic how light in nature behaves– Hard so uses empirical models, hacks, and some real
theoryMuch more about this in later lecture
![Page 25: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/25.jpg)
Example
![Page 26: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/26.jpg)
GEOMETRY - SummaryApplication Geometry Rasterizer
model space world space world space
compute lighting
camera space
projectionimage space
clip map to screen
![Page 27: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/27.jpg)
GEOMETRY - ProjectionApplication Geometry Rasterizer
• Two major ways to do it– Orthogonal (useful in few applications)– Perspective (most often used)
• Mimics how humans perceive the world, i.e., objects’ apparent size decreases with distance
![Page 28: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/28.jpg)
GEOMETRY - Projection• Also done with a matrix multiplication!• Pinhole camera (left), analog used in CG
(right)
Application Geometry Rasterizer
![Page 29: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/29.jpg)
GEOMETRY - SummaryApplication Geometry Rasterizer
model space world space world space
compute lighting
camera space
projectionimage space
clip map to screen
![Page 30: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/30.jpg)
GEOMETRY Clipping and Screen Mapping• Square (cube) after projection• Clip primitives to square
Application Geometry Rasterizer
Screen mapping, scales and translates square so that it ends up in a rendering windowThese ”screen space coordinates” togetherwith Z (depth) are sent to the rasterizer stage
![Page 31: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/31.jpg)
GEOMETRY - SummaryApplication Geometry Rasterizer
model space world space world space
compute lighting
camera space
projectionimage space
clip map to screen
![Page 32: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/32.jpg)
The RASTERIZER in more detail
• Scan-conversion– Find out which pixels are inside the primitive
• Texturing– Put images on triangles
• Interpolation over triangle• Z-buffering
– Make sure that what is visible from the camerareally is displayed
• Double buffering• And more…
Application Geometry Rasterizer
![Page 33: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/33.jpg)
The RASTERIZER Scan conversion• Triangle vertices from GEOMETRY is input• Find pixels inside the triangle
– Or on a line, or on a point• Do per-pixel operations on these pixels:
– Interpolation– Texturing– Z-buffering– And more…
Application Geometry Rasterizer
![Page 34: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/34.jpg)
The RASTERIZER Interpolation• Interpolate colors over the triangle
– Called Gouraud interpolation
Application Geometry Rasterizer
blue
red green
![Page 35: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/35.jpg)
The RASTERIZER Texturing
• Uses and other applications– More realism– Bump mapping– Pseudo reflections– Store lighting– Almost infinitely many uses
Application Geometry Rasterizer
+ =
One application of texturing is to ”glue”images onto geometrical object
![Page 36: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/36.jpg)
The RASTERIZER Z-buffering
• The graphics hardware is pretty stupid– It ”just” draws triangles
• However, a triangle that is covered by a moreclosely located triangle should not be visible
• Assume two equally large tris at different depths
Application Geometry Rasterizer
Triangle 1 Triangle 2 Draw 1 then 2
incorrect
Draw 2 then 1
correct
![Page 37: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/37.jpg)
• Would be nice to avoid sorting…• The Z-buffer (aka depth buffer) solves this• Idea:
– Store z (depth) at each pixel– When rasterizing a triangle, compute z at each
pixel on triangle– Compare triangle’s z to Z-buffer z-value– If triangle’s z is smaller, then replace Z-buffer and
color buffer– Else do nothing
• Can render in any order
Application Geometry RasterizerThe RASTERIZER Z-buffering
![Page 38: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/38.jpg)
• The monitor displays one image at a time• Top of screen – new image
Bottom – old imageNo control of split position
• And even worse, we often clear the screenbefore generating a new image
• A better solution is ”double buffering”– (Could instead keep track of rasterpos and
vblank).
Application Geometry RasterizerThe RASTERIZER double-buffering
![Page 39: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/39.jpg)
• Use two buffers: one front and one back• The front buffer is displayed• The back buffer is rendered to• When new image has been created in back
buffer, swap front and back
Application Geometry Rasterizer
The RASTERIZER double-buffering
![Page 40: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/40.jpg)
And, lately…• Programmable shading has become a hot
topic– Vertex shaders– Pixel shaders– Adds more control and much more possibilities
for the programmer
Application Geometry Rasterizer
HARDWARE
Vertex shaderprogram
Pixel shaderprogram
![Page 41: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/41.jpg)
The Pipeline and OpenGL
![Page 42: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/42.jpg)
Practical Approach•Process objects one at a time in the order they are generated by the application
–Can consider only local lighting•Pipeline architecture
•All steps can be implemented in hardware on the graphics card
applicationprogram
display
![Page 43: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/43.jpg)
OpenGL function format
glVertex3f(x,y,z)
belongs to GL library
function name
x,y,z are floats
glVertex3fv(p)
p is a pointer to an array
dimensions
![Page 44: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/44.jpg)
Example
glBegin(GL_POLYGON)glVertex3f(0.0, 0.0, 0.0);glVertex3f(0.0, 1.0, 0.0);glVertex3f(0.0, 0.0, 1.0);glEnd( );
type of objectlocation of vertex
end of object definition
![Page 45: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/45.jpg)
A Simple Program
Generate a triangle on a solid background
![Page 46: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/46.jpg)
Simple Application...#ifdef WIN32#include <windows.h>#endif
#include <GL/glut.h> // This also includes gl.h
static void drawScene(void){
glColor3f(1,1,1);
glBegin(GL_POLYGON);glVertex3f( 4.0, 0, 4.0);glVertex3f( 4.0, 0,-4.0);glVertex3f(-4.0, 0,-4.0);
glEnd();} Usually this and next 2
slides are put in the same file main.cpp
![Page 47: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/47.jpg)
void display(void){
glClearColor(0.2, 0.2, 0.8, 1.0); // Set clear colorglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the color buffer
and the z-bufferint w = glutGet((GLenum)GLUT_WINDOW_WIDTH);int h = glutGet((GLenum)GLUT_WINDOW_HEIGHT);glViewport(0, 0, w, h); // Set viewport
glMatrixMode(GL_PROJECTION); // Set projection matrix glLoadIdentity();gluPerspective(45.0,w/h, 0.2, 10000.0); // FOV, aspect ratio, near, far
glMatrixMode(GL_MODELVIEW); // Set modelview matrix glLoadIdentity();
gluLookAt(10, 10, 10, // look from0, 0, 0, // look at0, 0, 1); // up vector
drawScene();glutSwapBuffers(); // swap front and back buffer. This frame will now been displayed.
}
Simple Application
![Page 48: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/48.jpg)
int main(int argc, char *argv[]){
glutInit(&argc, argv);
/* open window of size 512x512 with double buffering, RGB colors, and Z-buffering */glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(512,512);glutCreateWindow("Test App");
/* the display function is called once when the gluMainLoop is called,* but also each time the window has to be redrawn due to window * changes (overlap, resize, etc). */glutDisplayFunc(display); // Set the main redraw function
glutMainLoop(); /* start the program main loop */return 0;
}
Simple Application...
![Page 49: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/49.jpg)
Changing Color per Vertexstatic void drawScene(void){
// glColor3f(1,1,1); glBegin(GL_POLYGON);
glColor3f(1,0,0);glVertex3f( 4.0, 0, 4.0);
glColor3f(0,1,0);glVertex3f( 4.0, 0,-4.0);
glColor3f(0,0,1);glVertex3f(-4.0, 0,-4.0);
glEnd();}
![Page 50: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/50.jpg)
Cooler application
Starts looking good!
![Page 51: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/51.jpg)
Questions
• If we have time– Hardware history– OpenGL history
• Else See you Tuesday 8-10– The maths (transformations)
![Page 52: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/52.jpg)
Hårdvaruhistoria
![Page 53: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/53.jpg)
Datorgrafik - utvecklingÅtergivning
•Streckfigurer (tråddiagram)
•Fyllda ytor (dolda ytproblemet)
•Texturerade ytor
•Fotorealism (ljus, skugga, reflektioner)
•Animering
•Ljud
•Multimedia
•Nätbaserat
•I mobiltelefon el dyl, stereo, VR
InteraktionAlltid varit centralt. Men utrustningen blivit allt mer sofistikerad.Haptik (återkoppling - feedback - i form av virtuell känsla).http://haptic.mech.northwestern.edu/intro/gallery/
![Page 54: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/54.jpg)
Hårdvara genom tiderna
![Page 55: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/55.jpg)
Datorgrafik - textterminaler kring 1980
• S k semigrafik (motsv Text-TV) möjlig.• C64 fungerade på detta sätt (1982-91).• Numera är alla datorer “grafiska”.
![Page 56: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/56.jpg)
Direct View Storage Tube
• Created by Tektronix–Did not require constant refresh–Standard interface to computers
• Allowed for standard software• Plot3D in Fortran
–Relatively inexpensive• Opened door to use of computer
graphics for CAD community
![Page 57: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/57.jpg)
CRT
Can be used either as a line-drawing device (calligraphic) or to display contents of frame buffer (raster mode)
![Page 58: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/58.jpg)
Ulf Assarsson © 2006
Graphics Hardware HistoryGraphics Hardware History80’s:
– linear interpolation of color over a scanline– Vector graphics
91’ Super Nintendo, Neo Geo,– Rasterization of 1 single 3D rectangle per frame (FZero)
95-96’: Playstation 1, 3dfx Voodoo 1– Rasterization of whole triangles
99’ Geforce (256)– Transforms and Lighting (geometry stage)
02’ 3DLabs WildCat Viper, P10– Pixel shaders, integers,
02’ ATI Radion 9700, GeforceFX– Vertex shaders and Pixel shaders with floats
![Page 59: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/59.jpg)
Värld med– föremål– observatör (kamera)
Vad behövs?– observatörens position– Tittriktning– Uppåtriktning– Synfält (vinkel o dyl)
3D-Grafik
![Page 60: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/60.jpg)
Raster Graphics
• Image produced as an array (the raster) of picture elements (pixels) in the frame buffer
![Page 61: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/61.jpg)
Datorgrafik - hårdvaraSå här fungerar det i stort i ett system med skärm som utenhet:
• Typiskt skickar vår datorpunkter, linjeändpunkter ellertriangelhörn till GPU’n somrastrerar och fyller med färg.
• Uppdatering till skärm skerfrån bildminnet gärna minst 60 ggr/sekund.
• En modern GPU klarar (i princip) 0.1 - 1 miljardertrianglar per sekund. I praktikennågra miljoner trianglardynamiskt i realtid. Kräver ävensnabb CPU. Och oftaplattformsberoende kodning!
• Bildminnet kräverstorleksordningen 1000x1000x4 bytes = 4 MB. Ingår ofta i texturminnet på 64-512 MB.
![Page 62: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/62.jpg)
OpenGL i korthetReferens: Häftet “Introduktion till OpenGL”OpenGL är
• ett bibliotek för 3D-grafik• en tillståndsmaskin• en pipelinemaskin, som i mer eller mindre hög grad kan implementeras i hårdvara• plattformsoberoende (men språk som använder OpenGL är det inte)
Konkurrent: Microsofts multimediasystem DirectX (inkluderarDirect 3D), nu i version 9. Konkurrensen välgörande. DirectX bara förWindows, medan OpenGL för SGI, Sun Solaris, Linux, Windows,Mac, ... .
![Page 63: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/63.jpg)
HISTORY OF OPENGL
![Page 64: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/64.jpg)
SGI and GL
•Silicon Graphics (SGI) revolutionized the graphics workstation by implementing the pipeline in hardware (1982)
•To access the system, application programmers used a library called GL
•With GL, it was relatively simple to program three dimensional interactive applications
![Page 65: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/65.jpg)
OpenGL
The success of GL lead to OpenGL (1992), a platform-independent API that was –Easy to use–Close enough to the hardware to get excellent performance
–Focus on rendering–Omitted windowing and input to avoid window system dependencies
![Page 66: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/66.jpg)
OpenGL Evolution
•Controlled by an Architectural Review Board (ARB)–Members include SGI, Microsoft, Nvidia, HP, 3DLabs, IBM,…….
–Relatively stable (present version 2.0)• Evolution reflects new hardware capabilities
– 3D texture mapping and texture objects– Vertex programs
–Allows for platform specific features through extensions
![Page 67: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/67.jpg)
OpenGL Libraries
•OpenGL core library–OpenGL32 on Windows–GL on most unix/linux systems (libGL.a)
•OpenGL Utility Library (GLU)–Provides functionality in OpenGL core but avoids having to rewrite code
•Links with window system–GLX for X window systems–WGL for Windows–AGL for Macintosh
![Page 68: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/68.jpg)
GLUT
•OpenGL Utility Toolkit (GLUT)–Provides functionality common to all window systems
• Open a window• Get input from mouse and keyboard• Menus• Event-driven
–Code is portable but GLUT lacks the functionality of a good toolkit for a specific platform
• No slide bars
![Page 69: pipeline and openGL overview - online€¦ · • A 3D scene is: – Geometry (triangles, lines, points, and more) – Light sources – Material properties of geometry – Textures](https://reader036.vdocuments.mx/reader036/viewer/2022062609/6101cd4cad22d076f31801e8/html5/thumbnails/69.jpg)
Software Organization
GLUT
GLU
GL
GLX, AGLor WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motifwidget or similar