1. how draw a line/point/polygon
2. anti-alias them if needed
3. Know the basic opengl functions
All this was covered in the last thread which ended with drawing a speedometer needle on a speedometer texture:
This thread is going to start to get into applying these concepts to try things and then getting into alpha masking and alpha blending and more versatile use of textures.
Drawing a Checkboard
Not much explanation is needed here, but the reason I am bothering to do this is because one common use of 2D graphics is tile oriented games.
Initialization:
Code: Select all
glClearColor (0, 0, 0, 0)
glMatrixMode (GL_PROJECTION) // Projection matrix
glOrtho(0, 512, 512, 0, 0, 1) // Define 2D coordinates = 512 x 512
Code: Select all
glClear (GL_COLOR_BUFFER_BIT) // Clear it
For i = 0 To 7
For j = 0 To 7
If (i + j) And 1 Then // Even=odd test
glColor3f (1, 1, 1) // White
Else
glColor3f (1, 0, 0) // Red
End If
glBegin (GL_QUADS)
x1 = i * 32 + 128 // 128 = left start, 32 = tile size
y1 = j * 32 + 128 // 128 = top start, 32 = tile size
x2 = x1 + 32
y2 = y1 + 32
glVertex2d (x1, y1)
glVertex2d (x2, y1)
glVertex2d (x2, y2)
glVertex2d (x1, y2)
glEnd ()
Next
Next