State Management and Drawing Geometry Objects

Slides:



Advertisements
Similar presentations
Chapter 2: Graphics Programming
Advertisements

1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Drawing Geometric Objects
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
1 GLUT Callback functions Event-driven: Programs that use windows  Input/Output  Wait until an event happens and then execute some pre-defined functions.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Speeding Up Rendering After Deciding What to Draw.
Interactive Computer Graphics Lecture 2: The programming approach to building graphical applications using OpenGL API.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Computer Graphics Bing-Yu Chen National Taiwan University.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Intro to OpenGL: Vertices and Drawing
UniS CS297 Graphics with Java and OpenGL State Management and Drawing Primative Geometric Objects.
NoufNaief.net 1 TA: Nouf Al-Harbi.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
OpenGL Vertex Arrays OpenGL vertex arrays store vertex properties such as coordinates, normal vectors, color values and texture coordinates. These properties.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Computer Graphics I, Fall 2010 Building Models.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Introduction to Graphics Programming. Graphics API.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
Draw a Simple Object.
State Management and Drawing Geometric Objects
State Management and Drawing Geometric Objects
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Objectives OpenGL drawing primitives and attributes
Starting to draw dealing with Windows which libraries? clipping
CSE 411 Computer Graphics Lecture #3 Graphics Output Primitives
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

State Management and Drawing Geometry Objects (OpenGL Book Ch 2)

Objective Clear the window to an arbitrary color Force any pending drawing to complete Draw with any geometric primitive Turn states on and off and query state variables Control the display of those primitives Specify normal vectors Use vertex arrays Save and restore state variables

Clearing the Window glClearColor(0.0, 0.0, 0.0, 0.0); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // or run more slowly with, // glClear(GL_COLOR_BUFFER_BIT); // glClear(GL_DEPTH_BUFFER_BIT);

Specifying a Color Pseudocode glColor3f(1.0, 0.0, 0.0); set_current_color(red); draw_object(A); draw_object(B); set_current_color(green); // wasted set_current_color(blue); draw_object(C); glColor3f(1.0, 0.0, 0.0);

Forcing Completion of Drawing glFlush(); Forces previously issued OpenGL commands to begin execution. glFinish(); Forces all previously issued OpenGL command s to complete. This command doesn’t return until all effects from previous commands are fully realized.

glutReshapeFunc(reshape) Example code void reshape (int w, int h) { glViewport (0, 0, w, h); glMatixMode (GL_PROJECTION); glLoadIdentity(); glOrtho2D(0, w, 0, h); }

What are Points, Lines, and Polygon? represented by a vertex Lines refer to line segments Polygons must be simple, convex, and planar Rectangles glRectf(x1, y1, x2, y2); glRectfv(*pt1, *pt2);

Curves and Curved Surface Approximating Curves

Specifying Vertices glVertex2s(2, 3); glVertex3d(0.0, 0.0, 3.14); glVertex4f(2.4, 1.0, -2.2, 2.0); GLdouble v[3] = {1.0, 9.0, 8.0}; glVertex3dv(v);

Drawing Geometric Primitives glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(4.0, 3.0); glVertex2f(6.0, 1.5); glVertex2f(4.0, 0.0); glEnd();

OpenGL Geometric Primitives GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP GL_POLYGON

Geometric Primitive Types

Valid Commands between glBegin(), glEnd() glVertex*() glColor*(), glIndex*() glNormal*() glTexCoord*() glEdgeFlag*() glMaterial*() glArrayElement() glEvalCoord*(), glEvalPoint*() glCallList(), glCallLists() and any C or C++ codes

Basic State Management glEnable(GL_DEPTH_TEST); glDisable(GL_FOG) if (glIsEnabled(GL_FOG)) ... glGetBooleanv(); glGetIntegerv(); glGetFloatv(); glGetDoublev(GL_CURRENT_COLOR,x); glGetPointerv();

Point and Line Details glPointSize(2.0); glLineWidth(2.0); glLineStipple(1,0xAAAA); glLineStipple(2,0xAAAA); glEnable(GL_LINE_STIPPLE);

Stippled Lines

Polygon Details Drawing polygons as points, outlines, or solids glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);

Reversing and Culling Polygon Faces glFrontFace(GL_CCW); glFrontFace(GL_CW); glCullFace(GL_BACK); glCullFace(GL_FRONT); glCullFace(GL_FRONT_AND_BACK);

Stippling Polygons glEnable(GL_POLYGON_STIPPLE); // Define stipple pattern fly here... glPolygonStipple(fly);

Marking Polygon Boundary Edges glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POLYGON); glEdgeFlag(GL_TRUE); glVertex3fv(V0); glEdgeFlag(GL_FALSE); glVertex3fv(V1); glVertex3fv(V2); glEnd();

Normal Vectors Provide Unit Normals! glBegin (GL_POLYGON); glNormal3fv(n0); glVertex3fv(v0); glNormal3fv(n1); glVertex3fv(v1); glVertex3fv(v2); glEnd(); Provide Unit Normals! glEnable(GL_NORMALIZE) can be expensive

Example: Drawing a unit cube Static GLfloat vdata[8][3] = { {0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0},{0.0,1.0,0.0}, {0.0,0.0,1.0},{1.0,0.0,1.0}, {1.0,1.0,1.0},{0.0,1.0,1.0}}; //global!! Static GLint allIndx[6][4] = { {4,5,6,7},{1,2,6,5},{0,1,5,4}, {0,3,2,1},{0,4,5,4},{2,3,7,6}}; for (i=0; i<6; i++){ glBegin(GL_QUADS); glVertex3fv(&vdata[allIndx[i][0]][0]); glVertex3fv(&vdata[allIndx[i][1]][0]); glVertex3fv(&vdata[allIndx[i][2]][0]); glVertex3fv(&vdata[allIndx[i][3]][0]); glEnd(); } 7 3 2 1 5 6 4 X Y Z

Vertex Arrays To reduce the number of function calls Six sides; eight shared vertices Step 1: Enabling arrays Step 2: Specifying data for the arrays Step 3: Dereferencing and rendering

Step 1: Enabling Arrays glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_INDEX_ARRAY); glEnableClientState(GL_EDGE_FLAG_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);

Step 2: Specifying Data for the Arrays glVertexPointer(size, type, stride, pointer) glColorPointer(size, type, stride, pointer) glIndexPointer(type, stride, pointer) glNormalPointer(type, stride, pointer) glTexCoordPointer(size, type, stride, pointer) glEdgeFlagPointer(stride, pointer)

Step 2: Specifying Data for the Arrays glVertexPointer(size, type, stride, ptr) static GLfloat v[] = { 0.0,0.0,0.0, 1.0,0.0,0.0, 1.0,1.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0, 1.0,0.0,1.0, 1.0,1.0,1.0), 0.0,1.0,1.0 }; glVertexPointer(3, GL_FLOAT, 0, v);

Stride static GLfloat intertwined [ ] = { 1.0, 0.2, 1.0, 100.0, 100.0, 0.0, /* ………………………………*/ 0.2, 0.2, 1.0, 200.0, 100.0, 0.0 }; glColorPointer(3, GL_FLOAT, 6*sizeof(GLfloat), intertwined); glVertexPointer(3, GL_FLOAT, 6*sizeof(GLfloat), &intertwined[3]);

Step 3: Dereferencing and Rendering Alternative 1: dereferencing a single array element glVertexPointer(3, GL_FLOAT, 0, v); glBegin(GL_QUADS); glArrayElement(4); glArrayElement(5); glArrayElement(6); glArrayElement(7); … glEnd(); 7 3 2 1 5 6 4 X Y Z

Dereferencing a List of Array Elements glVertexPointer(3, GL_FLOAT, 0, v); Static GLint allIndx[24]={4,5,6,7, 1,2,6,5, 0,1,5,4, 0,3,2,1, 0,4,5,4, 2,3,7,6}; Alternative 2: glBegin(GL_QUADS); for(int i = 0; i < 24; i++) glArrayElement(allIndx[i]); glEnd(); Alternative 3: Better still … glDrawElements(GL_QUADS,24,GL_UNSIGNED_INT,allIndx);

Hints for Building Polygonal Models of Surfaces Keep polygon orientations consistent. all clockwise or all counterclockwise Watch out for non-triangular polygons. Trade-off between speed and quality. Avoid T- intersections There are more… Read the book.

Next … Vectors, Matrices and Homogeneous coordinate system Transformations