Opengl: Introduction To Opengl - Opengl Architecture
Opengl: Introduction To Opengl - Opengl Architecture
Opengl: Introduction To Opengl - Opengl Architecture
3
OpenGL architecture
OpenGL Operation/ Architecture
From OpenGL reference
Display manual “Blue book”
List
Per- Rasteri-
Vertex zation
Eval- Opns. &
Comm- uator primitive Per-
ands assembly fragment
opns.
Pixel
opns. Texture
memory
What is to be Frame
drawn? buffer
How it is to be
drawn?
OpenGL
Can accumulate some
Operation
commands in a display list
for processing at a later
Display time (Batch mode). Or can
Lists proceed immediately
through the pipeline
Per- Per-
Eval- Vertex Rasteri-
Comm- frag-
uator Opns. & zation
ands ment
primitive opns.
assembly
Texture
Pixel
memory
opns.
From OpenGL Frame
reference manual buffer
“Blue book”
OpenGL Provides an efficient means
for approximating curve
Operation and surface geometry by
evaluating polynomial
Display
commands of input values
Lists
Per-
Per-
Eval- Raster- frag-
Vertex
Comm- uator ization ment
opns. &
ands opns.
primitive
assembly
Texture
Pixel memory
opns.
Frame
From OpenGL reference
buffer
manual “Blue book”
OpenGL Process geometric primitives -
points, line segments, and
Operation polygons as vertices and are
transformed, lit, and clipped to
Display the viewport in preparation for
Lists the next stage.
Per-
Comm- Per-
Eval- Raster- frag-
Vertex
uator ization ment
opns. &
opns.
primitive
assembly
Texture
Pixel memory
opns.
Frame
From OpenGL reference
buffer
manual “Blue book”
OpenGL Produces a series of
frame buffer addresses
Operation and associated values
using a two-dimensional
Display description of a point,
Lists line segment, or polygon
Per-
Per-
Eval- Raster- frag-
Comm- Vertex
uator ization ment
ands opns &
opns.
primitive
assembly
Texture
Pixel memory
opns.
Frame
From OpenGL reference
buffer
manual “Blue book”
OpenGL Z-buffering, and blending
of incoming pixel colors
Operation with stored colors, and
masking and other logical
Display
operations on pixel values
Lists
Per-
Per-
Eval- Raster- frag-
Vertex
Comm- uator ization ment
opns &
ands opns.
primitive
assembly
Texture
Pixel memory
From OpenGL opns.
Frame
reference manual
buffer
“Blue book”
OpenGL Input data can be in
the form of pixels
Operation (image for texture
mapping) is processed
Display
Lists in the pixel operations
stage.
Per- Per-
Eval- Vertex Raster- frag-
Comm- uator ops & ization ment
ands primitive opns
assembly
Texture
Pixel memory
opns
Frame
buffer
OpenGL architecture
• Commands may either be accumulated in display lists, or processed
immediately through the pipeline. Display lists allow for greater
optimization and command reuse, but not all commands can be put in
display lists.
• The first stage in the pipeline is the evaluator. This stage effectively takes
any polynomial evaluator commands and evaluates them into their
corresponding vertex and attribute commands.
• The second stage is the per-vertex operations, including transformations,
lighting, primitive assembly, clipping, projection, and viewport mapping.
• The third stage is rasterization. This stage produces fragments, which are
series of framebuffer addresses and values, from the viewport-mapped
primitives as well as bitmaps and pixel rectangles.
• The fourth stage is the per-fragment operations. Before fragments go to
the framebuffer, they may be subjected to a series of conditional tests and
modifications, such as blending or z-buffering.
• Parts of the framebuffer may be fed back into the pipeline as pixel
rectangles. Texture memory may be used in the rasterization process
when texture mapping is enabled.
OpenGL API
Library Organization
OpenGL (GL)
• Core Library
• OpenGL on Windows.
OpenGL Utility Library (GLU)
• It uses only GL functions to create common objects.
• It is available in all OpenGL implementations.
OpenGL Utility Toolkit (GLUT)
• It provides the minimum functionalities expected for
interacting with modern windowing systems.
1
OpenGL API
Program Structure
Step 1: Initialize the interaction between windows
and OpenGL.
Step 2: Specify the window properties and further
create window.
Step 3: Set the callback functions
Step 4: Initialize the program attributes
Step 5: Start to run the program
1
OpenGL API
Program Framework
#include <GL/glut.h> includes gl.h
glutDisplayFunc(myDisplay);
display callback
myInit(); set OpenGL state
glutMainLoop();
enter event loop
}
1
OpenGL API
Program Framework: Window Management
glutInit():initializes GLUT and should be
called before any other GLUT routine.
glutInitDisplayMode():specifies the
color model (RGB or color-index color model)
glutInitWindowSize(): specifies the size,
in pixels, of your window.
glutInitWindowPosition():specifies the
screen location for the upper-left corner
glutCreateWindow():creates a window
with an OpenGL context.
1
OpenGL API
Program Framework
void myInit(){
/* set colors */
glClearColor(1.0, 1.0, 1.0, 0.0);
}/* End of myInit */
void myDisplay(){
/* clear the display */
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}/* End of GasketDisplay */
1
OpenGL API
1
Primitives and Attributes
Program Form of Primitives
glBegin(type);
glVertex*(…);
glVertex*(…);
.
.
glVertex*(…);
glEnd();
1
Primitives and Attributes
Program Form of Primitives
Vertex Function: glVertex* ()
• * : can be as the form [nt | ntv]
• n : the number of dimensions (2, 3, 4)
• t : data type (i: integer, f: float, and d: double)
• v : the variables is a pointer.
glVertex2i (GLint x, GLint y);
glVertex3f(GLfloat x, GLfloat y, GLfloat z);
glVertex2fv(p); // int p[2] = {1.0, 1.0}
1
Primitives and Attributes
Points and Line Segment
Point: GL_POINTS
Line Segments: GL_LINES
Polygons:
• GL_LINE_STRIP
• GL_LINE_LOOP
1
Primitives and Attributes
Polygon Primitives
Polygons: GL_POLYGON
Triangles: GL_TRIANGLES
Quadrilaterals: GL_QUADS
Stripes: GL_TRIANGLE_STRIP
Fans: GL_TRIANGLE_FAN
2
Primitives and Attributes
RGB-Model
Setting Operations
glColor3f(r value, g value, b value);
2
OpenGL Geometric Drawing Primitives