Geometry






OpenGL Geometry

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.






OpenGL Geometry

GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP
   
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN





OpenGL Geometry

Using a Pyglet vertex_list:

    vlist = pyglet.graphics.vertex_list(3, ('v2f', [0,0, 400,50, 200,300]))

    ...

    vlist.draw(GL_TRIANGLES)





OpenGL Geometry

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()










Coordinate Systems






Coordinate Systems

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






Coordinate Systems

Some coordinate systems used:






gluOrtho2D

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)


Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.