Page 1 of 2

polygon is not drawn

Posted: Sun Jun 26, 2022 5:35 pm
by alko
i'm trying to draw a quad

Code: Select all

 Vect2D_s16 * 	pts;

    u16 palette[16];

int main()
{
    MEM_free(pts);
    palette[0] = RGB24_TO_VDPCOLOR(0x000000);
    palette[1] = RGB24_TO_VDPCOLOR(0x0000FF);
    palette[2] = RGB24_TO_VDPCOLOR(0x00FF00);
    palette[3] = RGB24_TO_VDPCOLOR(0xFF0000);
    palette[4] = RGB24_TO_VDPCOLOR(0x00FFFF);
    palette[5] = RGB24_TO_VDPCOLOR(0xFFFF00);
    palette[6] = RGB24_TO_VDPCOLOR(0xFF00FF);
    palette[7] = RGB24_TO_VDPCOLOR(0xFFFFFF);
    palette[8] = RGB24_TO_VDPCOLOR(0x404040);
    palette[9] = RGB24_TO_VDPCOLOR(0x000080);
    palette[10] = RGB24_TO_VDPCOLOR(0x008000);
    palette[11] = RGB24_TO_VDPCOLOR(0x800000);
    palette[12] = RGB24_TO_VDPCOLOR(0x008080);
    palette[13] = RGB24_TO_VDPCOLOR(0x808000);
    palette[14] = RGB24_TO_VDPCOLOR(0x800080);
    palette[15] = RGB24_TO_VDPCOLOR(0x808080);
    VDP_setPalette(PAL1, palette);
    VDP_setScreenWidth320();
    SYS_enableInts();
    VDP_clearPlane(BG_A, TRUE);
    BMP_init(TRUE, BG_A, PAL1, FALSE);
    BMP_setBufferCopy(TRUE);
    while(TRUE)
    {
        handleInput();

            pts[0].x =10;
            pts[0].y =10;
            pts[1].x =40;
            pts[1].y = 10;
            pts[2].x =40;
            pts[2].y = 40;
            pts[3].x =10;
            pts[3].y = 40;

BMP_drawPolygon	(pts,3,5);
BMP_flip(FALSE);
    }
    return 0;
}
but...
Image

Re: polygon is not drawn

Posted: Sun Jun 26, 2022 7:51 pm
by Stef
You don't initialize pts correctly.

By default variable are not initialized in C so you can't do

Code: Select all

    MEM_free(pts);
without having initialized pts first.
Normally you should have done:

Code: Select all

pts = NULL;
Then you should try to release pts only if pts != NULL so there is no reason to try to release on init.

Another problem here is that finally you don't allocate memory for pts:

Code: Select all

ptr = MEM_alloc(sizeof(Vect2D_s16) * numberOfPoint);
I think that a simpler way of doing is just using static allocation here so you won't have to worry about that allocation stuff.
Just declare pts as:

Code: Select all

Vect2D_s16 pts[MAX_POINTS];
A last point is that polygon rendering use 8 bit color (so you can create neat mesh filling), so here just 0x55 for the color instead of 5 :)

Re: polygon is not drawn

Posted: Fri Jul 01, 2022 8:47 pm
by alko
thanx

is it possible to draw polygon not only clockwise but also counterclockwise points ?

Re: polygon is not drawn

Posted: Mon Jul 04, 2022 8:26 am
by Stef
Unfortunately no. First because it makes the polygon processing easier (no need to test about clockwise direction) and also because that is the way to do back culling when drawing 3D transformed objects in general.
So yeah, when defining 2D polygons, you need to take care of that.

Re: polygon is not drawn

Posted: Mon Jul 04, 2022 12:33 pm
by alko
default resolution 256х160. how to change it for speed ?
I need fast clear\swap buffer how is that possible

Re: polygon is not drawn

Posted: Wed Jul 06, 2022 8:39 am
by Stef
Resolution is fixed, that is a limitation of the bitmap engine, mean that you're limited to 20 FPS max on NTSC systems and 30 FPS on PAL systems.
Resolution was flexible in priors implementations (very old SGDK version) but code was more convoluted and not as fast (width as power of 2 is a big win here)

Re: polygon is not drawn

Posted: Sun Jul 10, 2022 11:42 pm
by alko
I want put image over bitmap_render layer

Code: Select all

  VDP_setPalette(PAL1, palette);
    VDP_setScreenWidth320();

    VDP_clearPlane(BG_A, TRUE);
    VDP_clearPlane(BG_B, TRUE);
    BMP_init(TRUE, BG_A, PAL1, FALSE);
    BMP_setBufferCopy(TRUE);

 //JOY_setEventHandler(joyEvent);
    SYS_enableInts();

   u16 ind = TILE_USERINDEX;


    VDP_setPalette(PAL0, cabin.palette->data);
    VDP_drawImageEx(BG_B, &cabin, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind),0, 0, FALSE, TRUE);
    ind += cabin.tileset->numTile;
glitching on PLANE B, as if bitmap-blitting over two planes
Image

Re: polygon is not drawn

Posted: Sun Jul 10, 2022 11:48 pm
by alko
Image

Re: polygon is not drawn

Posted: Mon Jul 11, 2022 7:55 am
by Stef
The BMP mode uses a lot of main ram but also lot of VRAM so first you need to be sure you have enough VRAM to actually store your image.
Bitmap start to allocate its rendering buffer to TILE_USER_INDEX so you will overwrite it when you draw your image.
You need to initialize ind with BMP_FB1_END_TILE_INDEX instead (which is where free tile space start).
Also to make priority between planes easier, i suggest you to use BG_B for BMP mode (as you want it in the background) and BG_A for your image.
You can do the reverse but in that case you need to force BG_A in low priority and BG_B in high priority which is not as convenient..

Re: polygon is not drawn

Posted: Tue Jul 12, 2022 8:55 pm
by alko
I use BMP_flip(1) double-buffered render and I can't understand why this artifact appeared in Kega Fussion
Image

In Gens is ok
Image

VRAM with a margin (also, how to clear fonts for more free memory? )

Image

Re: polygon is not drawn

Posted: Wed Jul 13, 2022 7:31 am
by Stef
Kega isn't accurate, nor Gens is. You should test with BlastEm to see if you still have the same problem.
About the font, you can just "overwrite" it with your own tiles if you don't use it :)

Re: polygon is not drawn

Posted: Wed Jul 13, 2022 10:54 am
by alko
on Blastem visible similar artifact too

Image

Re: polygon is not drawn

Posted: Thu Jul 14, 2022 2:49 pm
by alko
when I change in gfx.res

Code: Select all

IMAGE cabin "cabin.png" -1
to

Code: Select all

IMAGE cabin "cabin.png" 0
The artifact has changed position

Image

maybe rescomp doesn't work properly?

Re: polygon is not drawn

Posted: Thu Jul 14, 2022 4:06 pm
by alko
I set:
IMAGE cabin "cabin.png" FAST
artifact is gone :roll:

Re: polygon is not drawn

Posted: Fri Jul 15, 2022 12:45 pm
by alko
Now Line is not drawn :lol:

Code: Select all

 Line *line;
line->pt1.x =0;
line->pt1.y =0;

line->pt2.x =100;
line->pt2.y =100;

line->col=10;

BMP_drawLine(line);