Noob Question about GLTexFromPixmap

BlitzMax Forums/BlitzMax OpenGL Programming/Noob Question about GLTexFromPixmap

Main Question:

Function LoadGlTextures()
	Local PointeurImg:Byte Ptr
	Local TexWidth
	Local TexHeight
	tex01:TPixmap=LoadPixmap("tile1.bmp")
	TexWidth=tex01.width
	TexHeight=tex01.Height
	PointeurImg=PixmapPixelPtr(tex01,0,0)
	pp=0
	For y=TexHeight-1 To 0 Step -1
		For x=0 To TexWidth-1
			Checkimage[y,x,0]=PointeurImg[pp]
			Checkimage[y,x,1]=PointeurImg[pp+1]
			Checkimage[y,x,2]=PointeurImg[pp+2]
			Checkimage[y,x,3]=100
			pp=pp+3
		Next
	Next
	tex01=Null
	glPixelStorei(GL_UNPACK_ALIGNMENT,1)
	glGenTextures(1, VarPtr Texname)
	glBindTexture(GL_TEXTURE_2D, Texname)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, Checkimage)
End Function

Above is the LoadGLTexture code from Nehe 6. This is the simplest code I have to load a texture. (Its sitting in a zip file with all the nehe, but tonyg said somewhere that it was the relevent one)

I want to just replace "everything" that can be replaced with
GLTexFromPixmap(LoadPixmap("tile1.bmp"))
But everywhere I can think to do it, I get a Int/int Ptr Problem.

Question Two:

Whats the "Smallest" code that nehe6 could really be? That is do I really need (For example), glClearColor(0.0, 0.0, 0.0, 0.0). I assume lots of Nehe6 is there as an educational method, but If I just went for default, what could I cut it down to?

Question Three:

Ok this might sound like a dumb question, but do I really have to re-allocate the verticies each frame
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

Cannot I do this just once in init, and then rotate the thing each frame?

Cavat:

I dont understand GL, and as I have continualy failed to understand GL. I have picked my programing level, and It is not in the depths of either DX or GL. I can see the technical skill needed, and I simply havent gained such skills. So if you could explain what I need to do, please assume I know nothing about GL, and try to have as few gl commands as possible.

Errrr... I said what?

Somewhere in the depths of forum search you, (well I think it was you), are talking about Textured polyies, and say that this code is relevent NeHe tut. If Im miss-quoting you, then sorry. But when I then looked at the NeHe Tuts, you seemed right.

below is a better way of doing things:

Global ScreenWidth:Int=800
Global ScreenHeight:Int=600
Global ScreenDepth:Int=32

Global xrot:Float=0
Global yrot:Float=0
Global zrot:Float=0

Global pixmap:TPixmap, texture%
Global geo%

GLGraphics(ScreenWidth,ScreenHeight,ScreenDepth,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER) '| BGL_FULLSCREEN

InitGl()
While Not KeyHit( KEY_ESCAPE )
	nehe6()
	glColor3f(1.0,1.0,1.0)
	'Framecounter--------------------------------------------
	Framecounter_counter=Framecounter_counter+1
	If Framecounter_time=0 Then Framecounter_time=MilliSecs()
	If Framecounter_time+1001 <MilliSecs() Then
		Framecounter_framerate=Framecounter_counter
		Framecounter_counter=0
		Framecounter_time=MilliSecs()
	EndIf

	'--------------------------------------------------------

	Flip
Wend
End

Function InitGl()

	LoadGlTextures()
	glClearColor(0.0, 0.0, 0.0, 0.0)
	glClearDepth 1.0
	glDepthFunc(GL_LESS)
	glEnable(GL_DEPTH_TEST)
	glShadeModel(GL_SMOOTH)
	glViewport(0,0,ScreenWidth,ScreenHeight)
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluPerspective(45.0,Float(ScreenWidth)/Float(ScreenHeight),1.0,100.0)
	glMatrixMode(GL_MODELVIEW)
	
End Function

Function LoadGlTextures()

	pixmap = LoadPixmap("data\NeHe.bmp")
	texture = GLTexFromPixmap(pixmap)
	
	geo = glGenLists ( 1 )
	
	glNewList ( geo, GL_COMPILE )
	
	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
	
	glEndList ()
	
End Function

Function nehe6()

	glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
   	glEnable(GL_TEXTURE_2D)
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
	glBindTexture GL_TEXTURE_2D,texture
	
	glLoadIdentity
	glTranslatef 0.0,0.0,-5.0
	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

	glCallList ( geo )

	xrot = xrot + 0.3                     ' X Axis Rotation
	yrot = yrot + 0.2                     ' Y Axis Rotation
	zrot = zrot + 0.4                     ' Z Axis Rotation
	glDisable(GL_TEXTURE_2D)
	
End Function


And even corrects the colour errors.

GLTexFromPixmap(LoadPixmap("tile1.bmp"))

This gives you a GLTexture name and thus you do not need to generate the texture you only need to bind it.

Whats the "Smallest" code that nehe6 could really be? That is do I really need (For example), glClearColor(0.0, 0.0, 0.0, 0.0). I assume lots of Nehe6 is there as an educational method, but If I just went for default, what could I cut it down to?

No it defualts to black.

Ok this might sound like a dumb question, but do I really have to re-allocate the verticies each frame

If you dont intend on change vertex positions then you can just use display list - they are realy simple.

Edit: You should be able to figure out how todo texture poly's from this.