polygon is not drawn

SGDK only sub forum

Moderator: Stef

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

polygon is not drawn

Post by alko » Sun Jun 26, 2022 5:35 pm

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
Image

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

Re: polygon is not drawn

Post by Stef » Sun Jun 26, 2022 7:51 pm

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 :)

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Fri Jul 01, 2022 8:47 pm

thanx

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

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

Re: polygon is not drawn

Post by Stef » Mon Jul 04, 2022 8:26 am

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.

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Mon Jul 04, 2022 12:33 pm

default resolution 256х160. how to change it for speed ?
I need fast clear\swap buffer how is that possible
Image

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

Re: polygon is not drawn

Post by Stef » Wed Jul 06, 2022 8:39 am

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)

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Sun Jul 10, 2022 11:42 pm

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
Image

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Sun Jul 10, 2022 11:48 pm

Image
Image

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

Re: polygon is not drawn

Post by Stef » Mon Jul 11, 2022 7:55 am

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..

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Tue Jul 12, 2022 8:55 pm

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
Image

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

Re: polygon is not drawn

Post by Stef » Wed Jul 13, 2022 7:31 am

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 :)

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Wed Jul 13, 2022 10:54 am

on Blastem visible similar artifact too

Image
Image

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Thu Jul 14, 2022 2:49 pm

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?
Image

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Thu Jul 14, 2022 4:06 pm

I set:
IMAGE cabin "cabin.png" FAST
artifact is gone :roll:
Image

alko
Very interested
Posts: 171
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: polygon is not drawn

Post by alko » Fri Jul 15, 2022 12:45 pm

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);
 
Image

Post Reply