Always a transparent surface in Visual Studio 2005

Hi

Im a newbie with SDL and am learning from the book from “Focus on SDL”.

Im stuck on the first chapter :slight_smile:

I always get a transparent screen with the following code

#include “sdl.h”
#include <stdio.h>
#include <stdlib.h>

SDL_Surface *g_pMainSurface = NULL;
SDL_Event g_Event;

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf(stderr, “Couldnt initialize SDL !\n”);
}
else
{
fprintf(stdout, “SDL initialized properly !\n”);
atexit(SDL_Quit);
}

g_pMainSurface = SDL_SetVideoMode(1024, 768, 0, SDL_ANYFORMAT);
if (!g_pMainSurface)
{
	fprintf(stderr, "Couldnt create main surface !\n");
	exit(1);
}

for ( ; ; )
{
	if (SDL_WaitEvent(&g_Event) == 0)
	{
		fprintf(stderr, "Error while waiting for an event !\n");
		exit(1);
	}

	// Check the type of event...
	if (g_Event.type == SDL_QUIT)
	{
		fprintf(stdout, "Quit event has occured !\n");
		break;
	}
}

fprintf(stdout, "Terminating program normally !\n");

return 0;

}

Im using Visual Studio 2005. I tried this code out on another system with Visual
Studio 2003 and get the expected blank black screen.

In Visual Studio 2005, Its always transparent and the window gets created with a
background, as the desktop that was at lauch. It doesnt change if I move the
screen around. So I guess it just uses what ever is presnt withing that desktop
region at creation and doesnt change later.

I hope the explanation is clear enough for any one to help me out.

Look forward to hear from anyone soon.

Regards

Vinay

It looks like you are not clearing the screen after you initialize it.
Granted you do not actually have access to the area in memory where the
desktop is stored, however, failure to clear it will result in "garbage"
being displayed. I know in double buffered mode a call to SDL_SwapBuffers()
would work. Not sure in single buffered mode but I believe it will.

HTH,
RichardOn 4/8/06, Vinay wrote:

Hi

Im a newbie with SDL and am learning from the book from “Focus on SDL”.

Im stuck on the first chapter :slight_smile:

I always get a transparent screen with the following code

#include “sdl.h”
#include <stdio.h>
#include <stdlib.h>

SDL_Surface *g_pMainSurface = NULL;
SDL_Event g_Event;

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf(stderr, “Couldnt initialize SDL !\n”);
}
else
{
fprintf(stdout, “SDL initialized properly !\n”);
atexit(SDL_Quit);
}

    g_pMainSurface = SDL_SetVideoMode(1024, 768, 0, SDL_ANYFORMAT);
    if (!g_pMainSurface)
    {
            fprintf(stderr, "Couldnt create main surface !\n");
            exit(1);
    }

    for ( ; ; )
    {
            if (SDL_WaitEvent(&g_Event) == 0)
            {
                    fprintf(stderr, "Error while waiting for an event

!\n");
exit(1);
}

            // Check the type of event...
            if (g_Event.type == SDL_QUIT)
            {
                    fprintf(stdout, "Quit event has occured !\n");
                    break;
            }
    }

    fprintf(stdout, "Terminating program normally !\n");

    return 0;

}

Im using Visual Studio 2005. I tried this code out on another system with
Visual
Studio 2003 and get the expected blank black screen.

In Visual Studio 2005, Its always transparent and the window gets created
with a
background, as the desktop that was at lauch. It doesnt change if I move
the
screen around. So I guess it just uses what ever is presnt withing that
desktop
region at creation and doesnt change later.

I hope the explanation is clear enough for any one to help me out.

Look forward to hear from anyone soon.

Regards

Vinay


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Richard J Hancock
RJH Computers
http://www.rjhcomputers.com