OpenGL: Presentation.

Uploaded on:
Category: General / Misc
OpenGL: Presentation Enlivened by slides from Mitch Repel and from David Luebke 3D Demonstrating, Design, and Liveliness Prof. Jarek Rossignac School of Registering Georgia Establishment of Innovation Diagram Verifiable viewpoint on equipment, guidelines, markets Assets: Sites and books
Slide 1

OpenGL: Introduction Inspired by slides from Mitch Parry and from David Luebke 3D Modeling, Graphics, and Animation Prof. Jarek Rossignac College of Computing Georgia Institute of Technology Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 2

Outline Historical point of view on equipment, benchmarks, markets Resources: Web locales and books API, library, and equipment: Map geometry to pixels and hues Pipeline: Transform, Clip, Project, Rasterize Geometric primitives: vertices, polygons, 3D shapes, chambers... Traits: shading, material, drawing mode Viewing: camera position, lens, item position Control and stream Programming traditions: glu-& gl-calls, sorts, - .h documents Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 3

History of the 3D design industry 1960s: Line drawings, concealed lines, parametric surfaces (B-splines…) Automated drafting & machining for auto, plane, and boats makers 1970’s: Mainframes, Vector tubes (HP…) Software: Solids, (CSG), Ray Tracing, Z-cradle for shrouded lines 1980s: Graphics workstations ($50K-$1M): Frame cushions, rasterizers , GL, Phigs VR: CAVEs and head-mounted showcases CAD/CAM & GIS: CATIA, SDRC, PTC Sun, HP, IBM, SGI , E&S, DEC 1990s: PCs ($2K): Graphics loads up, OpenGL, Java3D CAD+ Videogames +Animations: AutoCAD, SolidWorks…, Alias-Wavefront Intel, numerous load up merchants 2000s: Laptops, PDAs, Cell Phones: Parallel realistic chips Everything will be illustrations, 3D, enlivened, intuitive Nvidia, Sony, Nokia Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 4

Resources for OpenGL Primer by E. Holy messenger OpenGL user’s guide and programming manual Lots of online documentation and illustrations Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 5

OpenGL Open Standard (controlled by multi-organization board) Used as normal API for versatile applications Maps geometry to libraries that adventure design equipment Function: Take 3D geometry, characteristics, client activities Produce pictures/activitys OpenGL Pipeline: States (hues, rendering modes, view parameters, nearby casing) Geometry (vertices, network) streams in and gets: Transformed and cut to the survey frustum Colored and textured Projected and painted on the window\'s pixels (casing support) Hidden parts evacuated by equipment (z-cushion stores profundity to obvious surface) Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 6

Utilities and programming traditions OpenGL GLUT Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 7

GLUT segments Main() //Init window Init() //set state vars Display() //draw model Reshape() //conform w/h Mouse() //mouse occasions Keyboard() //console occasions Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 8

GLUT: Main int Main(int argc, char** argv) glutInit(); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (Vx_max-Vx_min, Vy_max-Vy_min); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 9

GLUT: Init void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(…); } Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 10

GLUT: Display void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glBegin(GL_LINES); glVertex2d(100.0, 100.0); glVertex2d(400.0, 100.0); … glEnd(); glFlush (); } Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 11

GLUT: Reshape void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D(Vx_min, Vx_max, Vy_min, Vy_max); glMatrixMode (GL_MODELVIEW); } Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 12

GLUT: Mouse void mouse(int catch, int state, int x, int y) { switch (catch) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { printf("left mouse click\n"); } break; default: break; } } Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 13

GLUT: Keyboard void keyboard(unsigned burn key, int x, int y) { switch (key) { case ‘r’: glutPostRedisplay(); break; case 27:/* Escape key */ exit(0); break; default: break; } } Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 14

OpenGL: Conventions Functions in OpenGL begin with gl Functions beginning with glu are utility capacities (i.e., gluLookAt () ) Functions beginning with glx are for interfacing with the X Windows framework Function names show contention sort/# Functions finishing with f bring Floats Functions finishing with i take Ints, capacities that end with v take a cluster, with b take byte, and so on. Ex: glColor3f() takes 3 drifts, yet glColor4fv() takes a variety of 4 buoys Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 15

OpenGL: Specifying Geometry in OpenGL comprises of a rundown of vertices in the middle of calls to glBegin() and glEnd() A basic sample: advising GL to render a triangle glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glEnd(); Usage: glBegin( geomtype ) where geomtype is: Points, lines, polygons, triangles, quadrilaterals, and so forth... Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 16

OpenGL: More Examples Example: GL underpins quadrilaterals: glBegin(GL_QUADS); glVertex3f(- 1, 1, 0); glVertex3f(- 1, - 1, 0); glVertex3f(1, - 1, 0); glVertex3f(1, 1, 0); glEnd(); This kind of operation is called prompt mode rendering ; every charge happens quickly Although you may not see the outcome in the event that you utilize twofold buffering Things get stepped into the back cushion Then supports are swapped Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 17

OpenGL: Front/Back Rendering Each polygon has two sides, front and back OpenGL can render the two distinctively The requesting of vertices in the rundown figures out which is the front side: When taking a gander at the front side, the vertices go counterclockwise This is fundamentally the right-hand tenet Note that this still holds after viewpoint projection Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 18

OpenGL: Drawing Triangles You can draw various triangles in the middle of glBegin(GL_TRIANGLES) and glEnd() : glide v1[3], v2[3], v3[3], v4[3]; ... glBegin(GL_TRIANGLES); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v4); glEnd(); The same vertex is utilized (changed, hued) numerous time (6 by and large) Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 19

v 2 v 4 v 0 v 5 v 1 v 3 OpenGL: Triangle Strips An OpenGL triangle strip primitive diminishes this excess by sharing vertices: glBegin(GL_TRIANGLE_STRIP); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v4); glVertex3fv(v5); glEnd(); triangle 0 is v0, v1, v2 triangle 1 is v2, v1, v3 ( why not v1, v2, v3? ) triangle 2 is v2, v3, v4 triangle 3 is v4, v3, v5 (once more, not v3, v4, v5) Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 20

v 4 v 3 v 5 v 0 v 2 v 6 v 1 OpenGL: Triangle Fan The GL_TRIANGLE_FAN primitive is another approach to decrease vertex repetition: Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 21

OpenGL: Drawing Other Primitives You can draw different primitives utilizing: GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_QUADS … Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 22

OpenGL: Specifying Color Can determine different properties, for example, shading To create a solitary water hued triangle: glColor3f(0.1, 0.5, 1.0); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v2); To deliver an easily Gouraud-shaded triangle: glColor3f(1, 0, 0); glVertex3fv(v0); glColor3f(0, 1, 0); glVertex3fv(v1); glColor3f(0, 0, 1); glVertex3fv(v2); In OpenGL, hues can likewise have a fourth part  (straightforwardness) Generally need  = 1.0 (hazy); Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 23

OpenGL: Modeling Transforms Some OpenGL orders produce change networks: glTranslatef(Tx, Ty, Tz); glRotatef(angleDegrees, Ax, Ay, Az); glScalef(Sx, Sy, Sz); Example of pivots around x, y, and z tomahawks glRotatef(xangle,1,0,0); glRotatef(yangle,0,1,0); glRotatef(zangle,0,0,1); Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 24

OpenGL: Modeling Transforms Example: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(…); glRotatef(…); Result: the modelview lattice is set to: I • T • R == T • R which then is utilized to change all ensuing vertices Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 25

OpenGL: Viewing Transforms Ex: gluLookAt() figures a lookat grid : gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); Use it in the wake of stacking the character. Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 26

OpenGL: Projection The projection network is by and large utilized for the point of view projection grid gluOrtho2D() makes a lattice for anticipating 2D organizes onto the screen without viewpoint, gluOrtho2D(double left, twofold right, twofold base, twofold top); Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 27

Selecting a Polygon w/Mouse Use gluUnProject() to discover world directions for mouse click on close and far section planes (p close and p far ). Cross each triangle in the scene with the line that goes through p close and p far . Jarek Rossignac, CoC, GT, ©Copyright 2003

Slide 28

Example 1 (Brooks van Horn) #include <glut.h> #include <

View more...