Lecture 10_ Graphics Software and OpenGL
Lecture 10_ Graphics Software and OpenGL
glVertex3f(x,y,z)
glVertex3fv(p)
p is a pointer to an array
OpenGL Command Formats
glVertex3fv( v )
nonconvex polygon
nonsimple polygon
Attributes
• Attributes are part of the OpenGL state and determine
the appearance of objects
• Color (points, lines, polygons)
• Size and width (points, lines)
• Stipple pattern (lines, polygons)
• Polygon mode
• Display as filled: solid color or stipple pattern
• Display edges
• Display vertices
RGB color
• Each color component is stored separately in the frame
buffer
• Usually 8 bits per component in buffer
• Note in glColor3f the color values range from 0.0
(none) to 1.0 (all), whereas in glColor3ub the values
range from 0 to 255
Color and State
• The color as set by glColor becomes part of the state and
will be used until changed
• Colors and other attributes are not part of the object but are
assigned when the object is rendered
• We can create conceptual vertex colors by code such as
glColor
glVertex
glColor
glVertex
Viewports
• Do not have to use the entire window for the image:
glViewport(x,y,w,h)
• Values in pixels (screen coordinates)
Geometric Primitive Types
Geometric Primitive Types
• GL_POINTS : Draws a point at each of the n vertices.
• GL_LINES : Draws a series of unconnected line segments. Segments
are drawn between v0 and v1, between v2 and v3, and so on. If n is
odd, the last segment is drawn between vn-3 and vn-2, and vn-1 is
ignored.
• GL_LINE_STRIP : Draws a line segment from v0 to v1, then
from v1 to v2, and so on, finally drawing the segment from vn-2 to
vn-1. Thus, a total of n-1 line segments are drawn. Nothing is drawn
unless n is larger than 1. There are no restrictions on the vertices
describing a line strip (or a line loop); the lines can intersect
arbitrarily.
• GL_LINE_LOOP : Same as GL_LINE_STRIP, except that a final
line segment is drawn from vn-1 to v0, completing a loop.
Geometric Primitive Types
• GL_TRIANGLES : Draws a series of triangles (three-sided
polygons) using vertices v0, v1, v2, then v3, v4, v5, and so on. If n
isn't an exact multiple of 3, the final one or two vertices are
ignored.
• GL_TRIANGLE_STRIP : Draws a series of triangles (three-sided
polygons) using vertices v0, v1, v2, then v2, v1, v3 (note the
order), then v2, v3, v4, and so on. The ordering is to ensure that
the triangles are all drawn with the same orientation so that the
strip can correctly form part of a surface. Preserving the
orientation is important for some operations, such as culling.
• GL_TRIANGLE_FAN :Same as GL_TRIANGLE_STRIP, except that the
vertices are v0, v1, v2, then v0, v2, v3, then v0, v3, v4, and so on.
Geometric Primitive Types
• GL_QUADS : Draws a series of quadrilaterals (four-sided polygons)
using vertices v0, v1, v2, v3, then v4, v5, v6, v7, and so on. If n isn't
a multiple of 4, the final one, two, or three vertices are ignored.
• GL_QUAD_STRIP: Draws a series of quadrilaterals (four-sided
polygons) beginning with v0, v1, v3, v2, then v2, v3, v5, v4, then
v4, v5, v7, v6, and so on. n must be at least 4 before anything is
drawn. If n is odd, the final vertex is ignored.
• GL_POLYGON :Draws a polygon using the points v0, ... , vn-1 as
vertices. n must be at least 3, or nothing is drawn. In addition, the
polygon specified must not intersect itself and must be convex. If
the vertices don't satisfy these conditions, the results are
unpredictable.
Header files
• #include <windows.h>
• #include <GL/gl.h>
• #include <GL/glu.h>
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);// red
glVertex3f(-4.0, -2.0, 0.0);
glColor3f(0.0, 1.0, 0.0);// green
glVertex3f(4.0, -2.0, 0.0);
glColor3f(0.0, 0.0, 1.0);// blue
glVertex3f(0.0, 5.0, 0.0);
glEnd();
WebGL
• WebGL is abbreviated as Web Graphics Library.
• It is mainly designed for rendering 2D graphics and
Interactive 3D graphics.
• It is Javascript API that can be used with HTML5.
• It supports cross-platform, and it is available in the English
language only.
• The WebGL programs consist of a control code that is
written in JavaScript.
• OpenGL is called as Open Graphics Library. It is referred to
as a cross-language and platform application programming
interface for rendering two dimensional and three-
dimensional vector graphics. OpenGL provides many
functionalities like extensions.
Revision Questions
1. Differentiate between GLU and GLUT components of
an OpenGL.
2. Explain the following OpenGL functions:
a) glVertex2i(12,30)
b) glClearColor (1.0,1.0,0.7,0.1)
c) glDisplayMode(object)
3. Compare and Contrast WebGL and OpenGL