MFC & SDL... problem

Thanks for Dennis Jenkins for sending a code that exports the window
to a BMP file.
My problem is that the following statement:
SDL_Surface *screen = SDL_GetVideoSurface ();
just simply doesn’t work. After this statement the screen variable is
NULL.
Is that because I’m using MFC? How can I get the video surface of an
MFC program? Or what am I doing wrong?
I only have a menu at the top of the window. By clicking on “Export
bmp” I’d like to save the whole surface to a BMP file. This is what the
source code is. This code always displays the “Cannot get the video
surface” error message" What am I doing wrong??
Thanks for your help !!!

void CMainFrame::OnExportbmpExport ()
{
//Initalize SDL
#ifdef _DEBUG
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
#else
SDL_Init (SDL_INIT_VIDEO);
#endif

//Get SDL Surface
SDL_Surface *screen = SDL_GetVideoSurface ();
SDL_Surface *temp;
unsigned char * pixels;
int i;

if (screen != NULL)
{
        if (!(screen->flags & SDL_OPENGL)) {
            SDL_SaveBMP (temp, "a.bmp");
        }

temp = SDL_CreateRGBSurface (SDL_SWSURFACE, screen->w, 

screen->h, 24,

#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000FF, 0x0000FF00, 0x00FF0000, 0
#else
0x00FF0000, 0x0000FF00, 0x000000FF, 0
#endif
);

pixels = (unsigned char *) malloc (3 * (screen->w) * (screen->h));
if (pixels == NULL){
    SDL_FreeSurface (temp);
}

glReadPixels (  0,
                        0, screen->w,
                        screen->h,
                        GL_RGB,
                        GL_UNSIGNED_BYTE,
                        pixels);

for (i = 0; i < screen->h; i++){
memcpy (((char *) temp->pixels) + temp->pitch * i
			  , pixels + 3 * (screen->w) * 

((screen->h) - i - 1)
, (screen->w) * 3);
}
free (pixels);

SDL_SaveBMP (temp, "a.bmp");
free (pixels);
SDL_FreeSurface (temp);
}

else
MessageBox (“Unable to get the video surface.”
, “Error”
, MB_OK | MB_ICONERROR);

// Shutdown SDL
SDL_Quit ();

}

Hi,

SDL hasn’t got anything to do with your problem, you need to use either MFC or
SDL. The two can work together but not the way you are hoping here.

On a more useful note have you looked here: http://www.mfcogl.com/
Specifically under “Simple MFC OpenGL Application” and then under “Bitmap
Graphics” and then “Example 3”.

The archive with the relevent files in is here but the link may not work:
http://www.mfcogl.com/Bitmap Lib on Cube, MFC & OpenGL 4_28_01.zip”

Have a look at the file “glbmp.cpp” paying particular attention to
CGLBMP::SaveGLBuffer(), CGLBMP::SaveImage(), and CGLBMP::SaveBMP().

Good luck,

cheers,
John.On Wednesday 18 February 2004 11:37 am, Bocsi Nemigaz wrote:

Thanks for Dennis Jenkins for sending a code that exports the window
to a BMP file.
My problem is that the following statement:
SDL_Surface *screen = SDL_GetVideoSurface ();
just simply doesn’t work. After this statement the screen variable is
NULL.
Is that because I’m using MFC? How can I get the video surface of an
MFC program? Or what am I doing wrong?
I only have a menu at the top of the window. By clicking on “Export
bmp” I’d like to save the whole surface to a BMP file. This is what the
source code is. This code always displays the “Cannot get the video
surface” error message" What am I doing wrong??
Thanks for your help !!!

void CMainFrame::OnExportbmpExport ()
{
//Initalize SDL
#ifdef _DEBUG
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
#else
SDL_Init (SDL_INIT_VIDEO);
#endif

//Get SDL Surface
SDL_Surface *screen = SDL_GetVideoSurface ();
SDL_Surface *temp;
unsigned char * pixels;
int i;

if (screen != NULL)
{
        if (!(screen->flags & SDL_OPENGL)) {
            SDL_SaveBMP (temp, "a.bmp");
        }

temp = SDL_CreateRGBSurface (SDL_SWSURFACE, screen->w,

screen->h, 24,

#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000FF, 0x0000FF00, 0x00FF0000, 0
#else
0x00FF0000, 0x0000FF00, 0x000000FF, 0
#endif
);

pixels = (unsigned char *) malloc (3 * (screen->w) * (screen->h));
if (pixels == NULL){
    SDL_FreeSurface (temp);
}

glReadPixels (  0,
                        0, screen->w,
                        screen->h,
                        GL_RGB,
                        GL_UNSIGNED_BYTE,
                        pixels);

for (i = 0; i < screen->h; i++){
memcpy (((char *) temp->pixels) + temp->pitch * i
  		  , pixels + 3 * (screen->w) *

((screen->h) - i - 1)
, (screen->w) * 3);
}
free (pixels);

SDL_SaveBMP (temp, "a.bmp");
free (pixels);
SDL_FreeSurface (temp);
}

else
MessageBox (“Unable to get the video surface.”
, “Error”
, MB_OK | MB_ICONERROR);

// Shutdown SDL
SDL_Quit ();
}


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

If you haven’t called SDL_SetVideoMode, SDL_GetVideoSurface has nothing to
return, so just returns NULL.On Wednesday 18 February 2004 05:37, Bocsi Nemigaz wrote:

Thanks for Dennis Jenkins for sending a code that exports the window
to a BMP file.
My problem is that the following statement:
SDL_Surface *screen = SDL_GetVideoSurface ();
just simply doesn’t work. After this statement the screen variable is
NULL.

you could always do something like yahoo games, maybe have a chat room and
then people can play eachother in tic tac toe, checkers etc? (:> ----- Original Message -----

From: tsm@accesscomm.ca (Tyler Montbriand)
To:
Sent: Wednesday, February 18, 2004 8:39 AM
Subject: Re: [SDL] MFC & SDL… problem…

On Wednesday 18 February 2004 05:37, Bocsi Nemigaz wrote:

Thanks for Dennis Jenkins for sending a code that exports the window
to a BMP file.
My problem is that the following statement:
SDL_Surface *screen = SDL_GetVideoSurface ();
just simply doesn’t work. After this statement the screen variable is
NULL.

If you haven’t called SDL_SetVideoMode, SDL_GetVideoSurface has nothing to
return, so just returns NULL.


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