Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Similar documents
11. Quadrics in OpenGL

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

Computer graphic -- Programming with OpenGL I

Programming of Graphics

2D Drawing Primitives

Rendering. Part 1 An introduction to OpenGL

void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend();

OpenGL Primitives. Examples: Lines. Points. Polylines. void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend(); }

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

CSC 8470 Computer Graphics. What is Computer Graphics?

Simple Geometric Modeling

Introduction to Computer Graphics with OpenGL/GLUT

三維繪圖程式設計 3D Graphics Programming Design 第三章三維繪圖狀態設定和幾何元件繪製嘉大資工系盧天麒

CS 4204 Computer Graphics

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

OUTLINE. Hierarchical Models Z-Fighting Primitives Besides Triangles Back Face Culling

Computer Graphics. OpenGL

Computer Graphics. Anders Hast. måndag 25 mars 13

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Graphics Programming

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Computer Graphics. This Week. Meshes. Meshes. What is a Polygon Mesh? Meshes. Modelling Shapes with Polygon Meshes.

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

CS 465 Program 4: Modeller

The Rendering Pipeline (1)

Lecture 3 Advanced Computer Graphics (CS & SE )

CSCI 4620/8626. Coordinate Reference Frames

Data Representation in Visualisation

Assignment 1. Simple Graphics program using OpenGL

3D Graphics and OpenGl. First Steps

Lecture 4 of 41. Lab 1a: OpenGL Basics

CS 432 Interactive Computer Graphics

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Visualising Solid Shapes

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

RECITATION - 1. Ceng477 Fall

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Luiz Fernando Martha André Pereira

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Fundamentals of Computer Graphics. Lecture 3 Generate a simple shape using OpenGL. Yong-Jin Liu

4: Polygons and pixels

The radius for a regular polygon is the same as the radius of the circumscribed circle.

Introduction to OpenGL

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

Computer Graphics. Chapter 3 Computer Graphics Software

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Models and Architectures

TABLE OF CONTENTS. Worksheets Lesson 1 Worksheet Introduction to Geometry 41 Lesson 2 Worksheet Naming Plane and Solid Shapes.. 44

The figures below are all prisms. The bases of these prisms are shaded, and the height (altitude) of each prism marked by a dashed line:

Programming using OpenGL: A first Introduction

Topics and things to know about them:

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

COMPUTER GRAPHICS LAB # 3

CSCI 4620/8626. Computer Graphics Attributes of Graphics Primitives (Chapter 5)

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Computer Graphics 1 Computer Graphics 1

Polygonal Meshes: Representing 3D Objects

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

COMP 371/4 Computer Graphics Week 1

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

SFU CMPT 361 Computer Graphics Fall 2017 Assignment 2. Assignment due Thursday, October 19, 11:59pm

Due: Thursday, April 28 th by the stroke of midnight! TA: Jeff Booth

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module.

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Draw the basic Geometry Objects. Hanyang University

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

Computer Graphics (Basic OpenGL)

Advances in MicroStation 3D

PRACTICAL GEOMETRY SYMMETRY AND VISUALISING SOLID SHAPES

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Modeling. Simulating the Everyday World

Scalar Field Visualization. Some slices used by Prof. Mike Bailey

ECE 104 Fundamentals of Computer Graphics Project 1

OpenGL. Toolkits.

(1) Page #2 26 Even. (2) Page 596 #1 14. (3) Page #15 25 ; FF #26 and 28. (4) Page 603 #1 18. (5) Page #19 26

Scan Conversion of Polygons. Dr. Scott Schaefer

Drawing Primitives. OpenGL basics

Introduction to Computer Graphics with WebGL

Graphics Pipeline & APIs

CGT 581 G Geometric Modeling Surfaces (part I)

3 Polygonal Modeling. Getting Started with Maya 103

Adaptive Point Cloud Rendering

Surface and Solid Geometry. 3D Polygons

Example: The following is an example of a polyhedron. Fill the blanks with the appropriate answer. Vertices:

Lesson 9. Three-Dimensional Geometry

Real Time Rendering Assignment 1 - Report 20/08/10

Triangle meshes I. CS 4620 Lecture Kavita Bala (with previous instructor Marschner) Cornell CS4620 Fall 2015 Lecture 2

CS451Real-time Rendering Pipeline

Transcription:

Geometry Primitives Sandro Spina Computer Graphics and Simulation Group Computer Science Department University of Malta 1

The Building Blocks of Geometry The objects in our virtual worlds are composed of a number of basic primitives. With only these few building blocks, we can create highly complex realistic structures. During this module you will learn most of the things you need to know in order to draw objects in three dimensions from these building blocks. In this module we shall be using OpenGL to describe and carry out some implementations using these primitives. 2

Points... (not Pixels) We have already seen that our image will finally be rendered as a number of pixels. A pixel is the smallest element in your computer screen... And can be one of many different colours.... So if you want to draw a line, just select two pixels and fill in all the pixels falling on the line between them. In Computer Graphics however, our points are fundamentally different. We don t care (as such) about screen coordinates but rather positional coordinates in some volume. 3

A Drawing Canvas (in 3D) We need a 3D coordinate system to define out 3D canvas. On this 3D canvas we ll draw our graphics primitives. We can visualise a 3D canvas as a volume with a Cartesian coordinate space enclosed. We define boundaries on this space... Let s say -100 to +100 along the three axes x,y and z. This volume will determine the clipping volume. 4

The Vertex (3D Point) The most basic of all primitives is the point (or vertex) Remember the game (on newspapers mainly) connect the dots... The image starts to make sense only when you connect the dots (points) A set of points define the image... But not just that How they are connected plays a fundamental role In order to draw a point (using OpenGL here but this is valid with DirectX as well using different syntax) we use the glvertex3f function. 5

The OpenGL Vertex (Example) glvertex3f(20.0f, 40.0f, 0.0f); Note that we use floating point numbers to represent coordinates. 6

The Primitives... Important: A primitive is the interpretation of a set of vertices into some shape. A vertex on it s own can be a primitive but we need to specify that the point is actually a primitive. However a vertex can be part of some other primitive... The endpoint of a line The corner of a quad The corner of a triangle In OpenGL there are 10 primitives as we ll see most of the times however we ll be using the triangle primitive. 7

Drawing Primitives... We need to indicate to our graphics hardware that we want to start drawing a primitive... In OpenGL we use the function glbegin() to tell OpenGL to begin interpreting a list of vertices as a particular primitive. Once your program submits all the vertices a call to glend() will advice OpenGL that you re done... If you ve done everything right OpenGL will then be able to display that primitive on screen. 8

Drawing Points... As we said earlier a Point on it s own is also a primitive if we want to. The following code is telling OpenGL that we want to draw point primitives... glbegin(gl_points); glvertex3f(0.0f, 0.0f, 0.0f); glvertex3f(20.0f, -20.0f, 0.0f); glvertex3f(-20.0f, 20.0f, 0.0f); glvertex3f(0.0f, 0.0f, -20.0f); glend(); 9

Check First Example (Points) I am using code::blocks to carry out my implementations of OpenGL. I recommend you download it. It s fantastic. The example we ll be checking out is available on the OpenGL Super Bible 4 th Edition book. There are a number of functions which we have not covered... Don t worry too much about them for the time being. Focus on the drawing of the point primitives. Switch to Code::Blocks example points spiral 10

Properties of Points Points are draw by default as squares... We can specify the size of the points using the function glpointsize()... By defauly value is 1. Note that the point size cannot be changed between the glbegin() and glend() calls... We need to set this before. 11

The Line Primitive The next logical steps is to draw a line primitive. As opposed to a GL_POINTS primitive which simple draws a point/vertex specified, GL_LINES takes two vertices and draws a line between them. glbegin(gl_lines); glvertex3f(0.0f, 0.0f, 0.0f); glvertex3f(20.0f, 20.0f, 0.0f); glvertex3f(0.0f, 0.0f, 0.0f); glvertex3f(-20.0f, -20.0f, 0.0f); glend() 12

Check 2 nd Example (Lines) In this second example we ll be drawing lines from the origin to different parts of the circumference of a circle. Again cos(angle) gives us the x-coordinate And sin(angle) gives us the y-coordinate We keep the z-coordinate to 0... But we can easily extend this example to draw a sphere. 13

Line Strip & Line Loop Primitives Two different OpenGL primitives... In GL_LINE_STRIP a line is drawn from one vertex to the next. Similar to GL_LINE but with reuse of vertices as opposed to GL_LINE. The GL_LINE_STRIP can be composed of as many vertices as required. GL_LINE_LOOP behaves exactly like GL_LINE_STRIP but draws an additional line between the first and last vertex specified. Perfect to draw polygons. 14

Line Strip & Line Loop Primitives We can use GL_LINE_STRIP to approximate a curve. Clearly the more vertices specified (the more close to one another) the better the approximation is. Revisit example one but now using GL_LINE_STRIP instead of GL_POINTS 15

Line Stippling.. (not a primitive) Stippling is a property of the line... Essentially makes the line appear either dotted or dashed. glenable(gl_line_stipple) enables this property whereas gldisable(gl_line_stipple) disables it. In OpenGL properties are set and reset in this way. A call to gllinestipple(glint factor, Glushort pattern) establishes the pattern used to draw the lines. The pattern parameter is a 16-bit value, where each bit represents a section of the line (on or off). Factor parameter is used as a multiplier of the pattern. 16

The Triangle Primitive (i) Without any doubt the most important primitive in CG So far with the primitives we ve seen we can draw everything especially if you consider that ultimately a triangle is simply 3 lines where the third vertex is connected back to the first. The problem with lines is that you are not creating surfaces... Hence we apply colour. We can of course apply colour to the line itself but not the surface between the lines. With lines we can create wireframe cube and not a solid cube. To draw solid objects we need polygons, and triangles are the most basic of all polygons. 17

The Triangle Primitive (ii) To draw the simplest of polygons we make use of GL_TRIANGLES glbegin(gl_triangles) glvertex2f(0.0f, 0.0f); glvertex2f(20.0f, 20.0f); glvertex2f(10.0f, 10.0f); glvertex2f(-20.0f, 0.0f); glvertex2f(0.0f, 20.f); glvertex2f(-10.0f, 10.0f); glend(); 18

Winding (i) You might have noticed that there are two ways by which I can specify the same triangle. Either V0, V1, V2 or V2, V1, V0 This very important property of polygons is referred to as winding... and essentially determines which direction the top surface of the polygon is facing. Very important for back-face culling. 19

Winding (ii) The three vertices of the triangle make up its face which can be either front face or back face. In OpenGL, by default, polygons with counter-clockwise winding are considered to be front facing. In DirectX, by default, polygons with clockwise winding are considered to be front facing. Why is this important to know? Front and back might have different characteristics Back-Face Culling VERY IMPORTANT : consistency throughout 20

Triangle Strips Primitive To represent different shapes (models) we need to draw many triangles connected to each other. For example we can draw a square by connecting two triangles one to the other. We can then create a cube from 2*6faces = 12 triangles. Instead of specifying the vertices of the triangles for each triangle (in a similar fashion to LINE_STRIP) we can specify a sequence of vertices forming the triangles. GL_TRIANGLE_STRIP primitive. 21

An example... Let s say we specify five vertices which will give us four triangles. I.e. One point per triangle after the first three (very efficient!!) V0, V1, V2, V3, V4 V4 V2 V2 V3 V2 V3 V0 V1 V0 V1 V0 V1 22

Triangle Fans We can use GL_TRIANGLE_FAN in order to represent a polygon made up of a number of connected triangles all sharing a central point... Assume we have V0, V1, V2, V3, V4... V0 is the central vertex... Then we have triangles V0, V1, V2 V0, V2, V3 V0, V3, V4 Triangle fans are particularly useful to create cones... Obviously the higher the number of vertices the smoother the circular base of the cone. 23

An Example... Using Triangles We ll now be checking some OpenGL code which draws a cone... (code available on the OpenGL SuperBible Book) We ll be setting colours for the triangles faces Some of the functions we ll see in the example we ll be looking at in a few weeks time. Depth Buffers and Back-face Culling Switch to code::blocks to check the code. 24

Quad Primitives... To move from triangles to quads we simply need to add a further vertex... GL_QUADS draws a four-sided polygon which does not necessarily have to be a square Quads are used to define flat surfaces like triangles. However it is important (very) that these vertices lie on the same plane. This was not important for triangles because any three points define one plane. With quads it s different since we use four points. Finally quads have clockwise winding!!! 25

Quad Strips Behave in a similar way to lines and triangle strips... 6 vertices define two quadrilaterals... 7 vertices define? Nothing... Because for every new quad you need to define to further vertices. Therefore 8 vertices = 3 quads. Note that winding remains clockwise for GL_QUAD_STRIP 26

Finally... GL_POLYGON The most general primitive... very rarely used (if not never) is the GL_POLYGON You can use it to draw a polygon with any number of sides. Actually it is quite redundant... All vertices of the polygon must lie on the same plane. To make sure this is the case you can always use GL_TRIANGLE_FAN... In this case only the triangles will need o be in the same plane and that s guaranteed!! 27

Convex Polygons... For rendering performance reasons it is important that polygons are convex. With triangles this is not an issue (well unless you align the three points) In general a polygon is convex if it does not have any indentation... In other words if we had to draw a line over the polygon this line would not enter and leave the polygon more than once. If this line exists then the polygon is concave. 28

Subdivision... And edges We can try to transform a concave polygon into a convex one by adding some edges within the polygon. This can be done through a technique called subdivision of surfaces. Consider a polygon with the shape of a star. This is concave. However if this polygon is split up into further polygons it will become a list of convex polygons... Actually it would be great if we could come up with a set of triangles to describe the polygon. 29

Surfaces... We have so far the building blocks of geometries... Effectively what we ll be doing is building surfaces using these building blocks... Quads and Triangles already do this... We shall now be looking at a number of geometric shapes which are usually built into 3D APIs as quadratic functions. These functions allow us to draw spheres, cylinders, cones and discs. 30

Quadratric Shapes / Surfaces... We shall again be using opengl (using C) to illustrate the examples however equivalents are available in DirectX. Quadratic shapes are rendered using the quads or triangle primitive. One can create many different objects simply by connecting together spheres, cylinders (or cones) and discs. Consider drawing an arrow with one cylinder, one cone, one disc. 31

OpenGL Code Specifics Creating a Quadric GLUT Library GLUquadricObj *pobj; pobj = glunewquadric(); //set parameters... gludeletequadric(pobj) // free memory 32

Quadric Shapes... Draw Styles GLUT allows us to modify the way these quads are rendered through the function : gluquadricdrawstyle(gluquadric *obj, Glenum drawstyle); We are offered four possible ways to render the quadrics: GLU_FILL Solid objects GLU_LINE Wireframe objects GLU_POINT Point set GLU_SILHOUETTE Adjoining edges are not drawn. 33

Quadric Shapes... Properties Normals Using gluquadricnormals(gluquadricobj *obj, Glenum normals) 2 nd parameter specifies where to compute the normals. GLU_NONE, GLU_FLAT, GLU_SMOOTH. Using gluquadricorientation() we can also specify the orientation of the normals. Textures Using gluquadrictexture(gluquadricobj *obj, Glenum texturecoords) we can decide whether texture coordinates are generated on the quadric. GL_TRUE or GL_FALSE 34

Sphere... The function call glusphere(gluquadricobj *obj, Gldouble radius, Glint slices, Glint stacks) Spheres can be drawn as rings of triangles or quads. You can think of slices and stacks as the lines of longitude (vertical) and latitude (horizontal) respectively. Clearly the more slices and stacks the smoother the sphere will be... Obviously we ll be defining more points thus making the sphere more accurate. 35

Cylinder... The function call glucylinder(gluquadricobj *obj, Gldouble baseradius, Gldouble topradius, Gldouble height, Glint slices, Glint stacks) Again cylinders can be drawn as rings of triangles or quads. 1 quad = 2 triangles. You can think of slices and stacks as the lines of longitude (vertical) and latitude (horizontal) respectively. A the topradius of 0 transfors the cylinder into a cone. 36

Disk... The function call glucylinder(gluquadricobj *obj, Gldouble baseradius, Gldouble topradius, Gldouble height, Glint slices, Glint stacks) Again cylinders can be drawn as rings of triangles or quads. 1 quad = 2 triangles. You can think of slices and stacks as the lines of longitude (vertical) and latitude (horizontal) respectively. A the topradius of 0 transfors the cylinder into a cone. 37

Putting it all together... Let s have a look at a program which simply creates and puts together a number of these shapes in order to build a more complex shape. Switch to code::blocks It is very important that you realise that I m using C and OpenGL just to make sure you understand that the language we use is irrelevant... Many (if not all) computer graphics basic concepts are true irrespective of the language we use. 38

Vertex and Index Buffers So far we have not been very efficient with our declaration of vertices... Using a vertex buffer we can use memory on the GPU to store vertex information... Then using an index buffer we can describe the topology of the geometry using the vertices (unique) which are stored in the VBO. This is very similar to what we ve been doing... But instead to sending primitive information to the GPU with each draw we store that information directly on the GPU. 39

A note on terrain generation A flat terrain can easily be represented as 2 triangles... Everyone would agree. But... How do I create a terrain which is rough? Instead of representing my terrain with just 2 triangles I can represent it (still flat) as 10, 100, 1000, etc triangles. Then I can alter the y-coordinate value for each vertex in order to create a bumpy surface geometry. Clearly the higher the number of vertices the higher the granularity of my terrain. 40

Switch to DirectX using XNA Let us now take a look at a program (available through the XNA creators site) which displays primitives. So far we have defined the vertices of the torus... But that s only good if we want to just draw the point set forming the shape. We also need to specify how the points are connected (triangle set) in order to be able to render the geometry surface. Switch to XNA project Primitives3DWindows. 41