Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lecture # 2: Introduction Of
OpenGL
BSE
Joddat Fatima
Joddat.fatima@gmail.com
Department of C&SE
Bahria University Islamabad
1
What Is OpenGL?
With OpenGL, you must build up your desired model from a small set of
geometric primitives - points, lines, and polygons.
2
3
GL Utility Toolkit (GLUT)
OpenGL
Very portable
GLUT:
No sliders
No dialog boxes
glutInit(int *argc, char **argv) initializes GLUT and processes any command line
arguments (for X, this would be options like -display and -geometry). glutInit()
should be called before any other GLUT routine.
For window to have an associated depth, stencil, and/or accumulation buffer. If you
want a window with double buffering, the RGBA color model, and a depth buffer,
you might call glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|
GLUT_DEPTH).
7
Window Management
Function main
Does initialization
Function init
Function display
Put comments like this on all programs for this class and
every other program you write for the rest of your
life.
#include <GL/glut.h> // GLUT stuff
and others.
16
intro1.cpp:
Function main [4/4]
// Do something
glutMainLoop();
return 0;
}
What is important to know now is that the first 4 parameters of glOrtho set
up a coordinate system for the window:
y-coordinate of bottom
y-coordinate of top
19
intro1.cpp:
Function display [1/4]
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClear sets every pixel in the color buffer to the color specified
with glClearColor.
3d means 3 GLdoubles.
Specifying the coordinates of actual things to draw is done between glBegin and
glEnd.
Indentation between glBegin and glEnd is helpful (but, of course, not required).
22
intro1.cpp:
Function display [4/4]
glBegin(GL_LINE_LOOP);
glVertex2d(0.5, 0.4);
glVertex2d(0.4, 0.2);
glVertex2d(0.6, 0.2);
glEnd();
Advantages to function-call-intensive
approach to API design:
Disadvantages:
The basic structure of a useful program can be simple: Its tasks are
to initialize certain states that control how OpenGL renders and to
specify objects to be rendered.
Before you look at some OpenGL code, let's go over a few terms.
The final rendered image consists of pixels drawn on the screen; a pixel
is the smallest visible element the display hardware can put on the
screen.
Information about the pixels (for instance, what color they're supposed
to be) is organized in memory into bitplanes.