Flickering (/blink) bug effect on opentk
Hello, I have this framebuffer class to render the game engine's scene and consequently copy it to an SDL texture (to be able to implement it within the UI that is made in SDL2), but I am experiencing flickering effects when adding a game object to the scene
58 Replies
Consequently, I also have the SpriteBatch2D class, which is responsible for rendering sprites.
my run method
If someone can identify the error and help me fix the bug, I would be grateful.
@CityPop
You unbind the framebuffer before reading the texture, not sure if that causes issues but maybe rearrange it?
Is the flickering every other frame or is it random?
every other frame
lemme try it
Every other frame sounds something to do with with swap buffers function but i could be wrong
most flickers in sdl mostly just the wrong ordering
It didn’t work, I’ve already tried several things, I’ve tried refactoring the rendering system, I’ve literally tried everything, I asked the AI for help and it didn’t work
the order should be :
Clear
Render
Render present
//Your timestep condition and repeat
did you fix this already? did you check the order?
yeah, i checked the order, this still has the same error, not just for animated sprites, but also for static sprites
GitHub
Severe flickering and unstable rendering on animated sprites using ...
📄 Description I am experiencing serious rendering issues in the Luna game engine involving animated sprites and the viewport system. Observed Problems Animated sprites constantly flicker / blink Sp...
GitHub
GitHub - iarleyyyxz/Luna2D: Free and open source 2D Game Engine in C#
Free and open source 2D Game Engine in C#. Contribute to iarleyyyxz/Luna2D development by creating an account on GitHub.
that either render order issue or vsync.. the latter is very unlikely
try toing around with the order, nothing much to do really other than debugging on your end
also .. why GL.Finish there tho?
i removed it
I already tried several orders, before I made a mistake, I was rendering two scenes (one in the run() method, and another in the UIViewport class) I removed it, it turned out that wasn’t the reason
you're using matrices or vector for transform?
how's your camera setup?
Vector
not set up yet
just the screen coordinates for now
remove that UI render or whatever it is and just plain texture2d to debug things
ok
I really wanted to try creating a UI in SDL, but these integration errors are driving me crazy
UI is a massive task just so you know, I personally if its just a fun project I'd just use Imgui.net instead
this is mine I made it two years ago iirc


thats SDL + ogl + Imgui.net
sdl for the window?
yes... the scene editor there Imgui.net
I really don't like imgui...
so just passing the framebuffer of OGL to imgui then back to sdl... quite simple actually
I feel trapped
oh gotcha
you have the source code?
the default is ugly, but you can do customs.. and there are tons of addons for that you can use on github
Can you name a few for me?
there are couple of challenges, the most painful one is the Text rendering
SDL_TTF is just bad and basic
for sure
your other options is to use FreeType binding
I prefer the latter, SDL_TTF is just garbage :when:
lol
or do it the easy way, use imgui.net
I will take it into consideration
.?
?
its private for now, I'm not working on it any further yet, proably later in the future
oh okay
where can i find these addons?
just google it :when: .. or just make your own custom in imgui.net, not that hard
The problem with ImGui is the issue of rendering custom icons.
hows is that a problem? as you can see in the gif above posted, I used heck tons of icons
i mean like this:

you can do that in imgui no issue
I don't know how to do it, I've always looked into it and it seems pretty complicated
.
well, everything is complicated when making your own game engine :when:
lol
fair
strip out anything unnecessary here, and just render plain texture2d and see how it goes
i think i find the error...
I think I'm calculating the frame size of the spritesheets wrong... the image moves as if it were rendering the entire spritesheet on the screen, and then moves until it renders the last frame
there you go
happy debbugging :blobthumbsup:
a little tip, use renderTarget so you're rendering all your texture2ds into a single texture instead of individual rendering like that, so you can have dynamic viewport for cases when detecting different screen resolutions
but thats for later, now just fix your current bug
i have a spritebatch for render multiple sprites in one draw call
spritebatch is unrelated to rendertexture
Okay, I had misunderstood
I’m going to refactor spritesheet class
bth how you spritebatch? sounds to me you're using SDL 2d api instead of OGL here
yeah very likely, if so, your ogl is useless there
mind you sdl 2d api cant do z-order by default
no no, im just using sdl to window and input
yeah my question was how you spritebatch, show me the snippet if you'r like
or just the ogl shader
you mean the shader class or the shader src?
I'm not using SDL 2D for game rendering. SDL is only used for window creation, input and (for now) the editor UI.
All sprites are rendered with OpenGL through my own Renderer2D / QuadRenderer system.
I currently have a simple SpriteBatch that queues sprites and draws them via OpenGL, but it's still being improved (no full batching or instancing yet).
The flickering issue was caused by mixing SDL_Renderer with OpenGL and some UV problems in my SpriteSheet system.
I'm now moving to a fully OpenGL-based pipeline to avoid these conflicts and implement proper batching and z-order.
ah nice then 👍
is it okay?
GL.TexImage2D(
TextureTarget.Texture2D,
0,
PixelInternalFormat.Rgba,
image.Width,
image.Height,
0,
PixelFormat.Rgba,
PixelType.UnsignedByte,
image.Data
);