Hello OpenGL Forum!!!

BlitzMax Forums/BlitzMax OpenGL Programming/Hello OpenGL Forum!!!

' thenks to PaulJG for excellent tutorial
Global GW:Int=800
Global GH:Int=600
Global angle:Float=0
Global mode = GL_QUADS
Global msg:String = "GL_QUADS"
bglCreateContext(GW,GH,32,0,BGL_BACKBUFFER|BGL_DEPTHBUFFER)'|BGL_FULLSCREEN)
init()



Repeat 
	click_timer:-1
	If click_timer < 0 Then click_timer = 0
	
	If MouseDown(1) = 1 And click_timer = 0
		glmode = glmode + 1
		If glmode>6 Then glmode = 0
		Select glmode
			Case 0 mode = GL_QUADS ; msg$ = "GL_QUADS"
			Case 1 mode = GL_LINES ; msg$ = "GL_LINES"
			Case 2 mode = GL_POLYGON ; msg$ = "GL_POLYGON"
			Case 3 mode = GL_TRIANGLES ; msg$ = "GL_TRIANGLES"
			Case 4 mode = GL_LINE_STRIP ; msg$ = "GL_LINE_STRIP"
			Case 5 mode = GL_LINE_LOOP ; msg$ = "GL_LINE_LOOP"
			Case 6 mode = GL_POINTS ; msg$ = "GL_POINTS"

		End Select
		click_timer = 50
	EndIf
	
	frametimer(2)
	display(mode)
	
	idle_function()
	glColor3f(1.0,1.0,1.0)
	bglDrawText(msg$,10,10)
	
	bglSwapBuffers

Until KeyDown(KEY_ESCAPE)
End

Function init()
	glClearColor(0.0, 0.0, 0.0, 0.0)
	glClearDepth(1.0)
	glEnable(GL_CULL_FACE)
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluPerspective(45.0, Float(GW)/Float(GH), 0.1, 100.0)
	glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()
End Function

Function display(mode)
	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
	glLoadIdentity()
	glTranslatef(0.0, 0.0, (Sin(angle)*10)-15)
	glRotatef(angle, 0.0, -1.0, 1.0)
	glBegin(mode)
	
		glColor3f(1.0,1.0,0.0) 			' Front Face yellow
	
			glVertex3f(-1.0, -1.0, 1.0) 
			glVertex3f( 1.0, -1.0, 1.0)
		glColor3f(1.0,0.0,0.0) 			'  Red
			glVertex3f( 1.0, 1.0, 1.0)
			glVertex3f(-1.0, 1.0, 1.0)

		glColor3f(0.0,0.5,0.0) 			' Back Face Dark Green
			glVertex3f(-1.0, -1.0, -1.0)
			glVertex3f(-1.0, 1.0, -1.0)
			glVertex3f( 1.0, 1.0, -1.0)
		glColor3f(0.0,1.0,0.0)
			glVertex3f( 1.0, -1.0, -1.0)

		glColor3f(1.0,0.0,0.0) ' Top Face Red
			glVertex3f(-1.0, 1.0, -1.0)
			glVertex3f(-1.0, 1.0, 1.0)
			glVertex3f( 1.0, 1.0, 1.0)
			glVertex3f( 1.0, 1.0, -1.0)

		glColor3f(0.0,0.0,1.0) ' Bottom Face Blue
			glVertex3f(-1.0, -1.0, -1.0)
			glVertex3f( 1.0, -1.0, -1.0)
		glColor3f(0.0,0.0,0.1)
			glVertex3f( 1.0, -1.0, 1.0)
			glVertex3f(-1.0, -1.0, 1.0)

		glColor3f(0.1,0.1,0.1) ' Right face Gray??
			glVertex3f( 1.0, -1.0, -1.0)
			glVertex3f( 1.0, 1.0, -1.0)
		glColor3f(0.0,0.0,0.0)
			glVertex3f( 1.0, 1.0, 1.0)
			glVertex3f( 1.0, -1.0, 1.0)

		glColor3f(1.0,1.0,1.0) ' Left Face White
			glVertex3f(-1.0, -1.0, -1.0)
			glVertex3f(-1.0, -1.0, 1.0)
		glColor3f(0.0,0.0,.75) 'blue
			glVertex3f(-1.0, 1.0, 1.0)
			glVertex3f(-1.0, 1.0, -1.0)
	
	

glEnd()
End Function

Function idle_function()
angle:+.1
If angle>360.0 angle=0.0
End Function


Function frametimer(msecs)
	now = MilliSecs()
	
	Repeat
		passed = MilliSecs()-now
		
	Until passed > msecs 

End Function


Woot!

Great Demo. I especially like it how you can change the drawing mode. I made the following small changes to your code.

- added some text to display the current mode and prompt the user.
- modified the click timing routine so it's more efficient.
- changed the rotation of the cube so that all six sides will be seen.
- changed the "gray??" colour to purple :)

' rem OPENGL spinnning cube by Bill Radford V1
' thanks to PaulJG for excellent tutorial
Global GW:Int=1024
Global GH:Int=768
Global angle:Float=0
Global mode = GL_QUADS
Global msg:String="GL_QUADS"
bglCreateContext(GW,GH,32,0,BGL_BACKBUFFER|BGL_DEPTHBUFFER|BGL_FULLSCREEN)
init()


Repeat 
	If MilliSecs() > click_timer
		If MouseDown(1) = True
			glmode :+ 1
			If glmode>6 Then glmode = 0
			Select glmode
				Case 0 mode = GL_QUADS ; msg$ = "GL_QUADS"
				Case 1 mode = GL_LINES ; msg$ = "GL_LINES"
				Case 2 mode = GL_POLYGON ; msg$ = "GL_POLYGON"
				Case 3 mode = GL_TRIANGLES ; msg$ = "GL_TRIANGLES"
				Case 4 mode = GL_LINE_STRIP ; msg$ = "GL_LINE_STRIP"
				Case 5 mode = GL_LINE_LOOP ; msg$ = "GL_LINE_LOOP"
				Case 6 mode = GL_POINTS ; msg$ = "GL_POINTS"
			End Select
			click_timer = MilliSecs() + 250
		EndIf
	EndIf
	
	frametimer(2)
	display(mode)
	

	bglDrawText("Mode: "+msg$,10,10)
	bglDrawText("Use Left Mouse Button to cycle through modes.",10,30)
	idle_function()
	bglSwapBuffers
	

Until KeyDown(KEY_ESCAPE)
End

Function init()
	glClearColor(0.0, 0.0, 0.0, 0.0)
	glClearDepth(1.0)
	glEnable(GL_CULL_FACE)
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluPerspective(45.0, Float(GW)/Float(GH), 0.1, 100.0)
	glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()
	
End Function

Function display(mode)
	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
	glLoadIdentity()
	glTranslatef(0.0, 0.0, (Sin(angle)*10)-15)
	glRotatef(angle, 1.0, -1.0, 1.0)
	
	glBegin(mode)
		glColor3f(1.0,1.0,0.0) ' Front Face yellow
		glVertex3f(-1.0, -1.0, 1.0)
		glVertex3f( 1.0, -1.0, 1.0)
		glVertex3f( 1.0, 1.0, 1.0)
		glVertex3f(-1.0, 1.0, 1.0)

		glColor3f(0.0,1.0,0.0) ' Back Face Green
		glVertex3f(-1.0, -1.0, -1.0)
		glVertex3f(-1.0, 1.0, -1.0)
		glVertex3f( 1.0, 1.0, -1.0)
		glVertex3f( 1.0, -1.0, -1.0)

		glColor3f(1.0,0.0,0.0) ' Top Face Red
		glVertex3f(-1.0, 1.0, -1.0)
		glVertex3f(-1.0, 1.0, 1.0)
		glVertex3f( 1.0, 1.0, 1.0)
		glVertex3f( 1.0, 1.0, -1.0)

		glColor3f(0.0,0.0,1.0) ' Bottom Face Blue
		glVertex3f(-1.0, -1.0, -1.0)
		glVertex3f( 1.0, -1.0, -1.0)
		glVertex3f( 1.0, -1.0, 1.0)
		glVertex3f(-1.0, -1.0, 1.0)

		glColor3f(0.8,0.0,1.0) ' Right face Purple
		glVertex3f( 1.0, -1.0, -1.0)
		glVertex3f( 1.0, 1.0, -1.0)
		glVertex3f( 1.0, 1.0, 1.0)
		glVertex3f( 1.0, -1.0, 1.0)

		glColor3f(1.0,1.0,1.0) ' Left Face White
		glVertex3f(-1.0, -1.0, -1.0)
		glVertex3f(-1.0, -1.0, 1.0)
		glVertex3f(-1.0, 1.0, 1.0)
		glVertex3f(-1.0, 1.0, -1.0)
	
		
	glEnd()
	
End Function

Function idle_function()
	angle:+.05
	If angle>360.0 angle=0.0
End Function


Function frametimer(msecs)
	now = MilliSecs()
	
	Repeat
		passed = MilliSecs()-now
		
	Until passed > msecs 

End Function


Code box working now... :) Thanks Perturbatio.

use codebox instead of code.

see What are the forum codes? for more info.