OpenGL + images

BlitzPlus Forums/BlitzPlus Programming/OpenGL + images

ghislain(Posted 2004) [#1]
I'm trying to display an image with OpenGL. I haven't seen any example around so i changed some code from the examples given by Peter Scheutz [see below].
In BlitzDirect_BP_Example_04.bb there is a function which creates a texture. I used this routine but instead of freeing the bank i returned the bank-handle so i can send the address to glDrawPixels. But I keep on getting error messages when i call this.
Does anyone have any ideas what is wrong with the code?

img = glLoadImage ("...")	; during initGL
glDrawimage (x, y, img)		; during drawing routine


function glLoadImage(filename$)
	; code just a copy from BlitzDirect_BP_Example_04.bb
	; by Peter Scheutz

	Local texture1 = LoadImage(filename$)
	If texture1 = 0 Then Return
	
	w=ImageWidth(texture1)
	h=ImageHeight(texture1)

	texBuf=ImageBuffer( texture1 )
	
	pixels=CreateBank(w*h*3) ; GL_RGB
	
	pitch=w*3
	i=BankSize(pixels)-pitch
	LockBuffer texBuf
		
	For y=0 To h-1
	For x=0 To w-1	
		pix=ReadPixelFast(x,y,texBuf)
		r=(pix And $FF0000) Shr 16
		g=(pix And $FF00) Shr 8	
		b=pix And $FF
		
		PokeByte pixels,i,r
		PokeByte pixels,i+1,g		
		PokeByte pixels,i+2,b					
		i=i+3
	Next 
		i=i-pitch*2
	Next 
	UnlockBuffer texBuf
	FreeImage texture1
	
	return pixels
end function

function glDrawImage (x,y, img)
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
	glRasterPos2i (x, y)
	glDrawPixels (width, heigt, GL_RGB, GL_UNSIGNED_BYTE, img)
	; width & height should be specified..
end function


Thanks!


Drago(Posted 2004) [#2]
Which error message are you getting?

the way I do 2d images, is to use a textured quad, this lets me rotate, blend, mask, scale etc.


ghislain(Posted 2004) [#3]
I get a windows error message: "blitz cc has encountered a problem and needs to be closed.."
Maybe it is just as easy to make a quad. There are no side-effects? It took some time in Blitz3d to get 'pixel-perfect' sprites..
But then, seems to me, the code should above should still work?


JoshK(Posted 2004) [#4]
Any time you pass a Blitz bank to a DLL, the userlib has to have a pointer* variable, like this:
glDrawPixels(nwidth%,height%,nformat%,ntype%,npixel*)

This is a common error in the opengl32.decls file, and you should watch out for it as you start using more commands.


ghislain(Posted 2004) [#5]
That seems to be the cause!
Thanks!