Tuesday, April 5, 2011

Having trouble initializing an SDL_Surface

I'm trying to set up something in SDL [in C++] where I can draw a one pixel big rectangle. I've got everything in my code working except my second SDL_Surface called rectangle. I'm having trouble initializing it. Here's the line where I try to initialize it:

rectangle = SDL_Surface(SDL_DOUBLEBUF | SDL_HWACCEL | 
                        SDL_SRCALPHA  | SDL_HWSURFACE,
                        screen->format, 1, 1, 16, NULL, clip_rect, 1);

Thank you for taking the time to read this and any answers you might choose to give.

From stackoverflow
  • I think that the main problem you are having is that there is no SDL_Surface function. To create a new surface, use SDL_CreateRGBSurface. Be sure to call SDL_FreeSurface on the returned surface after you are done with it or you will leak memory.

    Additionally, I am not sure why you are creating a surface for the rectangle. A cleaner way of drawing a solid-color rectangle is SDL_FillRect without creating a new surface.

    William : Yeah, that worked. Thank you very much.

0 comments:

Post a Comment