Hi,
The SDL_gfx library has not yet been ported to SDL2, probably because the new SDL_Renderer does not mix well with the used low-level routines. However, using C++ it is easy to write glue logic such that the SDL_gfx functions can be used unaltered. The next example should paint a circle on a red background:
Code:
#include <SDL.h>
#include <SDL_gfxPrimitives.h>
void circleColor(SDL_Window *win,int xc, int yc, int r,Uint32 col) { // overloaded function
circleColor(SDL_GetWindowSurface(win),xc,yc,r,col); // a function from library SDL_gfx
}
int main(int,char**) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1;
SDL_Window *window = SDL_CreateWindow(“Can’t”, 100, 100, 100, 100, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
SDL_SetRenderDrawColor(renderer, 255, 100, 100, 255); // red
SDL_RenderClear(renderer);
circleColor(window,50,50,20,0xff);
SDL_RenderPresent(renderer);
SDL_Event event;
while (1)
while(SDL_PollEvent(&event))
if (event.type==SDL_QUIT) goto quit;
quit: SDL_Quit();
return 0;
}
If this file is named cant.cpp, it can be compiled with
g++ -o cant cant.cpp $(sdl2-config --cflags) -I/usr/include/SDL $(sdl2-config --libs) -lSDL_gfx
So far no problems, but on the screen only the red background is displayed, but no circle! Apparently the renderer did not notice that something was painted to its surface. Would there be a solution to this problem?
wboe