Download

Drawing Basic Graphics Primitives






Advertisement
/ 18 []
Download Presentation
Comments
osric
From:
|  
(1117) |   (0) |   (0)
Views: 162 | Added:
Rate Presentation: 0 0
Description:
Drawing Basic Graphics Primitives. Lecture 4 Wed, Sep 3, 2003. OpenGL Functions. OpenGL function names always begin with gl, glu, or glut, depending on the library. Names of functions that allow a variable number of arguments are followed by a digit indicating the number.
Drawing Basic Graphics Primitives

An Image/Link below is provided (as is) to

Download Policy: Content on the Website is provided to you AS IS for your information and personal use only and may not be sold or licensed nor shared on other sites. SlideServe reserves the right to change this policy at anytime. While downloading, If for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.











- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -




Drawing basic graphics primitivesSlide 1

Drawing Basic Graphics Primitives

Lecture 4

Wed, Sep 3, 2003

Opengl functionsSlide 2

OpenGL Functions

  • OpenGL function names always begin with gl, glu, or glut, depending on the library.

  • Names of functions that allow a variable number of arguments are followed by a digit indicating the number.

  • Names of functions that allow various argument types are followed by a letter indicating the type.

State variablesSlide 3

State Variables

  • OpenGL maintains a large number of state variables.

  • These state variables are global – they are in effect and accessible within all functions.

  • Some states are

    • Colors used in various situations.

    • Shading effects.

    • Lighting effects.

Setting the colorSlide 4

Setting the Color

  • One of the states maintained is the current color used for drawing.

  • The color is a combination of red, green, and blue.

  • Use glColor*() to set the current color.

    • glColor3f(1.0, 0.0, 0.0) – bright red.

    • glColor3f(1.0, 1.0, 0.0) – bright yellow.

    • glColor3f(0.5, 0.5, 0.5) – medium gray.

Drawing dotsSlide 5

Drawing Dots

  • To color a single pixel, use the glVertex*() function.

    • glVertex2i(int, int).

    • glVertex3f(float, float, float), etc.

  • The pixel is colored with the current color, as set by glColor().

  • The coordinates are in “world” coordinates, not screen coordinates.

Primitive objectsSlide 6

Primitive Objects

  • The pixel-drawing function is called glVertex() because the pixel is typically a vertex in a polygon.

  • The programmer must indicate to the GPU whether the point is an isolated point or part of a line or polygon.

  • To do this, use glBegin() and glEnd() to enclose the vertices of the primitive objects.

Primitive objects1Slide 7

Primitive Objects

  • glBegin(type) defines the type of object to be drawn.

  • Some values of typeare

    • GL_POINTS

    • GL_LINES

    • GL_TRIANGLES

    • GL_POLYGON

  • glEnd() marks the end of the object.

Creating pointsSlide 8

Creating Points

  • The following program segment will draw three pixels.

glBegin(GL_POINTS);

glVertex2i(10, 20);

glVertex2i(50, 20);

glVertex2i(50, 50);

glEnd():

Creating trianglesSlide 9

Creating Triangles

  • The following program segment will draw and fill a triangle.

glBegin(GL_TRIANGLES);

glVertex2i(10, 20);

glVertex2i(50, 20);

glVertex2i(50, 50);

glEnd():

Creating triangles1Slide 10

Creating Triangles

  • The following program segment will draw, but not fill, a triangle.

glBegin(GL_LINE_LOOP);

glVertex2i(10, 20);

glVertex2i(50, 20);

glVertex2i(50, 50);

glEnd():

Drawing primitivesSlide 11

Drawing Primitives

  • For points, the size of the drawing pen is set by the function glPointSize(size).

  • For lines, the pen width is defined by the function glLineWidth(width).

  • The size and width are measured in pixels.

Example drawdotsSlide 12

Example: DrawDots

  • DrawDots.cpp

    • Why does each dot disappear when the next dot is drawn?

    • How could we modify the program so that all the dots remained?

      • Do not clear the buffer, but keep adding to it?

      • Store all the points in a list and draw each one every time?

    • What happens when the window is resized?

Making line drawingsSlide 13

Making Line Drawings

  • Drawing lines is similar to drawing points and triangles.

  • Use glBegin(GL_LINES);

  • Every pair of points drawn between glBegin() and glEnd() is rendered as a line.

  • We may list many pairs of points.

Example draw an xSlide 14

Example: Draw an X

  • The following program segment will draw two line segments that form an X.

glBegin(GL_LINES);

glVertex2i(50, 50);

glVertex2i(100, 100);

glVertex2i(50, 100);

glVertex2i(100, 50);

glEnd();

Example draw an x1Slide 15

Example: Draw an X

  • DrawX.cpp

Drawing polygonsSlide 16

Drawing Polygons

  • If we use GL_POLYGON in the glBegin() function, then the entire list of points is used to draw a single polygon.

  • What would the last example look like?

  • Why not use GL_POLYGON to draw several polygons in one group, just as with GL_LINES?

Example draw an octagonSlide 17

Example: Draw an Octagon

  • The following program segment will draw a regular octagon.

int cx = 100, cy = 100;

glBegin(GL_POLYGON);

for (int i = 0; i < 8; i++)

{

float dx = cos(i*PI/4);

float dy = sin(i*PI/4);

glVertex2i(x + 100*dx, y + 100*dy);

}

glEnd();

Example draw an octagon1Slide 18

Example: Draw an Octagon

  • DrawOctagon.cpp


Copyright © 2014 SlideServe. All rights reserved | Powered By DigitalOfficePro