There is the following code. The desired result is that a window is created and a filled circle is drawn:
有以下代码。所需的结果是创建一个窗口并绘制一个实心圆:
#include <SDL2/SDL.h>
#include <iostream>
#include <SDL2/SDL2_gfxPrimitives.h>
int main()
{
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
std::cout << "Could not initialise" << std::endl;
return 1;
}
window = SDL_CreateWindow("MyGame",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_SHOWN);
if(!window)
{
std::cout << "Could not create the window" << std::endl;
return 1;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_RenderClear(renderer);
Sint16 circleR = 100;
Sint16 circleX = 300;
Sint16 circleY = 300;
SDL_Surface* windowSurface = SDL_GetWindowSurface(window);
Uint32 circleColour = SDL_MapRGB(windowSurface->format, 255, 0, 0);
int result = filledCircleColor(renderer, circleX, circleY, circleR, circleColour);
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);
bool run = true;
while(run)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
run = false;
}
}
}
SDL_Quit();
return 0;
}
The problem is that the circle is not drawn - the window is all black.
问题是没有绘制圆圈 - 窗口全是黑色的。
The output:
drawing the circle r 100 x 300 y 300 circleColour 16711680
draw circle result 0
filledCircleColor
returns 0 what should mean that there's no error.
filledCircleColor返回0表示没有错误。
What should be done so that the circle is drawn? I'm using SDL 2.0.2 on Ubuntu with SDL2 gfx extension.
应该做什么才能绘制圆圈?我在Ubuntu上使用SDL 2.0.2,扩展名为SDL2 gfx。
1 个解决方案
#1
About SDL_GetWindowSurface
, the documentation says : "You may not combine this with 3D or the rendering API on this window."
关于SDL_GetWindowSurface,文档说:“你可能不会在这个窗口上将它与3D或渲染API结合起来。”
For me, in your example, SDL_GetWindowSurface
returns null.
对我来说,在您的示例中,SDL_GetWindowSurface返回null。
The filledCircleColor()
function takes a color of the form 0xRRGGBBAA.
filledCircleColor()函数采用0xRRGGBBAA形式的颜色。
It works after removing the surface part, and changing to :
它在移除表面部件后工作,并更改为:
int result = filledCircleColor(renderer, circleX, circleY, circleR, 0xFF0000FF);
#1
About SDL_GetWindowSurface
, the documentation says : "You may not combine this with 3D or the rendering API on this window."
关于SDL_GetWindowSurface,文档说:“你可能不会在这个窗口上将它与3D或渲染API结合起来。”
For me, in your example, SDL_GetWindowSurface
returns null.
对我来说,在您的示例中,SDL_GetWindowSurface返回null。
The filledCircleColor()
function takes a color of the form 0xRRGGBBAA.
filledCircleColor()函数采用0xRRGGBBAA形式的颜色。
It works after removing the surface part, and changing to :
它在移除表面部件后工作,并更改为:
int result = filledCircleColor(renderer, circleX, circleY, circleR, 0xFF0000FF);