CS0045 Module 2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/63

encourage image

There's no tags or description

Looks like no tags are added yet.

64 Terms

1
New cards

The fundamental entities that we work in our graphics system

Primitives

2
New cards

• Points

• Line Segments

• Polygons

Primitives

3
New cards

Each primitive has properties called __ that determines how it is displayed by OpenGL

attributes

4
New cards

A primitive in OpenGL is defined by its __

vertices

5
New cards

A __ is simply a point in 3D, given by its x, y, and z coordinates

vertex

6
New cards
<p>• GL_POINTS</p><p>• GL_LINES</p><p>• GL_LINE_STRIP</p><p>• GL_LINE_LOOP</p><p>• GL_POLYGON</p><p>• GL_TRIANGLES</p><p>• GL_TRIANGLE_STRIP</p><p>• GL_TRIANGLE_FAN</p><p>• GL_QUADS</p><p>• GL_QUAD_STRIP</p>

• GL_POINTS

• GL_LINES

• GL_LINE_STRIP

• GL_LINE_LOOP

• GL_POLYGON

• GL_TRIANGLES

• GL_TRIANGLE_STRIP

• GL_TRIANGLE_FAN

• GL_QUADS

• GL_QUAD_STRIP

OpenGL Primitives

7
New cards
<pre><code class="language-cpp">glVertex3fv( v )</code></pre><p></p>
glVertex3fv( v )


OpenGL Command Format

8
New cards

glVertex3fv( v )

Number of components

2 - (x,y)

3 - (x,y,z)

4 - (x,y,z,w)

9
New cards

glVertex3fv( v )

Data Type

b - byte

ub - unsigned byte

s - short

us - unsigned short

i - int

ui - unsigned int

f - float

d - double

10
New cards

glVertex3fv( v )

omit “v” for scalar form

glVertex2f( x, y )

11
New cards

Points

• GL_POINTS

12
New cards

Use this primitive type to render mathematical points. OpenGL renders a point for each vertex specified.

GL_POINTS

13
New cards
<pre><code class="language-cpp">glPointSize(2.0);
glBegin(GL_POINTS);
    glColor3f(1.0, 1.0, 1.0);
    glVertex2f(-0.5, -0.5);
    glColor3f(1.0, 0.0, 1.0);
    glVertex2f(-0.5, 0.5);
    glColor3f(0.0, 0.0, 1.0);
    glVertex2f(0.5, 0.5);
    glColor3f(0.0, 1.0, 0.0);
    glVertex2f(0.5, -0.5);
glEnd();</code></pre><p></p>
glPointSize(2.0);
glBegin(GL_POINTS);
    glColor3f(1.0, 1.0, 1.0);
    glVertex2f(-0.5, -0.5);
    glColor3f(1.0, 0.0, 1.0);
    glVertex2f(-0.5, 0.5);
    glColor3f(0.0, 0.0, 1.0);
    glVertex2f(0.5, 0.5);
    glColor3f(0.0, 1.0, 0.0);
    glVertex2f(0.5, -0.5);
glEnd();


GL_POINTS

14
New cards

Lines

• GL_LINES

• GL_LINE_STRIP

• GL_LINE_LOOP

15
New cards

Use this primitive to draw unconnected line segments

GL_LINES

16
New cards

OpenGL draws a line segment for each group of two vertices. If the application specifies n vertices, OpenGL renders n/2 line segments. If n is odd, OpenGL ignores the final vertex

GL_LINES

17
New cards
<pre><code class="language-cpp">glBegin(GL_LINES);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
glEnd();</code></pre><p></p>
glBegin(GL_LINES);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
glEnd();


GL_LINES

18
New cards

Use this primitive to draw a sequence of connected line segments

GL_LINE_STRIP

19
New cards

OpenGL renders a line segment between the first and second vertices, between the second and third, between the third and fourth, and so on

GL_LINE_STRIP

20
New cards
<pre><code class="language-cpp">glBegin(GL_LINE_STRIP);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
glEnd();</code></pre><p></p>
glBegin(GL_LINE_STRIP);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
glEnd();


GL_LINE_STRIP

21
New cards

Use this primitive to close a line strip

GL_LINE_LOOP

22
New cards

OpenGL renders this primitive like a GL_LINE_STRIP with the addition of a closing line segment between the final and first vertices

GL_LINE_LOOP

23
New cards
<pre><code class="language-cpp">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();</code></pre><p></p>
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();


GL_LINE_LOOP

24
New cards

void glLineWidth(GLfloat width);


Sets the fixed width of lines. The default value is 1.0. width is the new value of line width and must be greater than 0.0, otherwise an error is generated.

25
New cards

A technique used to break a solid line into a repeating pattern of dots or dashes

Line Stippling

<p>Line Stippling</p>
26
New cards

It allows you to create dashed or dotted lines by masking out specific pixels during the line-drawing process, rather than drawing every single pixel on the line

Line Stippling

27
New cards
<p>Parameter __ is used to reference a 16-bit integer that describes how the line should be displayed</p>

Parameter __ is used to reference a 16-bit integer that describes how the line should be displayed

pattern

28
New cards
<p>Integer parameter __ specifies how many times each bit in the pattern is to be repeated before the next bit in the pattern is applied</p>

Integer parameter __ specifies how many times each bit in the pattern is to be repeated before the next bit in the pattern is applied

repeatFactor

29
New cards
<p>The hexadecimal code__ converts into a 16-bit binary sequence containing eight zeros and eight ones</p>

The hexadecimal code__ converts into a 16-bit binary sequence containing eight zeros and eight ones

0x00FF

30
New cards
<p>This specific sequence creates a repeating pattern where a solid eight-pixel segment is followed by an eight-pixel gap</p>

This specific sequence creates a repeating pattern where a solid eight-pixel segment is followed by an eight-pixel gap

0x00FF

31
New cards
<p>This image illustrates how combining different stipple patterns and integer factors alters the final visual appearance of a line</p>

This image illustrates how combining different stipple patterns and integer factors alters the final visual appearance of a line

Line Stippling

32
New cards
<p>The "__" column specifies the binary layout of dashes and gaps using hexadecimal values, such as the tightly alternating bits of 0xAAAA</p>

The "__" column specifies the binary layout of dashes and gaps using hexadecimal values, such as the tightly alternating bits of 0xAAAA

PATTERN

33
New cards
<p>The "__" column defines a multiplier that scales and stretches the length of each individual dot or dash</p>

The "__" column defines a multiplier that scales and stretches the length of each individual dot or dash

FACTOR

34
New cards
<p>As demonstrated across the examples, increasing this __ elongates the rendered line segments without changing the underlying hexadecimal code itself</p>

As demonstrated across the examples, increasing this __ elongates the rendered line segments without changing the underlying hexadecimal code itself

factor

35
New cards

Before a line can be displayed in the current line-style pattern, we must activate the line-style feature of OpenGL. We accomplish this with the following function:

glEnable(GL_LINE_STIPPLE);

glDisable(GL_LINE_STIPPLE);


36
New cards
#include <GL/glut.h>

using namespace std;

void display(){
    glClear(GL_COLOR_BUFFER_BIT);

    glEnable(GL_LINE_STIPPLE);

    glLineWidth(2.0f);

    glLineStipple(4, 0xAAAA);

    glBegin(GL_LINE_STRIP);
        glVertex2f(-0.5, -0.5);
        glVertex2f(-0.5, 0.5);
        glVertex2f(0.5, 0.5);
        glVertex2f(0.5, -0.5);
    glEnd();

    glFlush();

    glDisable(GL_LINE_STIPPLE);
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutCreateWindow("Line Strip");
    glutDisplayFunc(display);

    glutMainLoop();

return 0;
}


GL_LINE_STIPPLE

<p>GL_LINE_STIPPLE</p>
37
New cards

• GL_TRIANGLES

• GL_POLYGON

• GL_TRIANGLE_STRIP

• GL_TRIANGLE_FAN

• GL_QUADS

• GL_QUAD_STRIP

Filled Primitives

38
New cards

Use this primitive to draw individual triangles. OpenGL renders a triangle for each group of three vertices.

GL_TRIANGLES

39
New cards

If your application specifies n vertices, OpenGL renders n/3 triangles. If n isn't a multiple of 3, OpenGL ignores the excess vertices

GL_TRIANGLES

40
New cards
<pre><code class="language-cpp">void displayTriangle(){

    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
        glVertex2f(-.5f,-.5f);
        glVertex2f(.5f,-.5f);
        glVertex2f(0.0f,.5f);
    glEnd();
    glFlush();
}</code></pre><p></p>
void displayTriangle(){

    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
        glVertex2f(-.5f,-.5f);
        glVertex2f(.5f,-.5f);
        glVertex2f(0.0f,.5f);
    glEnd();
    glFlush();
}


GL_TRIANGLES

41
New cards

Use __ to draw a single filled convex n-gon primitive

GL_POLYGON

42
New cards

OpenGL renders an n-sided polygon, where n is the number of vertices specified by the application. If n is less than 3, OpenGL renders nothing

GL_POLYGON

43
New cards
<pre><code class="language-cpp">void displayPolygon(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glVertex2f(0.1,0.1);
        glVertex2f(0.6,0.1);
        glVertex2f(0.7,0.3);
        glVertex2f(0.6,0.6);
        glVertex2f(0.1,0.6);
        glVertex2f(0.0,0.3);
    glEnd();
    glFlush();
}</code></pre><p></p>
void displayPolygon(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glVertex2f(0.1,0.1);
        glVertex2f(0.6,0.1);
        glVertex2f(0.7,0.3);
        glVertex2f(0.6,0.6);
        glVertex2f(0.1,0.6);
        glVertex2f(0.0,0.3);
    glEnd();
    glFlush();
}


GL_POLYGON

44
New cards

Use this primitive to draw a sequence of triangles that share edges

GL_TRIANGLE_STRIP

45
New cards

OpenGL renders a triangle using the first, second, and third vertices, and then another using the second, third, and fourth vertices, and so on

GL_TRIANGLE_STRIP

46
New cards
<pre><code class="language-cpp">void displayTriangleStrip(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLE_STRIP);
        glVertex2f(-.5f,-.5f);
        glVertex2f(.5f,-.5f);
        glVertex2f(0.0,.5f);
        glVertex2f(.7f,.5f);
    glEnd();
    glFlush();
}</code></pre><p></p>
void displayTriangleStrip(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLE_STRIP);
        glVertex2f(-.5f,-.5f);
        glVertex2f(.5f,-.5f);
        glVertex2f(0.0,.5f);
        glVertex2f(.7f,.5f);
    glEnd();
    glFlush();
}


GL_TRIANGLE_STRIP

47
New cards

Use this primitive to draw a fan of triangles that share edges and also share a vertex. Each triangle shares the first vertex specified.

GL_TRIANGLE_FAN

48
New cards

If the application specifies a sequence of vertices v, OpenGL renders a triangle using v0, v1, and v2; another triangle using v0, v2, and v3; another triangle using v0, v3, and v4; and so on

GL_TRIANGLE_FAN

49
New cards
<pre><code class="language-cpp">void displayTriangleFan(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLE_FAN);
        glVertex2f(0.0f,-.5f);
        glVertex2f(.5f,.5f);
        glVertex2f(0.0,.5f);
        glVertex2f(-.5f,.5f);
    glEnd();
    glFlush();
}</code></pre><p></p>
void displayTriangleFan(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLE_FAN);
        glVertex2f(0.0f,-.5f);
        glVertex2f(.5f,.5f);
        glVertex2f(0.0,.5f);
        glVertex2f(-.5f,.5f);
    glEnd();
    glFlush();
}


GL_TRIANGLE_FAN

50
New cards

Use this primitive to draw individual convex quadrilaterals. OpenGL renders a quadrilateral for each group of four vertices.

GL_QUADS

51
New cards

If the application specifies n vertices, OpenGL renders n/4 quadrilaterals. If n isn't a multiple of 4, OpenGL ignores the excess vertices

GL_QUADS

52
New cards
<pre><code class="language-cpp">void displayQuads(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_QUADS);
        glVertex2f(-0.25f, 0.25f); // vertex 1
        glVertex2f(-0.5f, -0.25f); // vertex 2
        glVertex2f(0.5f, -0.25f); // vertex 3
        glVertex2f(0.25f, 0.25f); // vertex 4

        glVertex2f(.7f, 0.5f); // vertex 1
        glVertex2f(0.0f,0.5f); // vertex 2
        glVertex2f(0.0f, 0.7f); // vertex 3
        glVertex2f(0.7f, 0.7f); // vertex 4
    glEnd();
    glFlush();
}</code></pre><p></p>
void displayQuads(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_QUADS);
        glVertex2f(-0.25f, 0.25f); // vertex 1
        glVertex2f(-0.5f, -0.25f); // vertex 2
        glVertex2f(0.5f, -0.25f); // vertex 3
        glVertex2f(0.25f, 0.25f); // vertex 4

        glVertex2f(.7f, 0.5f); // vertex 1
        glVertex2f(0.0f,0.5f); // vertex 2
        glVertex2f(0.0f, 0.7f); // vertex 3
        glVertex2f(0.7f, 0.7f); // vertex 4
    glEnd();
    glFlush();
}


GL_QUADS

53
New cards

Use this primitive to draw a sequence of quadrilaterals that share edges

GL_QUAD_STRIP

54
New cards

If the application specifies a sequence of vertices v, OpenGL renders a quadrilateral using v0, v1, v3, and v2; another quadrilateral using v2, v3, v5, and v4; and so on

GL_QUAD_STRIP

55
New cards
<pre><code class="language-cpp">void displayQuadStrip(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_QUAD_STRIP);
        glVertex2f(-.5f, -.5f);  // vertex 1
        glVertex2f(.5f,-.5f);  // vertex 2
        glVertex2f(-.5f, 0.0f);  // vertex 3
        glVertex2f(.5f, 0.0f);  // vertex 4

        glVertex2f(-.7f, .80f);  // vertex 5
        glVertex2f(.7f, 0.80f);  // vertex 6
    glEnd();
    glFlush();
}</code></pre><p></p>
void displayQuadStrip(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_QUAD_STRIP);
        glVertex2f(-.5f, -.5f);  // vertex 1
        glVertex2f(.5f,-.5f);  // vertex 2
        glVertex2f(-.5f, 0.0f);  // vertex 3
        glVertex2f(.5f, 0.0f);  // vertex 4

        glVertex2f(-.7f, .80f);  // vertex 5
        glVertex2f(.7f, 0.80f);  // vertex 6
    glEnd();
    glFlush();
}


GL_QUAD_STRIP

56
New cards

RGBA

Red, Green, Blue, Alpha

57
New cards

In RGBA mode, a color is specified by three intensities (for the Red, Green, and Blue components of the color) and optionally a fourth value, __, which controls transparency

Alpha

58
New cards

The function _______ maps available red, green, and blue intensities onto (0.0, 1.0) where 0.0 means that the color component is absent ((0.0, 0.0, 0.0) is black) and 1.0 is a saturated color ((1.0, 1.0, 1.0) is white

glColor4f(red, green, blue, alpha)

59
New cards

Fourth component = __

opacity

60
New cards

(Alpha) 1.0 is __ 0.0 is __

opaque, transparent

61
New cards
<pre><code class="language-cpp">void colorSample(){
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);
    glLineWidth(2.0f);

    glBegin(GL_LINES);
        glVertex2f(-0.8, 0.0);
        glVertex2f(.8, 0.0);
        
    glEnd();
    glFlush();
}</code></pre><p></p>
void colorSample(){
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);
    glLineWidth(2.0f);

    glBegin(GL_LINES);
        glVertex2f(-0.8, 0.0);
        glVertex2f(.8, 0.0);
        
    glEnd();
    glFlush();
}


glColor3f(0.0,0.0,1.0);

62
New cards
<pre><code class="language-cpp">void colorSample2(){
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3ub(92,181,100);

    glBegin(GL_TRIANGLES);
        glVertex2f(-.5f,-.5f);
        glVertex2f(.5f,-.5f);
        glVertex2f(0.0,.5f);

    glEnd();
    glFlush();
}</code></pre><p></p>
void colorSample2(){
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3ub(92,181,100);

    glBegin(GL_TRIANGLES);
        glVertex2f(-.5f,-.5f);
        glVertex2f(.5f,-.5f);
        glVertex2f(0.0,.5f);

    glEnd();
    glFlush();
}


glColor3ub(92,181,100);

<p>glColor3ub(92,181,100);</p>
63
New cards
<pre><code class="language-cpp">void colorSample3(){
    glClear(GL_COLOR_BUFFER_BIT);
    
    glLineWidth(10.0f);

    glBegin(GL_LINES);
        glColor3ub(92,181,100);
        glVertex2f(-0.8, 0.0);
        
        glColor3f(1.0f,0.0f,0.0f);
        glVertex2f(.8, 0.0)

    glEnd();
    glFlush();
}</code></pre><p></p>
void colorSample3(){
    glClear(GL_COLOR_BUFFER_BIT);
    
    glLineWidth(10.0f);

    glBegin(GL_LINES);
        glColor3ub(92,181,100);
        glVertex2f(-0.8, 0.0);
        
        glColor3f(1.0f,0.0f,0.0f);
        glVertex2f(.8, 0.0)

    glEnd();
    glFlush();
}


glColor3ub(92,181,100);

glColor3f(1.0f,0.0f,0.0f);

64
New cards
<pre><code class="language-cpp">void colorSample4(){
    glClear(GL_COLOR_BUFFER_BIT);
    
    glBegin(GL_TRIANGLES);
        glColor3ub(92,181,100);
        glVertex2f(-.5f,-.5f);
        glColor3f(1.0f,0.0f,0.0f);
        glVertex2f(.5f,-.5f);
        glColor3f(0.0f,0.0f,1.0f);
        glVertex2f(0.0,.5f);

    glEnd();
    glFlush();
}</code></pre><p></p>
void colorSample4(){
    glClear(GL_COLOR_BUFFER_BIT);
    
    glBegin(GL_TRIANGLES);
        glColor3ub(92,181,100);
        glVertex2f(-.5f,-.5f);
        glColor3f(1.0f,0.0f,0.0f);
        glVertex2f(.5f,-.5f);
        glColor3f(0.0f,0.0f,1.0f);
        glVertex2f(0.0,.5f);

    glEnd();
    glFlush();
}


glColor3ub(92,181,100);

glColor3f(1.0f,0.0f,0.0f);

glColor3f(0.0f,0.0f,1.0f);