Author Topic: Freebasic Images Library  (Read 12199 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Freebasic Images Library
« on: December 15, 2008 »
A lot of people post here having grabbed a copy of freebasic and they decide to do some pixel pushing with Tinyptc..

Well, we know what they say about all good intentions.
Actually it can be quite a daunting task if you have not done any software rendering before.

The first thing you need to make sure of is that you have the newest version of tinyptc.
Get it from our resources section and ask on the forum if you don't know how to install it (it's just copying 3 files, don't worry!).

The new version of tinyptc has extra compatibility and functionality, rbz keeps working on it to improve it. Make sure you keep it up to date if you want to use these frameworks.

Most small intros have thier graphics resourced as part of the executable file.
So how the hell do you do it?

You will need to have some utilities, rbz wrote two great programs;

bmp2raw
bin2bas

They are included in this archive and also available from our resources section.

bmp2raw first of all takes a picture (windows 8 bit bitmap) and splits it into two parts.
The first part is the colour palette.
The second part is the raw data.

We need a picture to work on.

Our example is called screen.bmp

Screen.bmp was created in microsoft paint as a 24 bit windows bitmap.
the whole picture is 512  X 172 pixels.

This was then converted into an 8 bit picture with irfanview.

Irfanview is a free image conversion program.
Get it here;

http://www.irfanview.com/

To convert a 24 bit image to 8 bit, load irfanview.
Load your image
go to the image tab in the top menu
go to decrease colour depth
select 256 colours
then save the file as screen.bmp

Simple as that.
You should not try and use 24 bit pictures, it's possible (and fairly easy) to use them but we're sticking to 256 colours here because that's what rbz's utilities are designed for.


to convert the picture into the right format for our program...
Save the 256 colour bitmap as:
screen.bmp
make sure that you have a copy of bin2bas and bmp2raw in that folder too


go to the start button
click run
type:
cmd
into the box
then use cd (whatever) to get into the folder containing screen.bmp
then type;
bmp2raw screen.bmp
then after a few seconds the pic will be converted into 2 files.
Then type;
bin2bas screen.bmp.pal screenpal.bas
bin2bas screen.bmp.raw screenraw.bas

That's the picture converted.


You can now use the files ;
screenpal.bas
screenraw.bas

in your programs.

You should look on this the same way you would if you were cutting out cookies ;)

The source I included loads the picture and provides you with a comand that lets you cut out any part of that picture and display it anywhere on your screen!

So you can put logos, fonts whatever you like on that screen and draw them with ease.

Please do enjoy it, and don't feel bad about asking any questions, they should be posted in here.

« Last Edit: September 11, 2009 by Shockwave »
Shockwave ^ Codigos
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Freebasic Images Library
« Reply #1 on: December 15, 2008 »
A huge thank you for this Shockwave! As you know I do sometimes struggle with certain bits and bobs!
This will help me and lots of others out too! Very kind of you to do this!
Regards
DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2688
  • Karma: 483
    • View Profile
    • http://www.rbraz.com/
Re: Freebasic Images Library
« Reply #2 on: December 15, 2008 »
Reading this tutorial I got an idea, how about integrating an image loader for tinyptc_ext ?
It's not too much code to add, and it could make newcomers live a bit more easy.

What do you guys think about it ?
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #3 on: December 16, 2008 »
It should give the option of resourcing the file into the exe or having it seperate but I think it would give newbies a huge help.

Not everyone wants to go through the pain of converting images and writing thier own bitmap drawing routines etc.

Great idea Rbz :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Freebasic Images Library
« Reply #4 on: December 16, 2008 »
Very good Framework for Newbies  :)

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 612
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: Freebasic Images Library
« Reply #5 on: December 16, 2008 »
Ah very cool :) k++ shockie, that'll definitely be helpful (for newbies or not :P)
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #6 on: December 16, 2008 »
Cheers for the Karma :D
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikerboy

  • Amiga 1200
  • ****
  • Posts: 349
  • Karma: 12
    • View Profile
Re: Freebasic Images Library
« Reply #7 on: December 16, 2008 »
a great hand of help indeed !  :cheers:  :D :cheers:

EDIT: just loaded in FBIde "images.bas" to study the example and see how it works, however everytime i try to compile a code containing OPTION STATIC and OPTION EXPLICIT , i get this -->

Quote
error 135: Only valid in -lang deprecated or fblite or qb, found 'OPTION' in 'OPTION STATIC'

error 135: Only valid in -lang deprecated or fblite or qb, found 'OPTION' in 'OPTION EXPLICIT'

is there something my freebasic installation is missing? anyone knows how to fix this?

thanx guys :)
« Last Edit: December 21, 2008 by va!n »


Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Freebasic Images Library
« Reply #8 on: December 17, 2008 »
@Bikerboy - Not sure if this is right but I just removed them! The routines still work fine! It is something to do with an older version of FB.

DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #9 on: December 17, 2008 »
You won't hurt anything using the fix Drewpee suggested there, it is indeed because you have a newer version of Freebasic than I do.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikerboy

  • Amiga 1200
  • ****
  • Posts: 349
  • Karma: 12
    • View Profile
Re: Freebasic Images Library
« Reply #10 on: December 17, 2008 »
allready tried that and got more errors, i even did it with other code examples with the same results .... what version do you guys have? i think i need to downgrade, this new version is for the trashcan.
« Last Edit: December 21, 2008 by va!n »


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #11 on: December 17, 2008 »
What errors did you have?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikerboy

  • Amiga 1200
  • ****
  • Posts: 349
  • Karma: 12
    • View Profile
Re: Freebasic Images Library
« Reply #12 on: December 17, 2008 »
Code: [Select]
Compiler output:
C:/Documents and Settings/bikerboy/Desktop/images2/screenpal.bas(2) error 4: Duplicated definition, found 'screen' in 'dim shared screen.bmp.pal(0 to 767) as ubyte = { _'
C:/Documents and Settings/bikerboy/Desktop/images2/screenraw.bas(2) error 4: Duplicated definition, found 'screen' in 'dim shared screen.bmp.raw(0 to 88063) as ubyte = { _'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(36) error 135: Only valid in -lang deprecated or fblite or qb, found 'OPTION' in 'OPTION STATIC'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(37) error 135: Only valid in -lang deprecated or fblite or qb, found 'OPTION' in 'OPTION EXPLICIT'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(125) error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'DIM L'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(149) error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'DIM L'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(210) error 7: Expected ')', found '.' in 'IMG_COLOURS(L)=RGB(screen.bmp.pal(RR),screen.bmp.pal(GG),screen.bmp.pal(BB))'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(220) error 3: Expected End-of-Line, found '.' in 'IMG_RAW(L)=screen.bmp.raw(L)'

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc:   FreeBASIC Compiler - Version 0.20.0 (08-10-2008) for win32 (target:win32)
OS:    Windows XP (build 2600, Service Pack 3)


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #13 on: December 17, 2008 »
It seems like your version of freebasic doesn't like the variable names of the arrays.

screen.bmp.pal
screen.bmp.raw

So to start off with, please load the following files into your IDE;

screenpal.bas
screenraw.bas

and the main program file too, whatever that is called.

go to the first line of screenpal.bas

change
screen.bmp.pal
to;
screenbmppal

Save screenpal.bas

go to the first line of screenraw.bas

change
screen.bmp.raw
to;
screenbmpraw

Save screenraw.bas

Then in the main program file replace every
screen.bmp.pal
with
screenbmppal
and every
screen.bmp.raw
with
screenbmpraw


Then comment out;

option static
option explicit

Then try compiling it, you might get other errors, if so, please post them.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikerboy

  • Amiga 1200
  • ****
  • Posts: 349
  • Karma: 12
    • View Profile
Re: Freebasic Images Library
« Reply #14 on: December 17, 2008 »
changed everything you said and --->

Code: [Select]
Compiler output:
C:/Documents and Settings/bikerboy/Desktop/images2/screenpal.bas(2) error 4: Duplicated definition, found 'screen' in 'dim shared screen.bmppal(0 to 767) as ubyte = { _'
C:/Documents and Settings/bikerboy/Desktop/images2/screenraw.bas(2) error 4: Duplicated definition, found 'screen' in 'dim shared screen.bmpraw(0 to 88063) as ubyte = { _'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(125) error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'DIM L'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(149) error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'DIM L'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(210) error 7: Expected ')', found '.' in 'IMG_COLOURS(L)=RGB(screen.bmppal(RR),screen.bmppal(GG),screen.bmppal(BB))'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(220) error 3: Expected End-of-Line, found '.' in 'IMG_RAW(L)=screen.bmpraw(L)'
« Last Edit: December 21, 2008 by va!n »


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #15 on: December 17, 2008 »
Well theres less errors but you still need to change;

screen.bmppal

to

screenbmppal

and

screen.bmpraw

to

screenbmpraw


Everywhere you see them.
It seems like Freebasic 2.0 doesnt like those full stops in array names
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikerboy

  • Amiga 1200
  • ****
  • Posts: 349
  • Karma: 12
    • View Profile
Re: Freebasic Images Library
« Reply #16 on: December 17, 2008 »
okies replaced everything and now got only 2 errors

Code: [Select]
Compiler output:
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(125) error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'DIM L'
C:/Documents and Settings/bikerboy/Desktop/images2/FBIDETEMP.bas(149) error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'DIM L'
« Last Edit: December 21, 2008 by va!n »


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17373
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic Images Library
« Reply #17 on: December 17, 2008 »
At line 125 replace
DIM L
with
DIM AS INTEGER L

At Line 149 do the same

:)

It will work after that. (fingers crossed)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikerboy

  • Amiga 1200
  • ****
  • Posts: 349
  • Karma: 12
    • View Profile
Re: Freebasic Images Library
« Reply #18 on: December 17, 2008 »
changed it at line 149 too , and it works ! :carrot:

thanx man, this was an opportunity to learn how to fix specific errors :D

i'll go now and try to fix the oracle one
« Last Edit: December 21, 2008 by va!n »


Offline matthew

  • C= 64
  • **
  • Posts: 27
  • Karma: 2
    • View Profile
    • My Wikispace
Re: Freebasic Images Library
« Reply #19 on: December 17, 2008 »
You don't have to change the code in order to get it to compile with the newest version of FreeBASIC.

If you're using FBIde, you just need to add -lang deprecated to your Compiler command & all the examples written in earlier versions of FreeBASIC should compile fine without any errors.