Qbasicnews.com

Full Version: Graphics question - (about loading bmp's)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do you load a 24-bit .bmp file in an array, so you can use it with the qbgfx4qb lib's put command??

And is it possible to create an high-res game using that methot??
Loading a bitmap is a lot easier using plain SDL instead of the qbgfx4fb library - it's ok to use both in the same program. Here's an example.

If you're really sure you want to use qbgfx4fb's put instead I can show you how to do it that way too. But it won't be as easy because you'll have to load the bitmap manually (just like in QB).

This code is untested, but should work:
Code:
'$include: "qbgfx4fb.bi"

declare sub loadBitmap (byval x%, byval y%, filename$)

screenEx 800, 600, 32  ' High resolution, 32 bit color

loadBitmap 10, 10, "filename.bmp"

Flip ' Make sure it shows up on the screen

end

sub loadBitmap (byval x%, byval y%, filename$)

   dim video as SDL_Surface ptr
   dim bitmap as SDL_Surface ptr
   dim rect as SDL_Rect

   ' SDL can load the bitmap for you:
   bitmap = SDL_LoadBMP("filename.bmp")

   video = SDL_GetVideoSurface

   rect.x = x
   rect.y = y
   ' This is SDL's equivalent for PUT:
   SDL_BlitSurface bitmap, 0, video, varptr(rect)

   SDL_FreeSurface bitmap

end sub
I tried compiling the program posted above. But I don't get it running.
Thats because SDL_LoadBMP isnt included in the BI files.
Yeah, turns out SDL_LoadBMP is a macro not a function.

Anyway, here's an updated version that does work:
Code:
'$include: "qbgfx4fb.bi"

declare function SDL_RWFromFile cdecl alias "SDL_RWFromFile" _
   (byval filename as string, byval fileMode as string) as uinteger

declare function SDL_LoadBMP_RW cdecl alias "SDL_LoadBMP_RW" _
   (byval src as uinteger, byval freesrc as integer) as SDL_Surface ptr

declare sub loadBitmap (byval x%, byval y%, filename$)

screenEx 800, 600, 32  ' High resolution, 32 bit color

loadBitmap 10, 10, "filename.bmp"

Flip ' Make sure it shows up on the screen

do: SDL_Delay 50: loop until len(Inkey$)

end

sub loadBitmap (byval x%, byval y%, filename$)

   dim video as SDL_Surface ptr
   dim bitmap as SDL_Surface ptr
   dim rect as SDL_Rect

   ' SDL can load the bitmap for you:
   bitmap = SDL_LoadBMP_RW(SDL_RWFromFile(filename$, "rb"), 1)

   video = SDL_GetVideoSurface

   rect.x = x
   rect.y = y
   ' This is SDL's equivalent for PUT:
   SDL_BlitSurface bitmap, 0, video, varptr(rect)

   SDL_FreeSurface bitmap

end sub
oh ya Crono the SDL_rect type isn't defined correctly in sdlvedio.bi. well unless there a new pakage update with the correction at freebasic.net that i haven't seen yet site seem down for me but my isp is gay.

if your getting waked results check the sdl_rect type an make shure the first two a x and y defined Short and h and w are defined Ushort
Quote:I tried compiling the program posted above. But I don't get it running.

Try compiling this:

Code:
' SDL Sample
'   Loads an image onto the screen in a 640 by 480 window. The
'   image is specified using the command line.

' $Include: "sdl\sdl.bi"
Option Explicit   ' Makes FBC require variables to be declared if used

Declare Function SDL_RWFromFile CDecl Alias "SDL_RWFromFile" _
   ( ByVal filename As String, ByVal fileMode As String) As UInteger

Declare Function SDL_LoadBMP_RW CDecl Alias "SDL_LoadBMP_RW" _
   ( ByVal source As UInteger, ByVal freesource As Integer ) As SDL_Surface Ptr

' Start SDL
Dim result As Byte
result = SDL_Init( SDL_INIT_VIDEO )
If result <> 0 Then
   End 1
End If

' Load the image that will be shown
Dim image As SDL_Surface Ptr ' SDL_Surface pointer
If Len( Command$ ) = 0 Then
   Print "Specify an image to load."
   End 2
End If
' SDL_LoadBMP is a macro
image = SDL_LoadBMP_RW( SDL_RWFromFile( Command$, "rb" ), 1 )
If image = 0 Then
   Print "Unable to load image."
   End 3
End If

' Set up the screen resolution
Dim screen As SDL_Surface Ptr
screen = SDL_SetVideoMode( 640, 480, 32, SDL_DOUBLEBUF) ' For fullscreen: SDL_DOUBLEBUF or SDL_FULLSCREEN
If screen = 0 Then
   SDL_Quit
   End 1
End If

' Blit the image onto the screen
Call SDL_BlitSurface( image, 0, screen, 0 )

' Main loop
Dim exitprogram As Byte
Dim event as SDL_Event
While exitprogram = 0
   ' Check for events
   While ( SDL_PollEvent( @event ) )
      Select Case event.type
         ' Check for a close event (usually SDL_QUIT but BASIC is not case sensitive so it was changed to this)
         Case SDL_EXIT:
            exitprogram = 1
      End Select
   WEnd
WEnd
I Still can't compile Sterlings one. It says:

Code:
fake: undifined reference to 'fbc_screenEx@16'
fake: undifined reference to 'fbc_GfxFlip@0'

The code Frobozz posted worked. So I trie working with that one.

Thanks a bunch to all who spend efford in helping me!!!