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!
|