• Welcome to Dark Bit Factory & Gravity.
 

Emulate BLOAD from memory?

Started by nzo, June 19, 2011

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nzo

I'd like to use GL2D to make a game and perhaps some demos, but I don't really want to use external gfx files.
As GL2D uses BLOAD internally to load BMP files, I'd like to be able to load my gfx from memory, much like the BMP2RAW method used with PTC.

Is there a way to do this?

Jim

Which gl2d library are you using nzo?
There's probably no way to get it to use something other than bload, but there will be a way manually to set the texture you want, but it might be a bit fiddly.
The gl functions themselves always work from ram.

Jim
Challenge Trophies Won:

nzo

The FB.IMAGE version.
The functions included will appear to work with a simulated BLOAD, but BLOAD does a bunch of "other" stuff automatically which I don't know.
The header info can be preset (bit depth etc.)

The main part which needs looking at:

        dim as FB.IMAGE ptr image = imagecreate(w,h)
        bload filename, image


cheers
Ray

Rbz

Take a look at imageinfo, I think you can use it to do this.
http://www.freebasic.net/wiki/KeyPgImageinfo
Challenge Trophies Won:

nzo

I was already using imageinfo to get that (from an already BLOAD'd image)
What I would like to do, is to refer to existing data (compiled in) and set up the image structure - kind of like imageinfo in reverse..

Clyde

#5
you could also do away with bload, and use rbz's very handy bmp2raw and bin2bas to store your media as files made up as bytes. Reduces the overall exe size too.
added: - please ignore me, I miss read your post Dude.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

relsoft

Quote from: nzo on June 19, 2011
I'd like to use GL2D to make a game and perhaps some demos, but I don't really want to use external gfx files.
As GL2D uses BLOAD internally to load BMP files, I'd like to be able to load my gfx from memory, much like the BMP2RAW method used with PTC.

Is there a way to do this?

Glowlines actually use an array in memory to draw glowlines. have a converter here that converts a standard fbgfx image into an fb array. just a fw lines of code actually. Post it later when get home.

I'm posting this on my old mobile WM5, so sory for the brevity.

opera mini roxxors!
Challenge Trophies Won:

relsoft

Can't find my own converter(maybe on another laptop)  but this should do the job (Not mine):



''these are  the constants you can adjust:
Const IMAGE_WIDTH = 16, IMAGE_HEIGHT = 16, IMAGE_BITDEPTH = 8
Const BMP_NAME = "my_image.bmp"
Const BAS_NAME = "my_image_array.bas"
Const ARRAY_DECL = "dim shared", ARRAY_NAME = "image_array"

''don't change anything you don't understand below this line
#include "crt.bi"
#include "fbgfx.bi"
Using fb
#if defined(__FB_WIN32__) Or defined(__FB_DOS__)
#define NEWLINE !"\r\n"
#else
#define NEWLINE !"\n"
#endif

Function array_def( array() As Uinteger ) As String
   
    Dim As String ret = "{"
   
    For i As Integer = Lbound(array) To Ubound(array)
       
        If i Mod 6 = 0 Then ret &= (!" _" NEWLINE "   ")
        ret &= " &H" & Hex(array(i), 8)
        If i < Ubound(array) Then ret &= "," Else ret &= " }"
       
    Next
   
    Return ret
   
End Function

screenres 1, 1, IMAGE_BITDEPTH, , GFX_NULL

Dim As Any Ptr p
Dim As Uinteger image_array(), pal(0 To 255)
Dim As Integer imagesize, arraysize

p = imagecreate(IMAGE_WIDTH, IMAGE_HEIGHT, RGB(0, 0, 0) )
Bload BMP_NAME, p

imageinfo( p, , , , , , imagesize )

If imagesize > 0 Then
   
    arraysize = (imagesize + ((1 Shl 2) - 1)) Shr 2
    Redim image_array( 0 To arraysize - 1 )
   
    memcpy( @image_array(0), p, imagesize )
   
Else
    End
end If

If IMAGE_BITDEPTH <= 8 Then
   
    Dim As Uinteger r, g, b
    For i As Integer = 0 To 255
        Palette Get i, r, g, b
        pal(i) = RGB(r, g, b)
    Next
End If

imagedestroy p
Screen 0

Open BAS_NAME For Output As #1
   
    Print #1, "const IMAGE_WIDTH = " & IMAGE_WIDTH & ", IMAGE_HEIGHT = " & IMAGE_HEIGHT & ", IMAGE_BITDEPTH = " & IMAGE_BITDEPTH
   
    Print #1, ARRAY_DECL & " as uinteger " & ARRAY_NAME;
    Print #1, "(0 to " & (arraysize - 1) & ") => " & array_def(image_array())
    Print #1,
   
    If IMAGE_BITDEPTH <= 8 Then
        Print #1, "dim as uinteger pal(0 to 255) => " & array_def(pal())
        Print #1,
    End If
   
    Print #1, "screenres IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_BITDEPTH"
   
    If IMAGE_BITDEPTH <= 8 Then
        Print #1, "for i as integer = 0 to 255"
        Print #1, "    palette i, pal(i) shr 16 and 255, pal(i) shr 8 and 255, pal(i) and 255"
        Print #1, "next"
    End If
   
    Print #1, "put (0, 0), " & ARRAY_NAME & ", pset"
    Print #1, "sleep"
   
Close #1





BTW, this is the updated version:

http://rel.betterwebber.com/MyProgs/gl2d_alphatest.rar

Challenge Trophies Won:

Storm Trooper

#8
very handy, thanks for sharing the codes.

what would it look like for bytes / byte ptrs, &h red, &h grn, &h blu for raw and palete. thanks

Jim

Quote''don't change anything you don't understand below this line
lol!  I think I'm going to add that to the top of all the source files at work.  >:D

Jim
Challenge Trophies Won: