OpenGL through Blitzmax

BlitzMax Forums/BlitzMax Programming/OpenGL through Blitzmax

Read the redbook (www.opengl.org). Seriously. It's actually not hard to understand the way they explain it, and all you have to do is convert it over. After reading the first 2 chapters, I whipped up this (to show basic triangle and vertex array operations) in five minutes:

SetGraphicsDriver GLMax2DDriver()
Graphics 800,600

glViewport (0, 0, 800, 600)
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()

Local pt1: Float [] = [0.5,0.0,0.75]
Local pt2: Float [] = [0.0,0.5,0.75]
Local pt3: Float [] = [0.5,0.5,-0.75]
Local offset: Float [] = [-0.75,0.0,0.5]

Repeat

Cls

glBegin(GL_POLYGON)

glColor3f(1.0,0,0)
glVertex3fv (pt1)
glColor3f(0,1.0,0)
glVertex3fv (pt2)
glColor3f(0,0,1.0)
glVertex3fv (pt3)

glEnd()

glBegin(GL_POLYGON)

glColor3f(1.0,0,0)
glVertex3fv (AddVecs(pt1,offset))
glColor3f(0,1.0,0)
glVertex3fv (AddVecs(pt2,offset))
glColor3f(0,0,1.0)
glVertex3fv (AddVecs(pt3,offset))

glEnd()


Flip()



Until KeyDown(KEY_ESCAPE) Or AppTerminate()

Function AddVecs:Float[](in:Float[],modd:Float[])
	Local total:Float [] = New Float[3]
	total[0] = in[0]+modd[0]
	total[1] = in[1]+modd[1]
	total[2] = in[2]+modd[2]
	Return total

End Function

And
Framework BRL.GLMax2D

SetGraphicsDriver GLMax2DDriver()
Graphics 800,600

glViewport (0, 0, 800, 600)
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()

Local x:Float = 0.5

Local pt1: Float [] = [x,0.0,0.75,0.0,x,0.75,x,x,0.75]
Local offset: Float [] = [-0.75,0.0,0.5]

Repeat

Cls

glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3,GL_FLOAT,0,pt1)

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

glBegin(GL_TRIANGLES)

glColor3f(1.0,0,0)
glArrayElement(1)
glArrayElement(2)
glArrayElement(3)

glEnd()


glLoadIdentity()
glRotatef(180,0.0,0.0,1.0)
glTranslatef(.25,0,0)
glBegin(GL_TRIANGLES)

glColor3f(0,0,1.0)
glArrayElement(1)
glArrayElement(2)
glArrayElement(3)

glEnd()


Flip()



Until KeyDown(KEY_ESCAPE) Or AppTerminate()

It's that easy to code basic images in OpenGL. Now, when you start creating more complicated scenes...