Primitives
Primitives
+X
What is a “pixel”
3
0 1 2 3 4 5
But when we think about images, a pixel is a rectangle.
Q: Where is (2,1)? A. The center of a pixel
0 1 2 3 4
Basic OpenGL Point Structure
• In OpenGL, to specify a point:
– glVertex*();
• In OpenGL, some functions require both a dimensionality and a data
type
– glVertex2i(80,100), glVertex2f(58.9, 90.3)
– glVertex3i(20,20,-5), glVertex3f(-2.2,20.9,20)
• Must put within a ‘glBegin/glEnd’ pair
– glBegin(GL_POINTS);
– glVertex2i(50,50);
– glVertex2i(60,60);
– glVertex2i(60,50);
– glEnd();
• Let’s draw points in our assignment #1
• Next up? Lines
Draw a line from 0,0 to 4,2
How do we choose between 1,0 and 1,1? What would be a good heuristic?
(4,2)
2
(0,0)
0 1 2 3 4
What are lines composed of?
Write glBegin(GL_LINES)
(4,2)
2
(0,0)
0 1 2 3 4
What we are working with
V1: (6,8) V2: (13,8)
(2,0)
0
0 1 2 3 4
(-0.2,2) Consider a translation (3.8,2)
(1.8,0)
0
0 1 2 3 4
The Ideal Line
(17,8)
What do we want?
• Continuous
appearance
• Uniform
thickness and
brightness (2,2)
• Pixels near the
ideal line are Discretization - converting a continuous signal
“on” into discrete elements.
(0,9)
(17,8)
(2,2)
(0,0) (18,0)
How do we change the
framebuffer?
(0,9) What’s the index into GLubyte framebuffer[]? Point is 9,5
(17,8)
(2,2)
(0,0) (18,0)
Example:
(0,9) (7,9)
Example 2:
Point1 V:(7,9 ) C:( 0,255,0)
Point2 V:(12,0) C:(0,255,0)
(0,9)
(17,8)
(2,2)
(0,0) (18,0)
Recap
• DDA/Line Intercept Algorithm
– Slope Intercept y = mx + b
– Easy to implement
– Slow
• Bresenham
– No floating point math
– Fast