I started screwing with SDL tonight, figured I'd stop back and help ya now that I'm becoming familiar with things:
Code:
Function SDL_LoadBMPFromArray( array() as ubyte ) As SDL_Surface Ptr
Dim As SDL_RWops Ptr rw = SDL_RWFromMem( @array( lbound( array ) ), ubound( array ) - lbound( array ) + 1 )
Dim As SDL_Surface Ptr temp = SDL_LoadBMP_RW( rw, 1 )
If ( temp = 0 ) Then
Print "Unable to load bitmap: " & *SDL_GetError()
Sleep
End 1
End If
''//Convert the image To optimal display format
Dim As SDL_Surface Ptr image = SDL_DisplayFormat( temp )
''//Free the temporary surface
SDL_FreeSurface( temp )
''//Return our loaded image
Return image
End Function
there's the code you wanted to convert an array into a surface ptr (hopefully). I still actually don't know why the original code didn't work unless... are/were you using OPTION BYVAL ?
anarky, that examples you showed *is* overwriting mem. either you have to do calculations (you're writing 0, then 1, a picture takes up more than one byte of mem), or use an array of ptrs instead. the issue here is you need to know the width/height of the bmp, so you can allocate the required space. example:
Code:
dim shared as ANY PTR image( 69 )
/' GLOBALS '/
Function GetBMPSizes( byref fileName As String, byref w as integer, byref h as integer ) As integer
Dim As Integer fileHandle = FreeFile
If Open( fileName, For Binary Access Read, As fileHandle ) = 0 Then
Dim buff As uShort
Get #fileHandle, , buff
If buff <> 19778 Then
Close #fileHandle
Return 0
End If
Dim bmpwidth As uInteger, bmpheight As uInteger
Get #fileHandle, &H12 + 1, w
Get #fileHandle, &H16 + 1, h
Close #fileHandle
Return -1
End If
return 0
End Function
sub LoadBMP ( byref filename as string, byval BMPHandle as integer)
dim as integer w, h
if GetBMPSizes( filename, w, h ) then
image( BMPHandle ) = imagecreate( w, h )
BLOAD filename, image( BMPHandle )
end if
end sub
sub DrawBMP ( byval BMPHandle as integer, byval locx as integer, byval locy as integer )
PUT (locx,locy), image(BMPHandle)
end sub
LoadBMP "d:\data\image\bftm.bmp", 1
LoadBMP "d:\data\image\blah.bmp", 2
DrawBMP 1,0,0
DrawBMP 2,20,20
untested, should work.
EDIT:
oh and btw, remember to imagedestroy() the indexes in the array when you don't need the images anymore.