Texture Problems with Nehe Lesson 6

BlitzMax Forums/BlitzMax OpenGL Programming/Texture Problems with Nehe Lesson 6

Evening All.

Just been going through those excellent Nehe Open GL tutorial lessons. And I'm having a spot of bother with lesson 6. All the previous tuts I've done upto now worked fine.

This however is doing me in alittle. as nothing is being displayed. I wondered if there were any slight differences between the beta max version of OpenGL?

And also could anyone who has done the Nehe lessons, please correct and point me in the right direction. I dont want another different method of textured quads, as I am trying so hard to stick with the Nehe stuff.

'-----------------------
' Nehe Open GL Lesson 6
'
' Textured Quads
'-----------------------

Strict

Const XRES=640
Const YRES=480
Const RRES=16

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

Global TextureImage
Global xrot:Float
Global yrot:Float
Global zrot:Float

InitOpenGL()


While Not KeyHit( KEY_ESCAPE ) Or MouseHit( 1 )
	
	RenderOpenGL()

bglSwapBuffers
Wend


Function InitOpenGL()

	LoadGLTextures	()							
	
	glEnable		(GL_TEXTURE_2D)						'Enable Texture Mapping ( New )

	glShadeModel	(GL_SMOOTH)							'Enable Smooth Shading
	
	glClearColor	(0.0, 0.0, 0.0, 0.5)					'Black Background
	glClearDepth	(1.0)								'Depth Buffer Setup
	
	glEnable		(GL_DEPTH_TEST)						'Enables Depth Testing
	glDepthFunc	(GL_LEQUAL)							'The Type Of Depth Testing To Do
	glHint		(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)	'Really Nice Perspective Calculations
	
End Function


Function RenderOpenGL()

	glClear		(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)			
	glLoadIdentity	()	
	
	glTranslatef	(0.0,0.0,-5.0)							'Move Into The Screen 5 Units

	glRotatef		(xrot,1.0,0.0,0.0)						'Rotate On The X Axis
	glRotatef		(yrot,0.0,1.0,0.0)						'Rotate On The Y Axis
	glRotatef		(zrot,0.0,0.0,1.0)						'Rotate On The Z Axis

	glBindTexture(GL_TEXTURE_2D, TextureImage)				'Select Our Texture
	
	
	glBegin(GL_QUADS)
		
		'
		' Front Face
		'
		glTexCoord2f(0.0, 0.0);	glVertex3f(-1.0, -1.0, 1.0)	'Bottom Left Of The Texture And Quad
		glTexCoord2f(1.0, 0.0);	glVertex3f( 1.0, -1.0, 1.0)	'Bottom Right Of The Texture And Quad
		glTexCoord2f(1.0, 1.0);	glVertex3f( 1.0,  1.0, 1.0)	'Top Right Of The Texture And Quad
		glTexCoord2f(0.0, 1.0);	glVertex3f(-1.0,  1.0, 1.0)	'Top Left Of The Texture And Quad
		
		
		'
		' Back Face
		'
		glTexCoord2f(1.0, 0.0);	glVertex3f(-1.0, -1.0, -1.0)	'Bottom Right Of The Texture And Quad
		glTexCoord2f(1.0, 1.0); 	glVertex3f(-1.0,  1.0, -1.0)	'Top Right Of The Texture And Quad
		glTexCoord2f(0.0, 1.0); 	glVertex3f( 1.0,  1.0, -1.0)	'Top Left Of The Texture And Quad
		glTexCoord2f(0.0, 0.0);	glVertex3f( 1.0, -1.0, -1.0)	'Bottom Left Of The Texture And Quad

		'
		' Top Face.
		'
		glTexCoord2f(0.0, 1.0);	glVertex3f(-1.0,  1.0, -1.0)	'Top Left Of The Texture And Quad
		glTexCoord2f(0.0, 0.0);	glVertex3f(-1.0,  1.0,  1.0)	'Bottom Left Of The Texture And Quad
		glTexCoord2f(1.0, 0.0);	glVertex3f( 1.0,  1.0,  1.0)	'Bottom Right Of The Texture And Quad
		glTexCoord2f(1.0, 1.0);	glVertex3f( 1.0,  1.0, -1.0)	'Top Right Of The Texture And Quad
		
		'
		' Bottom Face
		'
		glTexCoord2f(1.0, 1.0);	glVertex3f(-1.0, -1.0, -1.0)	'Top Right Of The Texture And Quad
		glTexCoord2f(0.0, 1.0);	glVertex3f( 1.0, -1.0, -1.0)	'Top Left Of The Texture And Quad
		glTexCoord2f(0.0, 0.0);	glVertex3f( 1.0, -1.0,  1.0)	'Bottom Left Of The Texture And Quad
		glTexCoord2f(1.0, 0.0);	glVertex3f(-1.0, -1.0,  1.0)	'Bottom Right Of The Texture And Quad
		
		'
		' Right face.
		'
		glTexCoord2f(1.0, 0.0);	glVertex3f( 1.0, -1.0, -1.0)	'Bottom Right Of The Texture And Quad
		glTexCoord2f(1.0, 1.0);	glVertex3f( 1.0,  1.0, -1.0)	'Top Right Of The Texture And Quad
		glTexCoord2f(0.0, 1.0);	glVertex3f( 1.0,  1.0,  1.0)	'Top Left Of The Texture And Quad
		glTexCoord2f(0.0, 0.0);	glVertex3f( 1.0, -1.0,  1.0)	'Bottom Left Of The Texture And Quad
		
		'
		' Left Face.
		'
		glTexCoord2f(0.0, 0.0);	glVertex3f(-1.0, -1.0, -1.0)	'Bottom Left Of The Texture And Quad
		glTexCoord2f(1.0, 0.0);	glVertex3f(-1.0, -1.0,  1.0)	'Bottom Right Of The Texture And Quad
		glTexCoord2f(1.0, 1.0);	glVertex3f(-1.0,  1.0,  1.0)	'Top Right Of The Texture And Quad
		glTexCoord2f(0.0, 1.0);	glVertex3f(-1.0,  1.0, -1.0)	'Top Left Of The Texture And Quad
	
	glEnd()
	
	
	xrot:+0.3											'X Axis Rotation
	yrot:+0.2											'Y Axis Rotation
	zrot:+0.4											'Z Axis Rotation


End Function



Function LoadGLTextures()
	
	Local Texture:TPixmap	=LoadPixmap		( "media\texture.png" )
	TextureImage			=bglTexFromPixmap	( Texture )

	glBindTexture GL_TEXTURE_2D, TextureImage
	
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)	' Linear Filtering
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)	' Linear Filtering

End Function




Thanks kindly,
.:|Thumbs|:.

Dont worry about it folks, I've spotted an omission from the tutorial lesson and it's all of the perspective and viewport setups. It now works fine. Worth noteing for others taking a look through the NEHE lessons.

Yes, if you don't set a viewport and a perspective view, he don't work. :)