Bennu Game Development

English Forums => Helpdesk => Topic started by: quasist on December 07, 2009, 10:29:32 PM

Title: Graphics question
Post by: quasist on December 07, 2009, 10:29:32 PM
It was fun installing bennu (on Windows XP) and making some simple "hello, 1000 random lines :)" projects for Wiz.
Since It is hard for me to uderstand spanish soucecode examples I have few questions.

As I suppose - when you DRAW_... someting it becomes a process(or something alike) and still presents onwards with it's ID. Am I correct?

How to draw a sprite on screen? Is it possible without putting it to graphics library?
Is it like

int i_gfx[127];
...

i_gfx[0]=Load_Png("gfx/wall00ne.png");

...Function how to draw multiple i_gfx[0] with X and Y on screen?

...unload from memory at shutdown

As I think I will need to make something alike
(idea in C format)
i_image[i_image_count++]=Draw_ ... somehow i_gfx[0] :P

and clear all drawing in i_image array at clearing the screen ?
Title: Re: Graphics question
Post by: Windgate on December 07, 2009, 10:58:04 PM
I can't understand all your question, but let's see:

Every PROCESS has a local variable called graph, if you do graph = load_png ( ... ), the process will show the png.

You need call 1 process for each graph you want to have on screen, it is not possible to have a process having more than 1 graphic.

I hope it help you...
Title: Re: Graphics question
Post by: Drumpi on December 08, 2009, 02:15:19 AM
When you draw something with DRAW_* functions, is not a "process", maybe an item, or class. It returns an ID and you can use it with MOVE_DRAW to move it, or DELETE_DRAW, etc, but is not a process.
A process it's a code, generally with a graphic, with his own properties, located on LOCAL VARIABLES (like X, Y, ANGLE, ALPHA...). You can't rotate a DRAW_* item, or change it form, color or else... but is faster to draw and move (i think, because it not have a code to execute, or lots of variables to check).

And yes, you can load maps without use an FPG. MAP and PNG are maps supported files that you can use alone. They are stored internally in FPG=0, so, you must do
FILE=0;
in every process you want to use it, and assign the ID that LOAD_* returns in GRAPH local variable. I.e:

int my_map, other_map;
my_map=LOAD_PNG("bored.png");
other_map=LOAD_PNG("happy.png);

PROCESS one ()
BEGIN
FILE=0;
GRAPH=my_map;
//rest of code
END
PROCESS two ()
BEGIN
FILE=0;
GRAPH=other_map;
//rest of code
END

I hope it help you ;)
Title: Re: Graphics question
Post by: quasist on December 08, 2009, 04:31:09 AM
Quote from: Drumpi on December 08, 2009, 02:15:19 AM
PROCESS one ()
BEGIN
FILE=0;
GRAPH=my_map;
//rest of code
END
PROCESS two ()
BEGIN
FILE=0;
GRAPH=other_map;
//rest of code
END

I hope it help you ;)
How to create array of processes ? :)
Title: Re: Graphics question
Post by: Drumpi on December 08, 2009, 01:33:45 PM
Uh? a process is like a C function or procedure, but them not finish his execution, they're runing every frame of the program at the same time than others.

By the way, when you call a process, it returns an ID and can store it in an INT array. Something like:

INT my_array[10];
(...)
my_array[0]=one();
my_array[1]=one();
my_array[2]=two();
(...)
Title: Re: Graphics question
Post by: Windgate on December 08, 2009, 01:54:13 PM
Array of processes, I don't know what do you exactly want to do, let's see:

As Drumpi said, if you want to launch 1000 PROCESS one ( ) and keep all process ids on an array you also can do:

GLOBAL
   int array [ 1000 ];

...
FROM x = 0 TO 999;
   array [ x ] = one ( );
END
...


Is this what you want?
Title: Re: Graphics question
Post by: quasist on December 08, 2009, 02:56:28 PM
Is it possible to launch a bunch (~256) processes with unique graph ID(to various PNG-s) from some loop structure?

Like to draw level map in Field of View by tiles.
Title: Re: Graphics question
Post by: Windgate on December 08, 2009, 03:00:41 PM
Definitively, yes, try it xD
Title: Re: Graphics question
Post by: Sandman on December 09, 2009, 10:27:34 AM
Use parameters (http://wiki.bennugd.org/index.php?title=Parameter).

Global
    int array [255];
End

Process Main()
Private
    int i;
    int map[1];
Begin
    map[0] = load_png("file");
    map[1] = load_png("other file");
    array[i] = proc(50,50,map[0]);
    array[i] = proc(150,150,map[1]);

    Repeat
        frame;
    Until(key(_ESC))

    let_me_alone();

OnExit
    unload_map(map[0]);
    unload_map(map[1]);
End

Process proc(int x, int y, int graph)
Begin
    Loop
        frame;
    End
End
...
Title: Re: Graphics question
Post by: quasist on December 10, 2009, 09:52:48 PM
Quote from: Sandman on December 09, 2009, 10:27:34 AM
Use parameters (http://wiki.bennugd.org/index.php?title=Parameter).
Thank you very much! This is exactly I was searching for.  :)
Title: Re: Graphics question
Post by: Windgate on December 11, 2009, 01:00:09 AM
Oh, just fucking parameters, ok, keep on trying, you will see Bennu is like a drug... If you start you won't stop... Any other problem you can report it ;)
Title: Re: Graphics question
Post by: quasist on December 11, 2009, 09:28:48 PM
Works perfect!

Now I have few more ( moddesc was not quite informative :( )

1) How to set transparent color?

2) How to correctly delete process with sprite? So I could alter the sprite on his ID.
Title: Re: Graphics question
Post by: Sandman on December 11, 2009, 11:18:15 PM
1) What do you mean? Do you mean you want to change the transparency of the process' graphic or that you want to change which colour 'is the transparent color'? In the first case, use the local alpha (http://wiki.bennugd.org/index.php?title=Alpha), in the second case, you're out of luck, but you could use 32bit images.

2) Not sure what you mean by this. If you want to unload a map (http://wiki.bennugd.org/index.php?title=Map_unload) that only a specific process uses, you can use OnExit (http://wiki.bennugd.org/index.php?title=OnExit), like in the example I gave you, but in the proc process. To alter the graphic of a process you can change the local variable graph (http://wiki.bennugd.org/index.php?title=Graph).

* Alpha is not documented, but it's a local variable. Ranges from 0 to 255. 0 means fully transparent, 255 means solid.
Title: Re: Graphics question
Post by: Windgate on December 12, 2009, 04:32:31 AM
Sandman said it all...

If you are using 16 bits colour mode, black (RGB = 0,0,0) is transparent, try it.

TIP: If you are using Gimp, Paint.NET, Photoshop, etc. you should always use PNG format on all your graphics.
Title: Re: Graphics question
Post by: quasist on December 12, 2009, 09:31:17 PM
Quote from: Windgate on December 12, 2009, 04:32:31 AM
If you are using 16 bits colour mode, black (RGB = 0,0,0) is transparent, try it.
Didn't work :(
Title: Re: Graphics question
Post by: Windgate on December 13, 2009, 12:29:00 AM
Let's see:

Take ANY sprite, save it as .png, open it with Paint.NET, select magic wand tool and set 0% tolerancy, click on backgrund colour to select it all, key Supr to set it as alpha, save the .png, put it on your fpg or just load it with load_png.

That's all, it MUST work.

PD: set_mode ( ... , ... , 16 , ... );
Title: Re: Graphics question
Post by: quasist on December 13, 2009, 09:21:30 AM
So bennu cannot auto-generate alpha channel?
Title: Re: Graphics question
Post by: Sandman on December 13, 2009, 12:45:15 PM
What would that do?

If you have a 16bit graphic (not the file), the color 0 is transparent. Depending on the file loaded this is NOT the same as black. If the file has an alpha channel, then that is used to make specific parts (the <50% alpha parts) color 0. Black parts (rgb(0,0,0)) do NOT get color 0, but get color 1, which is practically black. When loading files WITHOUT an alpha channel, THEN the black (rgb(0,0,0)) is used to determine transparent parts.

For 32bit, this doesn't matter at all: f you load a 32bit graphic in the 32bit mode, then it's mapped 1-on-1. If you load a 16bit graphic without alpha channel in 32bit mode, it's the same as described above.

Does this clear things up?
Title: Re: Graphics question
Post by: Windgate on December 13, 2009, 06:42:07 PM
Quote from: quasist on December 13, 2009, 09:21:30 AM
So bennu cannot auto-generate alpha channel?

Maybe... I don't know but I always use the magic wand way...
Title: Re: Graphics question
Post by: quasist on December 13, 2009, 10:20:34 PM
Got today my blitting working :). Too bad that bennu requires off-hand tools for alpha carving. But good cause to install photoshop :)
Title: Re: Graphics question
Post by: Windgate on December 14, 2009, 01:12:55 AM
I think it is possible to set a colour as alpha, but sorry, I don't know how to do this... Maybe anyone answer us about this, not me :P
Title: Re: Graphics question
Post by: Drumpi on December 15, 2009, 03:50:05 AM
Bennu, like Fenix, and like DIV game studio (father and grandfather of Bennu) never allow to user to select the transparent colour: in 8 bits mode, the first color of the palette, color 0, is the transparent colour, BUT you can set the RGB asociated to it for working with graphics editors.
In 16 bits mode, color 0 is the only transparent color, as same as 8bits, but you cannot set his RGB because EVERY color in 16 bits has an associated RGB value (defined by his bits: 5,6,5 for R,G,B component).

32 bits mode is new in Bennu, an add an alpha channel: its an 8bits extra information for alpha or transparency (8,8,8,8 for R,G,B,A components).
But be careful with collision function, it takes only color 0 as REAL transparent (pixels that not collide with others graphics).
Title: Re: Graphics question
Post by: quasist on December 31, 2009, 08:52:35 PM
Got evrything to working the way I wanted! :)

Thanks evryone.

Happy new year!