The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Using SDL_gfx in SDL2
wboe


Joined: 09 Jan 2012
Posts: 41
Location: Amsterdam, Netherlands
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
Using SDL_gfx in SDL2
Andreas Schiffler
Guest

FYI - I was planning to start working on a SDL_gfx2 lib at some point which will be more-or-less API compatible to SDL_gfx but uses only hardware accelerated drawing sans SDL_Surface bitbanging; i.e. a line is simply a 1pixel texture that is stretched and rotated, etc.

Up to now, various personal things kept me from getting started on that project, but maybe it is time for me to start on at least a stub implementation now. :-)

--Andreas

On 8/16/2012 5:08 AM, wboe wrote:

Quote:
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
#include

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


Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
wboe


Joined: 09 Jan 2012
Posts: 41
Location: Amsterdam, Netherlands
Hello Andreas,

Firstly: thanks for your gfx library, I used it with pleasure for a long time. My original question was about the possibility to keep using it also in SDL2, and why this didn't work is still a mystery for me.

You wrote that you are going to use OpenGL for the next release of SDL_gfx. So your focus is on speed again. However, in my opinion speed is not always that important. For instance when using SDL to create a GUI, then speed is not an issue. More important is robustness, flexibility and a wide choice of primitives. I reimplemented most of your gfx primitives using SDL_Renderer, which had the additional benefit that all checks regarding clipping can be skipped.

Maybe we end up with 2 gfx libraries: one offering blazing speed, the other offering a wide choice and ease of use. But first the coexistance of soft- and hardware rendering should be fully understood. So my question remains: how come the circle in my example was invisible?

wboe