go-sdl2 icon indicating copy to clipboard operation
go-sdl2 copied to clipboard

Render operations take too long

Open Pixdigit opened this issue 7 years ago • 5 comments
trafficstars

When doing drawing operations the renderers buffer is not immediately updated. If e.g. I fill a rect and directly present afterwards the rect will not be drawn. I think this is an issue with sdl. Either they are not mentioning it in their docu or is indeed a bug. It could however be solved within go. But I would recommend against since it would just be a workaround and not a fix. However this could be noted in the documentation of go-sdl2 that drawing operations take a while to succeed.

Pixdigit avatar Jul 10 '18 15:07 Pixdigit

Do you have a code example to help reproduce the problem?

I suspect a bad manipulation or faulty hardware, because there would be way much of a bigger uproar had this been the case...

nitrix avatar Jul 11 '18 19:07 nitrix

See the Pastebin here.

Pixdigit avatar Jul 11 '18 19:07 Pixdigit

The default color is white and you set it again to white.

Then you draw with SDL_RenderFillRect, which, when the argument is NULL, draws over the entire render target (your whole screen) with said new white.

Then we present the result, which is of course, going to look blank.

For fun, I switched to red and it behaved as expected and could not reproduce your issue.

-	screenRenderer.SetDrawColor(255, 255, 255, 255)
+	screenRenderer.SetDrawColor(255, 0, 0, 255)

untitled

nitrix avatar Jul 12 '18 02:07 nitrix

I set it again to the default colour because it is more descriptive. Also makes it easier to change colour.

For me this program results in this picture: picture

Note: the content is part of my desktop background. As soon as I add delay between the Draw call and the Present it works as intended.

Pixdigit avatar Jul 12 '18 09:07 Pixdigit

It does appear to be the behavior of native SDL2 when I run the C equivalent of the example which is this:

#include <SDL2/SDL.h>

int main()
{
    SDL_Window *window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0, 0);
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);

    SDL_SetWindowSize(window, 400, 400);

    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    SDL_RenderFillRect(renderer, NULL);
    SDL_Delay(1000);
    SDL_RenderPresent(renderer);
    SDL_Delay(3000);
}

I have put a note about this in the README.md under the FAQ section.

veeableful avatar Jul 14 '18 07:07 veeableful