I wanted to write screen saver function for my mother OpenGL Suface yesterday.
First, i thinked this is very easy!
I wrote SDL_SaveBMP(screen,"deneme.bmp");
The End..
That can be comic for you but unluckily it did not be.
The program showed an error message me and it was grotesque for me.
Then, I found a function from a web site but does not work correctly.When it saved a bmp file, it only showed a color on all surface.The color was color of glClearColor function.
The Screenshot Code:
int Screenshot(char *filename, SDL_Surface *screen)
{
SDL_Surface *temp;
unsigned char *pixels;
int i;
if (!(screen->flags & SDL_OPENGL))
{
SDL_SaveBMP(temp, filename);
return 0;
}
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
);
if (temp == NULL)
return -1;
pixels = malloc(3 * screen->w * screen->h);
if (pixels == NULL)
{
SDL_FreeSurface(temp);
return -1;
}
glReadBuffer(GL_FRONT_AND_BACK);
glReadPixels(0, 0,screen->w, screen->h,GL_RGB , GL_UNSIGNED_BYTE, pixels);
for (i=0; i<ekran->h; i++)
memcpy(((char *) temp->pixels) + temp->pitch * i, pixels + 3*screen->w * (ekran->h-i-1), screen->w*3);
free(pixels);
SDL_SaveBMP(temp, filename);
SDL_FreeSurface(temp);
return 0;
}
Not : For first error the reason is not different between screen,"filename" and "filename",screen.SDL_SaveBMP and Screenshot are different fuctions.
Thanks.