Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CRT and set FPS bugs
#1
Hi!

I found 2 bugs in Tilengine.

The first one is about the CRT filter. When I set a bitmap as background and a tilemap as layer, I have a strange glitch with the CRT enabled (nothing special if disabled) :
[Image: c074ae287b032a05044bcb97fe177df1-Full.webp?w=1308&h=863]

Here is the code :
Code:
#include "Tilengine.h"
#include <SDL2/SDL.h>

int main(void) {
    TLN_Tilemap foreground;

    TLN_Init (400, 240, 1, 0, 0);

    TLN_Bitmap bm = TLN_LoadBitmap("elis.bmp");
    TLN_Tilemap tm = TLN_LoadTilemap("assets/sonic/Sonic_md_fg1.tmx", NULL);
    TLN_SetBGBitmap(bm);
    TLN_SetLayerTilemap(0, tm);
    TLN_CreateWindow (NULL, CWF_S3|CWF_NOVSYNC);
    int fps = 60;
    TLN_SetTargetFps(10);
    int average_fps = 0;
    while (TLN_ProcessWindow()) {
        /* adjust game logic pacing to target fps */
        uint32_t begin = SDL_GetTicks();
TLN_DrawFrame(0);
        uint32_t end = SDL_GetTicks();
        uint32_t delta = end - begin;
        printf("FPS = %f\n", 1000.0 / (float)delta);
    }

    TLN_Deinit ();
}


The second is when I change the FPS, seems the animations of the flowers are always at the same speed. Is that normal? Shouldn't it be slower (or faster if above screen refresh rate)?

Thanks for your answer!
Reply
#2
Hi!

I've just returned from holidays and seen your post. Let me check it and answer soon.

The CRT issue happens when the front layer is scrolling, or just standing still?

I may need the "elis.bmp" image you're using as background, maybe this is something related to palette/color depth/transparent pixels that cannot reproduce with any random image I use for testing.

Regards,
Reply
#3
(04-02-2024, 04:20 AM)megamarc Wrote: Hi!

I've just returned from holidays and seen your post. Let me check it and answer soon.

The CRT issue happens when the front layer is scrolling, or just standing still?

I may need the "elis.bmp" image you're using as background, maybe this is something related to palette/color depth/transparent pixels that cannot reproduce with any random image I use for testing.

Regards,

Hi, here is the ZIP of my project. Thanks for your help!


Attached Files
.zip   tilengineTest.zip (Size: 776.7 KB / Downloads: 1)
Reply
#4
Hi,

I've found the explanation for both issues:

CRT filter

The problem here is that the background bitmap is smaller than the framebuffer. When thete's no background bitmap, each frame is cleared with the default background color. A background bitmap is supposed to cover the entire framebuffer, so the background color clear is disabled. The CRT effect applies a slight blurring, and because the rightmost part of the framebuffer isn't being cleared between frames, a feedback effect appears.

If you make the layer scroll, you'll see how the right part outside the background bitmap gets smeared even if you don't enable the CRT effect.

Just make sure that your background bitmap is at least as big as the framebuffer.

FPS throttling

The animation data inside the tmx file is expressed as delay between frames, in milliseconds. No matter how you play with fps, the delay between frames is respected, that's why you see the flowers always running at the same speed.

I've tweaked a bit your example.
  • To get an estimate of fps is not enough to sample just one frame, it's better to average some. So here I average each 500 ms (twice per second) to get a better estimate.
  • I've made the front layer scroll at constant speed of 1 pixel/frame
Now if you play with the TLN_SetTargetFps()function, you'll see how the average fps output on the console approximates the value you set, and that the layer scrolling speed varies, the higher the fps, the faster it scrolls.

Hope to have answered your questions!


Code:
#include "Tilengine.h"

int main(void) {
    TLN_Init (400, 240, 1, 0, 0);
    TLN_Bitmap bm = TLN_LoadBitmap("elis.bmp");
    TLN_Tilemap tm = TLN_LoadTilemap("assets/sonic/Sonic_md_fg1.tmx", NULL);
    TLN_SetBGBitmap(bm);
    TLN_SetLayerTilemap(0, tm);
    TLN_CreateWindow (NULL, CWF_S3|CWF_NOVSYNC);
    TLN_SetTargetFps(200);

    uint32_t time = 0;
    uint32_t numframes = 0;
    uint32_t t0 = TLN_GetTicks();
    int x = 0;
    while (TLN_ProcessWindow()) {
        /* adjust game logic pacing to target fps */
        uint32_t begin = TLN_GetTicks();
        TLN_DrawFrame(0);
        uint32_t end = TLN_GetTicks();
        time += (end - begin);
        numframes += 1;
       
        /* autoscroll */
        x += 1;
        TLN_SetLayerPosition(0, x, 0);
       
        /* average each 500 ms */
        if (end - t0 >= 500) {
            printf("FPS = %.02f\n", (1000.0 * numframes) / (float)time);
            t0 = end;
            time = numframes = 0;
        }
    }

    TLN_Deinit ();
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)