Need help with graphics commands

New to FreeBASIC? Post your questions here.
Imortis
Moderator
Posts: 1744
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Need help with graphics commands

Postby Imortis » Jan 07, 2006 23:15

I have written some code to pull letters out of a bsave'd file. I try to load that file directly into an ImageCreate'd variable, but it doesn't seem to work properally. Here is the code:

Code: Select all

dim letters as any ptr
dim letter(4*(8*8)+4) as byte
dim a as string
Screen 18
letters = ImageCreate(752,8)
bload "font.bsv",letters
cls
input a
cls
select case asc(a)
    case 32
    case 33
        get letters, (0,0)-(8,8), letter
        put(0,0), letter
    case else
        get letters, (((asc(a)-33)*8)+1,0)-(((asc(a)-33)*8)+8,8), letter
        put(0,0), letter
End Select
sleep
ImageDestroy(letters)


Any help world be apreciated. If it is needed, I will load up the font.bsv file later.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 08, 2006 1:05

Probably a dumb question, but you have your bit depth right?
Last edited by anonymous1337 on Jan 08, 2006 1:19, edited 3 times in total.
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Postby mambazo » Jan 08, 2006 1:07

is it chucking out at error at you? or is it just doing something unexpected?
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Postby mambazo » Jan 08, 2006 1:16

ah, a bsaved image file already has dimension data in it.

try declaring letters as

DIM AS UBYTE letters(4+(752*8))

then when you BLOAD

try

BLOAD "font.bsv", @letters
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 08, 2006 1:22

Code: Select all

get letters, (0,0)-(8,8), letter
This line of code is wrong. The 8's should be 7's. Your array is 0 - 7 not 0 - 8. Changing this gets the first case working just fine. The second still confuses me.
Last edited by anonymous1337 on Jan 08, 2006 1:33, edited 2 times in total.
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Postby mambazo » Jan 08, 2006 1:30

could also be to do with the fact that Screen 18 is 8-bit

so this is declaring an array much larger than is needed:-

Code: Select all

dim letter(4*(8*8)+4) as byte


should be:

Code: Select all

DIM AS UBYTE letter(4+(8*8))
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 08, 2006 1:33

Got it working! Sorry if I changed a couple lines of code. Mainly just the screen to work with my 24-bit image and I like screen 20 too.

Code: Select all

Screen 20, 24
dim letters as ubyte ptr
dim letter(4*(8*8)+4) as byte
dim a as string
letters = ImageCreate(752,8)
bload "font.bmp",letters
cls
input a
cls
select case asc(a)
    case 32
    case 33
        get letters, (0,0)-(7,7), letter
        put(0,0), letter
    case else
        get letters, (((asc(a)-33)*8),0)-(((asc(a)-33)*8)+7,7), letter
        put(0,0), letter
End Select
sleep
ImageDestroy(letters)
Last edited by anonymous1337 on Jan 08, 2006 1:35, edited 2 times in total.
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Postby mambazo » Jan 08, 2006 1:33

Try this:-

Code: Select all

DIM AS UBYTE letter(4+(8*8))
DIM AS UBYTE letters(4+(752*8))
DIM AS STRING a

SCREEN 18

BLOAD "font.bsv",@letters(0)

CLS
INPUT a
CLS
SELECT CASE ASC(a)
    CASE 32
    CASE 33
        GET letters, (0,0)-(7,7), letter(0)
        PUT(0,0), letter(0)
    CASE ELSE
        GET letters(0), (((ASC(a)-33)*8)+1,0)-(((ASC(a)-33)*8)+8,8), letter(0)
        PUT(0,0), letter(0)
END SELECT
SLEEP
Last edited by mambazo on Jan 08, 2006 1:53, edited 1 time in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 08, 2006 1:34

Hey! i got it working first ^_^

EDIT: But mabazo's has less code ;_;
Last edited by anonymous1337 on Jan 08, 2006 1:37, edited 1 time in total.
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Postby mambazo » Jan 08, 2006 1:36

true true... :)

(but mine has less code, so there :P )
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 08, 2006 1:43

Oh hey. Is it alright if I steal this code to help make a font routine for my game? This is really useful. All I need now is multiple letter support. There's already font threads round here. Wonder why I never checked em out.
Imortis
Moderator
Posts: 1744
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Postby Imortis » Jan 09, 2006 2:20

Thanks for all the help, guys. I tried all kinds of things and the error it was tossing out was that is would not display anything from the bsaved file. I will try this code out shortly and report to you whether or not it has success.

@anonymous1337: Knock yourself out. That's what this was going to be anyway. Just put my name in a comment or some such.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 13, 2006 6:51

Multiple letters and a crap text box...

Code: Select all

dim text_Box_x = 10
dim text_box_y = 10
dim text_box_width = (8 * 14)
dim text_box_Height = 90
Screen 20, 24
'dim letters as any ptr
dim letters as ubyte ptr
dim letter(4*(8*8)+4) as byte
dim put_x as integer
put_x = text_box_x + 1
dim Put_y as integer
put_y = text_box_y + 1
dim a as string
letters = ImageCreate(752,8)
bload "font.bmp",letters
input a
cls
line (0, 0)-(1023, 767), rgb(255, 255, 255), bf
line (text_box_x, text_Box_Y)-(text_Box_x + (text_box_width - 1), text_Box_y + (text_box_Height - 1)), rgb(255, 0, 0), b
for i = 1 to len(a)
select case asc(a, i)
    case 32
    case 33
        get letters, (0,0)-(7,7), letter
        put(0,0), letter
    case else
        get letters, (((asc(a, i)-33)*8),0)-(((asc(a, i)-33)*8)+7,7), letter
        put(put_x,put_y), letter, alpha, 255
End Select
Put_x += 8
if put_x > (text_box_x + text_box_width) then
    put_y += 8
    put_x = 11
end if
sleep 30 'For a nice DELAY! It looks like a moving convo.
next
sleep
ImageDestroy(letters)
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario
Contact:

Postby axipher » Jan 13, 2006 14:09

This is nice, could someone maybe upload the actual font file please???
Imortis
Moderator
Posts: 1744
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Postby Imortis » Jan 13, 2006 16:05

I need to rewrite mine, becuase it was apperently not done correctly the first time. I will fix it and post a modified routine to use it later.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 7 guests