Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using SDL to use a Bitmap from memory.
#11
I'm still getting a "Fatal Signal" error on the line where it's GETing the filesize. I can't figure out why, as it's getting a valid number, and I don't see what's causing the harm.

You suuuuuuure it would'nt be easier to just translate the variable?
Reply
#12
Hah. Fuck me. I told you to change the wrong line last time. Argh.


Well, I changed it to completely get rid of the integer pointer there. Please try the original code (I edited it.)
Reply
#13
Ok, now the SDL_Surface "temp" is returning zero, despite the fact that the "buffer" varaible, and "filesize" variable, and the resulting rw value being input into the statement contain actual values.

I really appreciate your help, but do you think you could just tell me how to get my buffer array, and turn it into the data type that SDL_RWFromMem is looking for, so that I can see how that works out? From what I can tell so far, that's really the only step left that's required for getting this to work correctly. =]
Reply
#14
Nope, sorry. I have no idea how the code works; I only translated it from the equivalent c. If the code doesn't work I don't know what to tell you, sorry. x_x
Reply
#15
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.
Reply
#16
At this point, I have very bloated working code that uses a different handle for each image.

Thanks for this help, when I can get back to coding this weekend I will try to modify it. PM me if you wish to see the image loading code.
Screwing with your reality since 1998.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)