JuliaMultimedia / SimpleDirectMediaLayer.jl

SDL2
MIT License
81 stars 18 forks source link

Rectangle outlines are noisey #71

Closed mpeters2 closed 10 months ago

mpeters2 commented 11 months ago

MacOS 14.0 Julia 1.9.3 SimpleDirectMediaLayer v0.4.0

When I draw a rectangle outline, it's fill with random stuff. In the code below, I draw a dark blue/green filled rectangle followed by a yellow outline.

Screenshot 2023-12-10 at 1 35 28 PM

Another example:

Screenshot 2023-12-10 at 1 40 19 PM

and another example, where I commented-out the lines that draw the filled blue/green rectangle:

Screenshot 2023-12-10 at 1 42 22 PM
using SimpleDirectMediaLayer
using SimpleDirectMediaLayer.LibSDL2

# Minimum code to demonstrate border error when drawing rectangles.

@assert SDL_Init(SDL_INIT_EVERYTHING) == 0 "error initializing SDL: $(unsafe_string(SDL_GetError()))"

win = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1000, 1000, SDL_WINDOW_SHOWN)
SDL_SetWindowResizable(win, SDL_TRUE)

renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)

#SDL_RenderClear(renderer)                      # this clears the background to the current color
#    SDL_RenderPresent(renderer);
SDL_PumpEvents()
mRect = SDL_Rect(250, 150, 200, 200)                    # wacky Julia struct constructor; x,y, widht, height; Ref() gives us the pointer
SDL_SetRenderDrawColor(renderer, 0, 127, 127, 255); 
SDL_RenderFillRect( renderer, Ref{SDL_Rect}(mRect))     # that addition mess lets me send the rect as a pointer to the rect

SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255)      # Yellow outline
SDL_RenderDrawRect( renderer, Ref{SDL_Rect}(mRect))     # draw outline rectangle

SDL_RenderPresent(renderer);
SDL_PumpEvents()
SDL_Delay(10000)

exit()
mpeters2 commented 10 months ago

Calling SDL_RenderClear(renderer) before initial drawing and after each SDL_RenderPresent(renderer) cleared out the noise.