Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC Graphics Programming

Similar presentations


Presentation on theme: "CSC Graphics Programming"— Presentation transcript:

1 CSC 307 1.0 Graphics Programming
Budditha Hettige Department of Statistics and Computer Science

2 Graphics Programming 2D Drawing
03 Graphics Programming 2D Drawing

3 Primitive Types GL_POINTS GL_LINES GL_TRIANGLES GL_TRIANGLE_STRIP
GL_QUAD_STRIP GL_LINE_STRIP GL_LINE_LOOP GL_QUADS GL_POLYGON GL_TRIANGLE_FAN

4 Points point is represented by a set of floating-point numbers called a vertex glBegin(GL_POINTS); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(6.0, 1.5); glVertex2f(4.0, 0.0); glEnd();

5 Lines (GL_LINES) Pairs of vertices interpreted as individual line segments

6 Lines (GL_LINE_STRIP)
Series of connected line segments

7 Lines (GL_LINE_LOOP) Same as GL_LINE_STRIP, with a segment added between last and first vertices

8 Line Details Specify lines with different widths and lines
void glLineWidth(GLfloat width); Stippled Lines void glLineStipple(GLint factor, GLushort pattern); glEnable(GL_LINE_STIPPLE);

9 Example glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x0101); /* dotted */ glLineStipple(1, 0x00FF); /* dashed */ glLineStipple(1, 0x1C47); /* dash/dot/dash */ glLineStipple(1, 0x0101); glBegin(GL_LINE_LOOP); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd();

10 Triangles (GL_TRIANGLES)
Triples of vertices interpreted as triangles

11 OpenGL 2D-Drawing glBegin(GL_TRIANGLES); glEnd();
glVertex2f(-0.20f, 0.0f); glVertex2f(0.20f, 0.0f); glVertex2f(0.0f, 0.40f); glVertex2f(-0.60f,-0.20f); glVertex2f(-0.20f,-0.40f); glVertex2f(0.0f, -0.80f); glVertex2f(0.20f, -0.40f); glVertex2f(0.60f, -0.20f); glEnd();

12 Triangles (GL_TRIANGLE_STRIP)
Linked strip of triangles

13 Triangles (GL_TRIANGLE_FAN)
Linked fan of triangles

14 Quad-(GL_QUADS) Quadruples of vertices interpreted as four-sided polygons

15 Quads (GL_QUAD_STRIP)
Linked strip of quadrilaterals

16 Polygon (GL_POLYGON) Boundary of a simple, convex polygon

17 Polygon Details Points, Outlines, or Solids
void glPolygonMode(GLenum face, GLenum mode); Face GL_FRONT_AND_BACK, GL_FRONT, or GL_BACK Mode GL_POINT, GL_LINE, or GL_FILL

18 Stippling Polygons Example
filled polygons are drawn with a solid pattern void glPolygonStipple(const GLubyte *mask); Example Polygons.cpp glEnable(GL_POLYGON_STIPPLE); glPolygonStipple(fly); glRectf(125.0, 25.0, 225.0, 125.0); GLubyte fly[] = { 0x00, 0x00, 0x00, 0x00, 0x00,... };

19 OpenGL 2D-Drawing void display(void) { glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0); // red glBegin(GL_POLYGON); glVertex2f(-0.20f, 0.50f); glVertex2f(0.20f, 0.50f); glVertex2f(0.50f, 0.20f); glVertex2f(0.50f, -0.20f); glColor3f (0.0, 0.0, 1.0); // blue glVertex2f(0.20f, -0.50f); glVertex2f(-0.20f, -0.50f); glVertex2f(-0.50f, -0.20f); glVertex2f(-0.50f, 0.20f); glEnd(); glFlush (); }

20 RGB Color Space G R B Green (1,0,0) Yellow (1,1,0) White (1,1,1) Cyan
Image: Pixel maps to color Green (1,0,0) Yellow (1,1,0) White (1,1,1) Cyan (0,1,1) Red (1,0,0) R Blk Blue (0,0,1) Magenta (1,0,1) B

21 Common Composite Colors

22 Colors glColor3f(1.0, 0.0, 0.0); The current RGB color is red: full red, no green, no blue. RGB Display Modes

23 Specifying a Color and a Shading Model
RGBA mode, use the glColor*() command to select a current color. void glColor3{b s i f d ub us ui}(TYPE r, TYPE g, TYPE b); void glColor4{b s i f d ub us ui}(TYPE r, TYPE g, TYPE b, TYPE a); void glColor3{b s i f d ub us ui}v(const TYPE *v); void glColor4{b s i f d ub us ui}v(const TYPE *v);

24 Specifying a Shading Model
single color (flat shading) many different colors (smooth shading, also called Gouraud shading) void glShadeModel(GLenum mode); GL_SMOOTH (the default) or GL_FLAT. glShadeModel(GL_SMOOTH); Example: Shading.cpp


Download ppt "CSC Graphics Programming"

Similar presentations


Ads by Google