texture trouble :/

BlitzMax Forums/BlitzMax OpenGL Programming/texture trouble :/

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

This is a simple example - hope it helps even though you've probably solved it by now... :P
Strict

Incbin "ending.png"


' Variables

Global ..
	theTexture:Int

Local ..
	thePixmap:TPixmap, ..
	time:Int = 0, ..
	timeDiff:Int = 0, ..
	timeSecond:Int = 0, ..
	fps:Int = 0, shownFPS:Int = 0


' First set up openGL

bglCreateContext(800, 600, 32, 0, BGL_BACKBUFFER|BGL_DEPTHBUFFER)
glClearColor(0, 0, 0, 64)
glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH)
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)

glMatrixMode(GL_PROJECTION)
glLoadIdentity

gluPerspective(45.0, 4.0 / 3.0, 1.0, 100.0)

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
glEnable(GL_TEXTURE_2D)
glMatrixMode(GL_MODELVIEW)


' Load the texture

thePixmap = LoadPixmap("incbin::ending.png")
theTexture = bglTexFromPixmap(thePixmap)
glBindTexture(GL_TEXTURE_2D, theTexture)


' The game loop

Repeat
	timeDiff = MilliSecs() - time
	time = MilliSecs()
	timeSecond :+ timeDiff
	If timeSecond > 1000.0 Then
		timeSecond :Mod 1000.0
		shownFPS = fps
		fps = 0
	EndIf
	fps :+ 1
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

	DrawEnding
	
	bglDrawText("FPS: " + shownFPS, 0, 0) 

	glFlush

	bglSwapBuffers
	
	FlushMem
Until KeyHit(KEY_ESCAPE)


Function DrawEnding()
	glBindTexture(GL_TEXTURE_2D, theTexture)

	glEnable(GL_TEXTURE_2D)

	glLoadIdentity
	
	glTranslatef(0.0, 0.0, -5.0)
	glScalef(4.0, 4.0, 0.0)
			
	glBegin(GL_POLYGON)
		glNormal3f(  0.0, 0.0, 1.0)
		glTexCoord3f(0.0, 1.0, 0.0) 
		glVertex3f(  -0.5, -0.5,  0.0)
		glTexCoord3f(1.0, 1.0, 0.0)
		glVertex3f(   0.5, -0.5,  0.0)
		glTexCoord3f(1.0, 0.0, 0.0)
		glVertex3f(   0.5,  0.5,  0.0)
		glTexCoord3f(0.0, 0.0, 0.0) 
		glVertex3f(  -0.5,  0.5,  0.0)
		glColor4f(1.0, 1.0, 1.0, 1.0)
	glEnd
	glDisable(GL_TEXTURE_2D)
	
	glPopMatrix
End Function