0% found this document useful (0 votes)
28 views26 pages

Pipeline

The document discusses the graphics pipeline and geometric primitives in computer graphics. 1. The graphics pipeline processes geometric primitives through stages like transformation, projection, rasterization and displays the final pixels on screen. 2. Geometric primitives include points, lines and triangles defined by vertices. In modern OpenGL, primitives are stored in vertex buffer objects for rendering.

Uploaded by

jude jobori
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views26 pages

Pipeline

The document discusses the graphics pipeline and geometric primitives in computer graphics. 1. The graphics pipeline processes geometric primitives through stages like transformation, projection, rasterization and displays the final pixels on screen. 2. Geometric primitives include points, lines and triangles defined by vertices. In modern OpenGL, primitives are stored in vertex buffer objects for rendering.

Uploaded by

jude jobori
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

CS332 Computer Graphics

Lecture 3

Graphics Pipeline
Graphics Pipeline
Primitives: Points, Lines, Triangles
[Angel Ch. 2]

Abdullah Alfarrarjeh
German Jordanian University

1
Graphics Pipeline

Primitives+ Translate Is it visible 3D to 2D Convert to Shown


material Rotate on screen? pixels on the screen
properties Scale (framebuffer)

2
The Framebuffer
• Special memory on the graphics card

• Stores the current pixels to be displayed on the


monitor

• Monitor has no storage capabilities

• The framebuffer is copied to the monitor at each


refresh cycle
A framebuffer is designed with enough memory to store two frames worth of video data.
In a technique known generally as double buffering, the framebuffer uses half of its
memory to display the current frame. While that memory is being displayed, the other 3
half of memory is filled with data for the next frame.
Rendering with OpenGL

• Application generates the


geometric primitives (polygons, lines)

• System draws each one into the framebuffer

• Entire scene is redrawn anew every frame

4
The pipeline is implemented by
OpenGL, graphics driver and
the graphics hardware

OpenGL programmer does not need to implement


the pipeline.

However, pipeline is reconfigurable


➔ “shaders”
5
Graphics Pipeline

•Efficiently implementable in hardware


(but not in software)

•Each stage can employ multiple specialized processors,


working in parallel, buses between stages

•#processors per stage, bus bandwidths are fully


tuned for typical graphics use

6
Vertices (compatibility profile)

• Vertices in world coordinates


void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
– Vertex (x, y, z) is sent down the pipeline.
– Function call then returns.
• Use GLtype for portability and consistency
• glVertex{234}{sfid}[v](TYPE coords)
Number of Data Type Vector
Components s – short Omit “v” for
2 – (x, y) f – float scalar form:
3 – (x, y, z) I - integer glVertex2f(x, y) 7
4 – (x, y, z, w) d - double
Vertices (core profile)

• Vertices in world coordinates


• Store vertices into a Vertex Buffer Object (VBO)
• Upload the VBO to the GPU during program
initialization (before rendering)
• OpenGL renders directly from the VBO

8
Transformer (compatibility profile)

• Transformer in world coordinates


• Must be set before object is drawn!
glRotatef(45.0, 0.0, 0.0, -1.0);
glVertex2f(1.0, 0.0);
• Complex [Angel Ch. 3]

9
Transformer (core profile)

• Transformer in world coordinates


• 4x4 matrix
• Created manually by the user
• Transmitted to the shader program before rendering

10
Clipper

• Mostly automatic (must set viewing volume)

11
Projector

• Complex transformation [Angel Ch. 4]


Orthographic Perspective

12
Projector

• Complex transformation [Angel Ch. 4]


Orthographic Perspective

• In the perspective view (the default), objects which are far away are smaller than
13
those nearby.
• In the orthographic view, all objects appear at the same scale.
Rasterizer

• Interesting algorithms [Angel Ch. 6]


• To window coordinates
• Antialiasing

14
Geometric Primitives
• Suppose we have 8 vertices:
p0, p1, p2, p3, p4, p5, p6, p7

• Then, one can interpret them as:

• GL_POINTS, GL_LINES, GL_TRIANGLES


are examples of primitive type
15
Geometric Primitives
(compatibility profile)
• Specified via vertices
• General schema
glBegin(type);
glVertex3f(x1, y1, z1);
...
glVertex3f(xN, yN, zN);
glEnd();
• type determines interpretation of vertices
• Can use glVertex2f(x,y) in 2D

16
Example: Draw Two Square Edges
(compatibility profile)
(0,1) (1,1)
• Type = GL_LINES
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, -1.0);
glVertex3f(1.0, 0.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
(0,0) (1,0)
glVertex3f(0.0, 1.0, -1.0);
glEnd();
• Calls to other functions are allowed between
glBegin(type) and glEnd();

17
Geometric Primitives
(core profile)
• Specified via vertices
• Stored in a Vertex Buffer Object
(VBO)
int numVertices = 300;
float vertices[3 * numVertices];

// (… fill the “vertices” array …)


// create the VBO:
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
18
vertices, GL_STATIC_DRAW);
Render Points and Line Segments
(compatibility profile)

glBegin (GL_POINTS); // or GL_LINES to render lines


glVertex3f(…);

glVertex3f(…);
glEnd();

19
Render Points and Line Segments
(core profile)

glDrawArrays(GL_POINTS, 0, numVertices); // render points


glDrawArrays(GL_LINES, 0, numVertices); // render lines

20
Main difference between the two profiles
Compatibility: Core:
Initialization:
int numVertices = 300;
float vertices[3 * numVertices];

Rendering: // (… fill the “vertices” array …)

glBegin(type); // create the VBO:


glVertex3f(x1, y1, z1); GLuint vbo;

... glGenBuffers(1, &vbo);


glVertex3f(xN, yN, zN); glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnd(); glBufferData(GL_ARRAY_BUFFER,
sizeof(vertices), vertices, GL_STATIC_DRAW);

Rendering:
glDrawArrays(type, 0, numVertices);
22
Common Bug

int numVertices = 50000;


float * vertices = (float*) malloc (sizeof(float) * 3 * numVertices);

glBufferData(GL_ARRAY_BUFFER,
sizeof(vertices), vertices, GL_STATIC_DRAW);

What is wrong?

23
Common Bug
int numVertices = 50000;
float * vertices = (float*) malloc (sizeof(float) * 3 * numVertices);

glBufferData(GL_ARRAY_BUFFER,
sizeof(vertices), vertices, GL_STATIC_DRAW);

glBufferData(GL_ARRAY_BUFFER,
sizeof(float) * 3 * numVertices, vertices, GL_STATIC_DRAW);

24
Polygons
• Polygons enclose an area

• Rendering of area (fill) depends on attributes


• All vertices must be in one plane in 3D
• GL_POLYGON and GL_QUADS are only
available in the compatibility profile
(removed in core profile since OpenGL 3.1)
25
Triangle Strips

• Efficiency in space and time


• Reduces visual artefacts on old graphics cards

26
Summary

1. Graphics pipeline
2. Primitives: vertices, lines, triangles

27

You might also like