SGDK questions: palettes... BMP... Collision, sprites

SGDK only sub forum

Moderator: Stef

Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

SGDK questions: palettes... BMP... Collision, sprites

Post by Mills »

Well, now i want some imformation about palettes,
I have this code, it does not load the palettes... "Incompatible pointer in VDP_setpalette"

Code: Select all

    u16 palette[64];
    u16 ind;
 
    VDP_setScreenWidth320();

    ind = TILE_USERINDEX;
   //Plane A
    VDP_drawImageEx(APLAN, &plane_A, TILE_ATTR_FULL(PAL0,0,0,0,ind),0,0,0,1);
    ind += plane_A.tileset->numTile;

   //Plane B
    VDP_drawImageEx(BPLAN, &plane_B, TILE_ATTR_FULL(PAL1,0,0,0,ind),0,0,0,1);
    ind += plane_B.tileset->numTile;

   
   VDP_setPalette(0,plane_A.palette);
   VDP_setPalette(1,plane_B.palette);	
Then i'd like to know how the built in tool that converts the images (from the .res files), gets the palettes, and how they are organized, i'd like to have arrays for every palette like this one:

Code: Select all

	

const u16 bkg_palette[16] = {
   0x0000,0x0424,0x0026,0x0420,0x0248,0x0ECA,0x0846,
   0x0446,0x048A,0x0864,0x0A88,0x0888,0x0664,0x0C86,0x0668,0x0EEE,
};	
I want to make several sprites using the same palette, each sprite is a separate image with 4 different colors. How do i draw them so that they use the same palette?.

BMP get pixel and set pixel... This code does nothing at all...
At 2,2 pixels are white, at 30,30 pixels are black, so this should paint a white pixel in the middle of the black zone.. It does not.. and i don't know how to load the bmp palette...

Code: Select all

	

u16 color = 0x0000;

int main(){

 VDP_drawBitmap(VDP_PLAN_A,&bkg,0,0);

color = BMP_GETPIXEL(2,2);
BMP_SETPIXEL(30,30,color);

}
Thanks
Last edited by Mills on Thu Apr 24, 2014 10:15 pm, edited 1 time in total.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SGDK questions: palettes... BMP...

Post by Stef »

For the VDP_setPalette(..) method you have to pass it the data pointer :

Code: Select all

VDP_setPalette(1, plane_B.palette->data);
I know that is something i definitely need to improve to make it consistent with other advanced loading methods.
Then i'd like to know how the built in tool that converts the images (from the .res files), gets the palettes, and how they are organized, i'd like to have arrays for every palette like this one:

Code: Select all

const u16 bkg_palette[16] = {
	0x0000,0x0424,0x0026,0x0420,0x0248,0x0ECA,0x0846,
	0x0446,0x048A,0x0864,0x0A88,0x0888,0x0664,0x0C86,0x0668,0x0EEE,
};
I want to make several sprites using the same palette, each sprite is a separate image with 4 different colors. How do i draw them so that they use the same palette?.
If you want to share the same palette between different sprites then it may be a good idea to store these sprites in the same image.
Actually rescomp does not change anything in the palette, it directly uses the palette stored by the image software (except it adapt color for genesis color). Gimp is one of these software which allow you to modify the color organization in palette if you want.
BMP get pixel and set pixel... This code does nothing at all...
At 2,2 pixels are white, at 30,30 pixels are black, so this should paint a white pixel in the middle of the black zone.. It does not.. and i don't know how to load the bmp palette...
The Bitmap mode is something special, it aims to simulate a bitmap buffer for the Megadrive by using linear buffer in main memory.
You need to use it only if you want to do sort of "generated" GFX, you have an example about of to use it in the "cube" sample.
The Bimap mode only uses 1 palette and you can define which palette to use when you initialize the Bitmap engine :

Code: Select all

BMP_init(..)
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Re: SGDK questions: palettes... BMP...

Post by Mills »

Stef wrote: If you want to share the same palette between different sprites then it may be a good idea to store these sprites in the same image.
Then, how do i define 2 different sprites from one image?

For example, this image, i want the rocket and the smoke, to be different sprites, the rocket has 2 animations, and the smoke has also 2 animations but it is smaller.

Image
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Then that might be a problem ;)
Can you specifically specify the palette on your image software so you can share same palette for each image ?
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Post by Mills »

Stef wrote:Then that might be a problem ;)
Can you specifically specify the palette on your image software so you can share same palette for each image ?
That would solve it, i use gimp. I'll test the idea.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

If you use Gimp there is no problem, i'm using it myself and hopefully i can workout the palette very easily :)
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Post by Mills »

Stef wrote:If you use Gimp there is no problem, i'm using it myself and hopefully i can workout the palette very easily :)
I tried to set the same palette to some sprites, it nearly got the correct colors, bot not all..

I got the best results by creating a big image with all sprites, indexing it to 16 colors, and then saving every sprite to one separate file, starting with the big image. Even this way, some colors (one or two) were changed.

By the way, how many sprites (8x8 tiles) can i fit in vram?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Mills wrote:
Stef wrote:If you use Gimp there is no problem, i'm using it myself and hopefully i can workout the palette very easily :)
I tried to set the same palette to some sprites, it nearly got the correct colors, bot not all..

I got the best results by creating a big image with all sprites, indexing it to 16 colors, and then saving every sprite to one separate file, starting with the big image. Even this way, some colors (one or two) were changed.

By the way, how many sprites (8x8 tiles) can i fit in vram?
You can export the current palette with Gimp and then load it later to force to work it on your image. If you don't do that, Gimp will optimize colors and remove the useless ones i guess.
Also about the tiles number, basically in SGDK you have TILE_USERLENGTH define which give you the maximum number of tile yo can load up. Normally when you load tile, you have to use the :
TILE_USERINDEX and TILE_USERMAXINDEX to get the "start" and "end" index position where you can load tiles in VRAM.
Tile space change depending you tilemap plan configuration, in SGDK i assume that all tilemap and tables are in the high part of the VRAM and that window is always the first one so all calculations are made from its position. If you set the window tilemap position to 0 then you don't have any space for tile so that is something to avoid really !
By default i believe you have space for about 1200 tiles in VRAM.
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Post by Mills »

Having trouble with big sprites

In this actual image from the emulator you can see: the "green" sprites can move, but they are not animated. The "orange" sprites can't move, and they are animated. The purple gadget seems to be the problem, maybe it is just too big...

Image

So did i reach the limit? :)

Another question, Is there any way to make colision masks? Like loading a simple image in ram, just with two or three colors, and read the color of the pixel at any position? I don't know how to make the ball bounce. :(
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Normally sprites should be used only for moving objects, if they don't move at all you can try to only update part of the background image.
About collision box, you can ask rescomp to generate some simple ones with your sprites objects (you can look in the rescomp.txt file to see how enable them in the SPRITE definition). The thing is that you still have your code to do collision detection. For background collision, you have to do it from your own as there is not any "tools" for that currently. You can define your own collision structures (list of collision boxes, line intersection...), i believe image would be overkill in term of space !
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Post by Mills »

Stef wrote:Normally sprites should be used only for moving objects, if they don't move at all you can try to only update part of the background image.
About collision box, you can ask rescomp to generate some simple ones with your sprites objects (you can look in the rescomp.txt file to see how enable them in the SPRITE definition). The thing is that you still have your code to do collision detection. For background collision, you have to do it from your own as there is not any "tools" for that currently. You can define your own collision structures (list of collision boxes, line intersection...), i believe image would be overkill in term of space !
So i could define the limits of the track with lines, and then i can detect if a sprite got near one of the lines, right?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

For instance yeah, but that is more "game logic" stuff and not directly related to SGDK itself as there is no tools for that in SGDK.
But you may find some help easily on Internet, as this site :
http://www.wildbunny.co.uk/blog/2011/12 ... detection/
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Post by Mills »

Stef wrote:For instance yeah, but that is more "game logic" stuff and not directly related to SGDK itself as there is no tools for that in SGDK.
But you may find some help easily on Internet, as this site :
http://www.wildbunny.co.uk/blog/2011/12 ... detection/
Thanks a lot.

I have trouble setting the 4º palette, i can set the first 3, but i can't set the last one:

Code: Select all


    VDP_setPalette(0,planeB.palette->data);
    VDP_setPalette(1,planeA.palette->data);
    VDP_setPalette(2,sprite0.palette->data);
    
    VDP_setPalette(3,sprite1.palette->data); /does not load any palette.


One question about sgdk and the MD/Gen hardware itself.

My game looks like this:

Code: Select all

..
..

int Program = 0; 

int main(){

 while (Program == 0) Scene/hole/menu0 ;  
 
 while (Program == 1) Scene/hole/menu1 ;  
 
 while (Program == 2) Scene/hole/menu2 ;  

 .

 .

 .
}
Every "while" is a level or menu screen selected with a int variable.
How big can the main.c be?, does the console load the whole code in ram?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Actually there is no reason that the 4th palette is not loaded...
Did you checked in an emulator ? By the way, it is a good practice to use constant when you have them just to avoid problems (index offset...). For palette you can use PAL0, PAL1, PAL2 and PAL3 for instance :)
Also don't worry about the size of the code, it is located in ROM do you don't have to worry about this ;)
Mills
Interested
Posts: 34
Joined: Fri Apr 11, 2014 11:09 pm

Post by Mills »

Stef wrote:Actually there is no reason that the 4th palette is not loaded...
Did you checked in an emulator ? By the way, it is a good practice to use constant when you have them just to avoid problems (index offset...). For palette you can use PAL0, PAL1, PAL2 and PAL3 for instance :)
Also don't worry about the size of the code, it is located in ROM do you don't have to worry about this ;)
I'll keep trying :).

Someone told me a rom i created did not work on real MD/GEN, The fusion emulator shows "wrong checksum". Can sgdk add the right checksum without having to use a rom fixer?.
Post Reply