在SDL 2.0中创建1x1纹理

时间:2014-01-01 06:50:12

标签: c++ sdl sdl-2

在C#和XNA中,您可以像这样创建1x1纹理:

Texture2D white_pixel;
white_pixel = new Texture2D(GraphicsDevice, 1, 1);
white_pixel.SetData<Color[]>(new Color{ Color.White });
// Sorry if I got the syntax wrong, it's been a while

然后,你可以通过这样做任意地将像素绘制成任何大小和颜色:

spriteBatch.Begin();
spriteBatch.Draw(white_pixel, new Rectangle(0, 0, width, height), Color.Whatever);
spriteBatch.End();

SDL中的等价物是什么?

SDL_Texture *tex = nullptr;
SDL_CreateTexture(renderer,
                               Uint32        format, // What do I put here
                               int           access, // and here
                               1
                               1);
// Not sure if this is correct
SDL_SetTextureColorMod(tex,
                       255,
                       255,
                       255)
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.w = 10;
rect.h = 10;
SDL_RenderCopy(renderer, tex, nullptr, &rect);  

1 个答案:

答案 0 :(得分:0)

SDL_PIXELFORMAT_RGB24的{​​{1}} / SDL_PIXELFORMAT_BGR24format的{​​{1}}将是一个良好的开端。

或者您可以直接通过SDL_SetRenderDrawColor()SDL_RenderFillRect()绘制彩色矩形。