3D Graphics and OpenGl [4ex]First Steps
Transcript of 3D Graphics and OpenGl [4ex]First Steps
![Page 1: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/1.jpg)
3D Graphics and OpenGl
First Steps
![Page 2: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/2.jpg)
Rendering of 3D GraphicsObjects defined in (virtual/mathematical) 3D space.
We see surfaces of objects ⇒ define surfaces.
Triangles will be the fundamental element.
![Page 3: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/3.jpg)
Rendering of 3D GraphicsObjects defined in (virtual/mathematical) 3D space.
We see surfaces of objects ⇒ define surfaces.
Triangles will be the fundamental element.
![Page 4: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/4.jpg)
Rendering of 3D GraphicsObjects defined in (virtual/mathematical) 3D space.
We see surfaces of objects ⇒ define surfaces.
Triangles will be the fundamental element.
![Page 5: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/5.jpg)
Rendering of 3D GraphicsObjects defined in (virtual/mathematical) 3D space.
We see surfaces of objects ⇒ define surfaces.
Triangles will be the fundamental element.
![Page 6: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/6.jpg)
Rendering of 3D GraphicsMain objective: transfer (models built of) triangles from 3D space to 2Dscreen space. Add colors to the screen pixels covered by triangle(shading).
Coordinate systems:
![Page 7: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/7.jpg)
Rendering of 3D GraphicsMain objective: transfer (models built of) triangles from 3D space to 2Dscreen space. Add colors to the screen pixels covered by triangle(shading).
Coordinate systems:
![Page 8: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/8.jpg)
Rendering of 3D GraphicsMain objective: transfer (models built of) triangles from 3D space to 2Dscreen space. Add colors to the screen pixels covered by triangle(shading).
Coordinate systems:
![Page 9: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/9.jpg)
Vertices
Core data: vertices of triangles.
glBegin(GL_TRIANGLES);
glVertex3f(20.0, 20.0, 0.0);
glVertex3f(80.0, 20.0, 0.0);
glVertex3f(80.0, 80.0, 0.0);
.
.
glEnd();
![Page 10: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/10.jpg)
Other OpenGL Primitives
![Page 11: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/11.jpg)
OpenGL Primitives
Polygons and quads are divided into triangles by OpenGL beforerendering. Must be plane and convex
For efficiency, use array lists (single rendering call accessing array ofmany points) and display lists (precompiled and stored groups of OpenGLcommands, including declarations of geometry/primitives). See sections3.1 and 3.2.
![Page 12: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/12.jpg)
OpenGL Primitives
Polygons and quads are divided into triangles by OpenGL beforerendering. Must be plane and convex
For efficiency, use array lists (single rendering call accessing array ofmany points) and display lists (precompiled and stored groups of OpenGLcommands, including declarations of geometry/primitives). See sections3.1 and 3.2.
![Page 13: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/13.jpg)
OpenGL Primitives
Polygons and quads are divided into triangles by OpenGL beforerendering. Must be plane and convex
For efficiency, use array lists (single rendering call accessing array ofmany points) and display lists (precompiled and stored groups of OpenGLcommands, including declarations of geometry/primitives). See sections3.1 and 3.2.
![Page 14: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/14.jpg)
Geometry
Core data: triangles
Triangle vertices and associated data:
I Position
I Color
I Normal vector
I Texture coordinate
Vertex data are interpolated across triangle at rendering time (details ofinterpolation and other parts of rendering later).
![Page 15: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/15.jpg)
Geometry
Core data: triangles
Triangle vertices and associated data:
I Position
I Color
I Normal vector
I Texture coordinate
Vertex data are interpolated across triangle at rendering time (details ofinterpolation and other parts of rendering later).
![Page 16: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/16.jpg)
Geometry
Core data: triangles
Triangle vertices and associated data:
I Position
I Color
I Normal vector
I Texture coordinate
Vertex data are interpolated across triangle at rendering time (details ofinterpolation and other parts of rendering later).
![Page 17: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/17.jpg)
Geometry
Core data: triangles
Triangle vertices and associated data:
I Position
I Color
I Normal vector
I Texture coordinate
Vertex data are interpolated across triangle at rendering time (details ofinterpolation and other parts of rendering later).
![Page 18: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/18.jpg)
OpenGL has a state
State machine: Long list of set variables affecting rendering. Value fixedafter initialization until changed. (Alternative would be to give long listof parameters for all rendering calls).
E.g., setting (foreground/vertex) color using glColor:
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(20.0, 20.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(80.0, 20.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(80.0, 80.0, 0.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(20.0, 80.0, 0.0);
glEnd()
![Page 19: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/19.jpg)
OpenGL has a state
State machine: Long list of set variables affecting rendering. Value fixedafter initialization until changed. (Alternative would be to give long listof parameters for all rendering calls).
E.g., setting (foreground/vertex) color using glColor:
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(20.0, 20.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(80.0, 20.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(80.0, 80.0, 0.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(20.0, 80.0, 0.0);
glEnd()
![Page 20: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/20.jpg)
Projections
Transfer (models built of triangles built of vertex) points from 3D spaceto 2D screen space.
Two types:
I Orthographic
I Perspective
![Page 21: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/21.jpg)
Projections
Transfer (models built of triangles built of vertex) points from 3D spaceto 2D screen space.
Two types:
I Orthographic
I Perspective
![Page 22: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/22.jpg)
Orthographic Projection
![Page 23: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/23.jpg)
Orthographic Projection
![Page 24: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/24.jpg)
Perspective Projection
![Page 25: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/25.jpg)
Perspective Projection
![Page 26: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/26.jpg)
Perspective
Helix curve:
Orthographic:
Projective:
![Page 27: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/27.jpg)
Perspective
Helix curve:
Orthographic:
Projective:
![Page 28: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/28.jpg)
Clipping before Projection
The geometry is clipped against the viewing area planes beforeprojection. Further clipping planes can be specified manually.
![Page 29: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/29.jpg)
Clipping before Projection
The geometry is clipped against the viewing area planes beforeprojection. Further clipping planes can be specified manually.
![Page 30: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/30.jpg)
Stretch after Projection
The projected image is stretched to the screen/window size afterprojection.
![Page 31: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/31.jpg)
OpenGL Buffers
A buffer is a screensize 2D array of (pixel) data. Several buffers areavailable in OpenGL (collectively called the framebuffer).
Two important buffer types:
I Color buffers. Hold the color values to be shown on screen.
I Depth buffer. Resolves hidden surface removal.
![Page 32: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/32.jpg)
OpenGL Buffers
A buffer is a screensize 2D array of (pixel) data. Several buffers areavailable in OpenGL (collectively called the framebuffer).
Two important buffer types:
I Color buffers. Hold the color values to be shown on screen.
I Depth buffer. Resolves hidden surface removal.
![Page 33: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/33.jpg)
OpenGL Buffers
A buffer is a screensize 2D array of (pixel) data. Several buffers areavailable in OpenGL (collectively called the framebuffer).
Two important buffer types:
I Color buffers. Hold the color values to be shown on screen.
I Depth buffer. Resolves hidden surface removal.
![Page 34: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/34.jpg)
(Free)GLUTI Library that abstracts away OS-specific interface/libraries between
OpenGL and OS (incl. creation of framebuffer and double bufferingswaps).
I Handles keyboard/mouse input, windowing management.
I Event loop.
I OpenGL programmer associates callback functions with events.
I Animation through timed callbacks (glutTimerFunc()) or idle timecallback (glutIdleFunc()).
I Commands for triangles for basic models (cube, cone, sphere, torus,teapot,. . . ).
GLU is a lower level utility library (may also appear as commandname prefix).
![Page 35: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/35.jpg)
(Free)GLUTI Library that abstracts away OS-specific interface/libraries between
OpenGL and OS (incl. creation of framebuffer and double bufferingswaps).
I Handles keyboard/mouse input, windowing management.
I Event loop.
I OpenGL programmer associates callback functions with events.
I Animation through timed callbacks (glutTimerFunc()) or idle timecallback (glutIdleFunc()).
I Commands for triangles for basic models (cube, cone, sphere, torus,teapot,. . . ).
GLU is a lower level utility library (may also appear as commandname prefix).
![Page 36: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/36.jpg)
(Free)GLUTI Library that abstracts away OS-specific interface/libraries between
OpenGL and OS (incl. creation of framebuffer and double bufferingswaps).
I Handles keyboard/mouse input, windowing management.
I Event loop.
I OpenGL programmer associates callback functions with events.
I Animation through timed callbacks (glutTimerFunc()) or idle timecallback (glutIdleFunc()).
I Commands for triangles for basic models (cube, cone, sphere, torus,teapot,. . . ).
GLU is a lower level utility library (may also appear as commandname prefix).
![Page 37: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/37.jpg)
(Free)GLUTI Library that abstracts away OS-specific interface/libraries between
OpenGL and OS (incl. creation of framebuffer and double bufferingswaps).
I Handles keyboard/mouse input, windowing management.
I Event loop.
I OpenGL programmer associates callback functions with events.
I Animation through timed callbacks (glutTimerFunc()) or idle timecallback (glutIdleFunc()).
I Commands for triangles for basic models (cube, cone, sphere, torus,teapot,. . . ).
GLU is a lower level utility library (may also appear as commandname prefix).
![Page 38: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/38.jpg)
(Free)GLUTI Library that abstracts away OS-specific interface/libraries between
OpenGL and OS (incl. creation of framebuffer and double bufferingswaps).
I Handles keyboard/mouse input, windowing management.
I Event loop.
I OpenGL programmer associates callback functions with events.
I Animation through timed callbacks (glutTimerFunc()) or idle timecallback (glutIdleFunc()).
I Commands for triangles for basic models (cube, cone, sphere, torus,teapot,. . . ).
GLU is a lower level utility library (may also appear as commandname prefix).
![Page 39: 3D Graphics and OpenGl [4ex]First Steps](https://reader030.fdocuments.net/reader030/viewer/2022012505/6180fa1fe5e45e2b706ba46a/html5/thumbnails/39.jpg)
(Free)GLUTI Library that abstracts away OS-specific interface/libraries between
OpenGL and OS (incl. creation of framebuffer and double bufferingswaps).
I Handles keyboard/mouse input, windowing management.
I Event loop.
I OpenGL programmer associates callback functions with events.
I Animation through timed callbacks (glutTimerFunc()) or idle timecallback (glutIdleFunc()).
I Commands for triangles for basic models (cube, cone, sphere, torus,teapot,. . . ).
GLU is a lower level utility library (may also appear as commandname prefix).