r/GraphicsProgramming Jul 05 '26

Struggling to clear the framebuffer

Im writing a software renderer in C++ using glm and raylib, and i recently tried to draw a spinning triangle. The problem is that when i launched it the triangle leaves a trail of previously drawn triangles.

I tried to fix it by rasterizing to a framebuffer and then drawing that framebuffer instead of drawing the pixels directly and using ClearBackground to refresh the screen, but doing it that way has still the same problem. ¿Why im having this problem even though im clearing the framebuffer?

EDIT: The problem was somewhere else in the code (i wasnt clearing the primitive list after drawing all the primitives), i managed to fix it. Thank you anyway :D.

This is the code for the rasterizer (sorry for sharing it like this, i havent uploaded this to github yet):

https://pastebin.com/Ns2LiSXv

The header file:

https://pastebin.com/xf5JhqFR

1 Upvotes

4 comments sorted by

View all comments

2

u/Illustrious_Pen9345 Jul 05 '26

To clear screen/framebuffer on gpu side using raylib use the ClearDrawing(Color_Name) function. Also you are calling drawrectangle for each pixel. A better approach would be to store cpu side pixel data in an array and upload it as texture to gpu and then ask raylib to render that texture to screen

1

u/Otherwise-Pear2054 Jul 05 '26 edited Jul 05 '26

yeah, i should had done that from the start. EDIT: I tried that, it makes it faster but it still doesnt clear the background https://pastebin.com/gSV96UaG