Inside3D!
     

OpenGL 2D Examples - 102 Using the Basics

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> OpenGL Programming
View previous topic :: View next topic  
Author Message
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Wed Dec 17, 2008 3:03 am    Post subject: OpenGL 2D Examples - 102 Using the Basics Reply with quote

This focuses on applying the 2D basics and assumes you understand:

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:
glClearColor (0, 0, 0, 0)
glMatrixMode (GL_PROJECTION) // Projection matrix
glOrtho(0, 512, 512, 0, 0, 1)  // Define 2D coordinates = 512 x 512


Rendering each frame:

Code:

    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

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> OpenGL Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group