Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 

Similar presentations


Presentation on theme: "Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 "— Presentation transcript:

1 Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk  http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl - Circle and Ellipse drawing algorithms - Extract from Chapter 2 of OpenGL Programming Guide

2 Lecture 2: Some definitions of terms 2 Today’s Lecture and Lab  Review of Tutorial 1  Lab: any problems?  Some definitions of basic terms in OpenGL  Outline of today’s tutorial:  drawing circles and ellipses

3 Lecture 2: Some definitions of terms 3 Review of Tutorial  From last week’s tutorial you should be able to  Compile a Visual C++ OpenGL program  Change the position of a point (vertex), pp 35-36  Change the background colour, pp 30-31  Change the colour of the drawn object, pp 32  Change the way vertices are joined, pp 43-47

4 Lecture 2: Some definitions of terms 4 In the lab  If you are having problems check that your M: drive is not full  Examples will compile on machines in the 6 th and 7 th floor labs but not the 3 rd floor  If you are having M: drive problems even after deleting files check with the Computer Desk in the ARC

5 Lecture 2: Some definitions of terms 5 Defining some terms: Vertex  A vertex is the basic building block in OpenGL  It is a point in space defined by x, y, z and w  We can forget w until level 3, and z for a few weeks X Y Z

6 Lecture 2: Some definitions of terms 6 Ways of Drawing Vertices  Most function names in OpenGL begin with gl followed by the name of the operation and then the number and type of the parameters, e.g.  glVertex2s(2,3);two integers  glVertex3d(0.0, 0.0, 3.1452589); three doubles  glVertex3f(15.0, 12.0, 5.0);three floats  Gldouble dvect[3] = {5.0, 9.0, 12.6}  glVertex3dv(dvect) an array of points  We might use the latter to draw a collection of stored points

7 Lecture 2: Some definitions of terms 7 Ways of Drawing Vertices ….  As you saw in last weeks tutorial, more complex shapes are made by joining vertices together in different ways  This is controlled by the parameter passed to glBegin() see pages 44-46 of the handout  The different attributes, GL_POINTS, GL_LINES can be used to draw different shapes  However different attributes may also been used because  The data was scanned and stored as points, triangles or quads  or, some 3d algorithms, depend on the way the data is stored, e.g. lighting and collision detection

8 Lecture 2: Some definitions of terms 8 Representing Colour  One of the main colour representing models in Computer Graphics is to use Red, Green and Blue components in a pixel  By adding more or less of each component we can control the colour drawn e.g.  Red 0, Green 0, Blue 0 == Black  Red 1, Green 0, Blue 0 == Red  Red 1, Green 1, Blue 0 == Yellow  Red 0, Green 1, Blue 1 == Cyan  Red 1, Green 1, Blue 1 == White  (More examples on page 33 of handout)

9 Lecture 2: Some definitions of terms 9 Representing Colour...  In OpenGL the colour component is controlled by values between 0.0 and 1.0  To set the current drawing colour we call  glColor3f(r, g, b) where r, g and b are floating point numbers between 0.0 and 1.0 representing red, green and blue.  We can also set the background colour using  glClearColor(red, green, blue, alpha)  Alpha is used to control transparency and is zero in our examples

10 Lecture 2: Some definitions of terms 10 Graphics Context: The OpenGL State Machine  You may have observed that points and shapes are draw in a colour until you change the colour via a call to glColor*()  The colour state is retained during drawing operations  In fact, all drawing states are retained until they are changed by the appropriate function call  Drawing is done in the current Graphics Context and the same state machine approach is used by all graphics libraries: OpenGL, Windows, Macintosh, X Windows

11 Lecture 2: Some definitions of terms 11 Graphics Context: Other Attributes  Other attributes which control the current graphics context are  Primitive Drawing mode: GL_POINTS etc  Colour  Point sizeglPointSize(float)  Line WidthglLineWidth(float)  Line StyleglLineStipple(int, short) pages 53-56  Operations on the current drawing matrix which control scale, translation and rotation (level 3)  A common error in programming is to forget to change the graphics context when required

12 Lecture 2: Some definitions of terms 12 Today’s Tutorial: Circle Drawing  OpenGL does not have a primitive function for drawing circles  The handout has a fairly inefficient routine using floating point numbers and calls to cos() and sin()  The attached algorithms (from Foley and van Dam) use either integer only (Circle) or integer and some floats (Ellipse) to draw shapes more efficiently  Implement these two algorithms in OpenGL: replace CirclePoints() and EllipsePoints() by calls to glVertex*() and glColor(). Note use symmetry to draw all points.

13 Lecture 2: Some definitions of terms 13 Next Week  More drawing with  scaling, rotation and translation  Resources for your PC  the GLUT library can be found at http://www.xmission.com/~nate/glut.html See the Readme file on where to put components  Using GLUT with Borland C++ http://home.clara.net/paulyg/ogl.htm

14 Lecture 2: Some definitions of terms 14 Other resources  OpenGL tutorials http://www.opengl.org/developers/code/tutorials.html However, most assume knowledge of Windows API  GLUT sample code http://trant.sgi.com/opengl/toolkits/glut- 3.5/progs/progs.html


Download ppt "Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 "

Similar presentations


Ads by Google