OpenGL includes functions to draw points, lines, and triangles.
All other shapes are made up of these elements.
A basic shape is entirely described by its vertices, which are connected by straight edges.
The graphics hardware fills in all the necessary pixels.
GL_POINTS | GL_LINES | GL_LINE_STRIP | GL_LINE_LOOP |
---|---|---|---|
GL_TRIANGLES | GL_TRIANGLE_STRIP | GL_TRIANGLE_FAN | |
Using a Pyglet vertex_list:
vlist = pyglet.graphics.vertex_list(3, ('v2f', [0,0, 400,50, 200,300])) ... vlist.draw(GL_TRIANGLES)
For older, fixed-function pipeline, the basic method for drawing a shape is:
glBegin(...) glVertex(...) glVertex(...) glVertex(...) ... glEnd()
Always be sure to have a matching glEnd() for each glBegin()
A coordinate system is needed for measuring objects' positions
It allows us to describe any location by a set of numbers - 2 numbers when working in 2 dimensions, 3 numbers for 3 dimensions.
A coordinate system has an origin (a reference point) and coordinate axes
In 2D we have an X axis and a Y axis. In 3D, we add a Z axis.
The axes are perpendicular - they are independent
Some coordinate systems used:
For older, fixed-function pipeline
The default drawing coordinate system can be changed with the function gluOrtho2D
e.g.:
glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0.0, 10.0, 0.0, 5.0) glMatrixMode(GL_MODELVIEW)