第二次循环后填充SDL2_gfx屏幕

时间:2021-01-18 12:08:28

So when this code taken from Cannot draw a filled circle with SDL2 gfx:

所以当这段代码从无法用SDL2 gfx绘制一个实心圆时:

SDL_RenderClear(renderer);

Sint16 circleR = 100;
Sint16 circleX = 300;
Sint16 circleY = 300;

int result = filledCircleColor(renderer, circleX, circleY, circleR, 0xFF0000FF);

//std::cout << "drawing the circle r " << circleR << " x " << circleX << " y " << circleY << " circleColour " << circleColour << std::endl;
std::cout << "draw circle result " << result << std::endl;

SDL_RenderPresent(renderer);

runs only once, it properly draws a circle. However, if it loops around and executes it a second, time, the screen fills with the color's circle, which in this case is red. The same effect happens on all the other functions. How can you ensure a proper circle is drawn on multiple loops and not a window full of color?

只运行一次,它正确地绘制一个圆圈。但是,如果它循环并执行一秒钟,则屏幕将填充颜色的圆圈,在这种情况下为红色。所有其他功能都会产生同样的效果。如何确保在多个循环上绘制正确的圆,而不是一个充满颜色的窗口?

1 个解决方案

#1


2  

You need to set the clear color with SDL_SetRenderDrawColor before your call to SDL_RenderClear. Otherwise the color you set while drawing your circle will still be the active draw color and you'll fill the entire render area with it.

在调用SDL_RenderClear之前,需要使用SDL_SetRenderDrawColor设置清晰颜色。否则,在绘制圆形时设置的颜色仍然是活动的绘制颜色,您将使用它填充整个渲染区域。

#1


2  

You need to set the clear color with SDL_SetRenderDrawColor before your call to SDL_RenderClear. Otherwise the color you set while drawing your circle will still be the active draw color and you'll fill the entire render area with it.

在调用SDL_RenderClear之前,需要使用SDL_SetRenderDrawColor设置清晰颜色。否则,在绘制圆形时设置的颜色仍然是活动的绘制颜色,您将使用它填充整个渲染区域。