Using Multiple Textures

BlitzMax Forums/BlitzMax OpenGL Programming/Using Multiple Textures

I've tried to do a cube with different textures per side.
And Im having lots of problems with this. As it works with the one texture, and not with anymore.

'=======================
' 6 Sided textured cube
' Please use your own media.
'=======================

Strict

Const XRES=640
Const YRES=480
Const RRES= 32

bglCreateContext(XRES,YRES,RRES,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER | BGL_FULLSCREEN)

HideMouse

Global Texture:Int[6]
Global XROT:Float
Global YROT:Float
Global ZROT:Float

InitOpenGL()



'
' The main program loop.
'
While Not KeyHit(KEY_ESCAPE)
	
	UpdateOpenGL()	
	bglSwapBuffers

Wend
End


Function InitOpenGL()

	LoadGLTextures	()

	glEnable		(GL_TEXTURE_2D)									' Enable Texture Mapping

	glViewPort	(0,0,XRES,YRES)
	
	glMatrixMode	(GL_PROJECTION)
	glLoadIdentity ()

	gluPerspective	(45.0,Float(XRES)/Float(YRES),0.1,100.0)

	glMatrixMode	(GL_MODELVIEW)						
	glLoadIdentity	()	


	glShadeModel	(GL_SMOOTH)
	glClearColor	(0.0, 0.0, 0.0, 0.0)

	glClearDepth	(1.0)							
	glEnable		(GL_DEPTH_TEST)					
	glDepthFunc	(GL_LEQUAL)		

	glHint		(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

End Function



Function UpdateOpenGL()
	
	glClear		(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)			
	glLoadIdentity	()	
	
	
	'
	' Draw The 6 different Textured cube.
	'
	glLoadIdentity	()						'GLLoadIdentity resets to center of screen ;)
	glTranslatef	( 0, 0.0, -5.0 )			'Move Right 1.5 Units and into the screen 7.0
	
	glRotatef		( XROT, 1.0, 1.0, 1.0 ) 		'rotate the cube on all axis x,y and z.
	
	glBegin		(GL_QUADS)				'Draw using Quads.
		
		
		'		
		' Front Face.
		'
		glBindTexture	(GL_TEXTURE_2D, Texture[0] )

		glNormal3f	( 0.0, 0.0, 1.0 )
		
		glTexCoord2f	( 0.0, 0.0 );   glVertex3f  (-1.0, -1.0,  1.0 )
		glTexCoord2f	( 1.0, 0.0 );   glVertex3f  ( 1.0, -1.0,  1.0 )
		glTexCoord2f	( 1.0, 1.0 );   glVertex3f  ( 1.0,  1.0,  1.0 )
		glTexCoord2f	( 0.0, 1.0 );   glVertex3f  (-1.0,  1.0,  1.0 )
		
		
		'
		' Back Face.
		'
		glBindTexture	(GL_TEXTURE_2D, Texture[1])
	
		glNormal3f	( 0.0, 0.0,-1.0 )
		
		glTexCoord2f	( 1.0, 0.0 ); 	 glVertex3f  ( -1.0, -1.0, -1.0 )
		glTexCoord2f	( 1.0, 1.0 );	 glVertex3f  ( -1.0,  1.0, -1.0 )
		glTexCoord2f	( 0.0, 1.0 );	 glVertex3f  (  1.0,  1.0, -1.0 )
		glTexCoord2f	( 0.0, 0.0 ); 	 glVertex3f  (  1.0, -1.0, -1.0 )
	
		
		'	
		' Top Face.
		'
		glBindTexture	(GL_TEXTURE_2D, Texture[2])

		glNormal3f	( 0.0, 1.0, 0.0 )
		
		glTexCoord2f	( 0.0, 1.0 );   glVertex3f  ( -1.0,  1.0, -1.0 )
		glTexCoord2f	( 0.0, 0.0 );   glVertex3f  ( -1.0,  1.0,  1.0 )
		glTexCoord2f	( 1.0, 0.0 );   glVertex3f  (  1.0,  1.0,  1.0 ) 
		glTexCoord2f	( 1.0, 1.0 );   glVertex3f  (  1.0,  1.0, -1.0 )
		
		
		'
		' Bottom Face.
		'
		glBindTexture	(GL_TEXTURE_2D, Texture[3])

		glNormal3f	( 0.0, -1.0, 0.0 )
		
		glTexCoord2f	( 1.0, 1.0 );   glVertex3f  ( -1.0, -1.0, -1.0 )
		glTexCoord2f	( 0.0, 1.0 );   glVertex3f  (  1.0, -1.0, -1.0 )
		glTexCoord2f	( 0.0, 0.0 );   glVertex3f  (  1.0, -1.0,  1.0 ) 
		glTexCoord2f	( 1.0, 0.0 );   glVertex3f  ( -1.0, -1.0,  1.0 )
		
		
		'
		' Right Face.
		'
		glBindTexture	(GL_TEXTURE_2D, Texture[4])

		glNormal3f	( 1.0, 0.0, 0.0 )
		
		glTexCoord2f	( 1.0, 0.0 );   glVertex3f  ( 1.0, -1.0, -1.0 )
		glTexCoord2f	( 1.0, 1.0 );   glVertex3f  ( 1.0,  1.0, -1.0 )
		glTexCoord2f	( 0.0, 1.0 );   glVertex3f  ( 1.0,  1.0,  1.0 )
		glTexCoord2f	( 0.0, 0.0 );   glVertex3f  ( 1.0, -1.0,  1.0 )
		
		
		'
		' Left Face.
		'
		glBindTexture	(GL_TEXTURE_2D, Texture[5])

		glNormal3f	( -1.0, 0.0, 0.0 )
		
		glTexCoord2f	( 0.0, 0.0 );   glVertex3f  ( -1.0, -1.0, -1.0 )
		glTexCoord2f	( 1.0, 0.0 );   glVertex3f  ( -1.0, -1.0,  1.0 )
		glTexCoord2f	( 1.0, 1.0 );   glVertex3f  ( -1.0,  1.0,  1.0 )
		glTexCoord2f	( 0.0, 1.0 );   glVertex3f  ( -1.0,  1.0, -1.0 )

	glEnd()								'Done Drawing The Quad.

XROT:+.1

End Function



Function LoadGLTextures()
	
	Local Text1:TPixmap =LoadPixmap("media/texture1.png")
	Local Text2:TPixmap =LoadPixmap("media/texture2.png")
	Local Text3:TPixmap =LoadPixmap("media/texture3.png")
	Local Text4:TPixmap =LoadPixmap("media/texture4.png")
	Local Text5:TPixmap =LoadPixmap("media/texture5.png")
	Local Text6:TPixmap =LoadPixmap("media/texture6.png")

	
	'
	' Create 1st MipMapped Texture
	'
	glGenTextures(1, Varptr Texture[0])									' Create a Texture

	glBindTexture		(GL_TEXTURE_2D, Texture[0])
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps	(GL_TEXTURE_2D, 3, Text1.width, Text1.height, GL_RGB, GL_UNSIGNED_BYTE, Text1.pixels)


	'
	' Create 2nd MipMapped Texture
	'

	glGenTextures		(1, Varptr Texture[1])									' Create a Texture

	glBindTexture		(GL_TEXTURE_2D, Texture[1])
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps	(GL_TEXTURE_2D, 3, Text2.width, Text2.height, GL_RGB, GL_UNSIGNED_BYTE, Text2.pixels)


	'
	' Create 3rd MipMapped Texture
	'
	glGenTextures		(1, Varptr Texture[2])									' Create a Texture

	glBindTexture		(GL_TEXTURE_2D, Texture[2])
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps	(GL_TEXTURE_2D, 3, Text3.width, Text3.height, GL_RGB, GL_UNSIGNED_BYTE, Text3.pixels)


'
	' Create 4th MipMapped Texture
	'
	glBindTexture		(GL_TEXTURE_2D, Texture[3])
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps	(GL_TEXTURE_2D, 3, Text4.width, Text4.height, GL_RGB, GL_UNSIGNED_BYTE, Text4.pixels)


	'
	' Create 5th MipMapped Texture
	'

	glGenTextures		(1, Varptr Texture[4])									' Create a Texture

	glBindTexture		(GL_TEXTURE_2D, Texture[4])
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps	(GL_TEXTURE_2D, 3, Text5.width, Text5.height, GL_RGB, GL_UNSIGNED_BYTE, Text5.pixels)

	'
	' Create 6th MipMapped Texture
	'
	glGenTextures		(1, Varptr Texture[5])									' Create a Texture

	glBindTexture		(GL_TEXTURE_2D, Texture[5])
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	gluBuild2DMipmaps	(GL_TEXTURE_2D, 3, Text6.width, Text6.height, GL_RGB, GL_UNSIGNED_BYTE, Text6.pixels)

End Function


Thanks for your help, it's much appreciated. How cool Is OpenGL in BMAX! :)

THUMBZ! :)