Problem creating background

So noone can tell me anything??

Apokliptico wrote:

Hi everyone!
Well, I’m working with the new SDL 1.3 (Guys, you might wanna improve the documentation on this version), and I’m having a lot of trouble with the SDL_CreateRGBSurface function, so basically my code is this:

Code:
bool CApp::OnInit() //This initializes the SDL lib.
{
Uint32 rmask = 0x0000005f;
Uint32 gmask = 0x00003f00;
Uint32 bmask = 0x006f0000;
Uint32 amask = 0x2f000000;
SDL_Surface *SurBackground1 = SDL_CreateRGBSurface(0, 200, 200 , 32, rmask,gmask,bmask,amask);
SurBackground = SDL_DisplayFormatAlpha(SurBackground1);
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
srand(time(NULL));
numwinds = 0;
while(CApp::CWindow());
return true;
}

bool CApp::CWindow() //This creates different windows.
{
if(!(numwinds < MAX_WINDOWS)) return false;
Window_Display[numwinds] = SDL_CreateWindow(“App”, 800 * rand() / (float) RAND_MAX, 600 * rand() / (float) RAND_MAX, 200, 200, SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
if(SDL_CreateRenderer(Window_Display[numwinds], -1, SDL_RENDERER_ACCELERATED) < 0) cout << SDL_GetError() << endl;
numwinds++;
return true;
}

void CApp::OnRender() //This is the renderer.
{
for(int i = 0; i < MAX_WINDOWS; i++)
{
if(Window_Display[i])
{
SDL_SelectRenderer(Window_Display[i]);
SDL_Texture *TempText = NULL;
SDL_RenderClear();
SDL_RenderCopy(TempText,NULL,NULL);
SDL_RenderPresent();
}
}
}

It works fine in the sense that it shows the windows with a black background, but I want the background to be a different color and then I want to use a jpeg as a background over the old background.

Can you help me please??
THANKS!!

Use SDL_SetRenderDrawColor() to set the draw color before you call SDL_RenderClear(), and that will give you any color background you want.

To use a jpeg, you should use the SDL_image library to load the image into an SDL_Surface, which is the decoded image residing in system memory. Then use SDL_CreateTextureFromSurface() to turn it into an SDL_Texture, which resides in video memory for hardware accelerated renderers. You can then use it in SDL_RenderCopy() to put it on the screen.