Advertisement Jump to content
Sign in to follow this  
Lith

SDL saving surfaces

This topic is 3362 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Yes:

SDL_Surface* screen = SDL_CreateRGBSurface( SDL_SWSURFACE, width, height,
32, 0x0000ff, 0x00ff00, 0xff0000, 0x000000 );

unsigned char* pixels = new unsigned char[ width * height * 4 ];
unsigned char* temp = new unsigned char[ width * height * 4 ];

glReadPixels( 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, temp );

for (unsigned int i = 0; i < height; ++i) {
memcpy( pixels + (height-i-1) * width*4, temp + i * width*4, width*4 );
}

screen->pixels = pixels;

SDL_SaveBMP( screen, "screenshot.bmp" );
SDL_FreeSurface( screen );
delete[] temp;
[/src]

Share this post


Link to post
Share on other sites
Thanks for the reply, but i dont really understand some of that code.

And where you have
glReadPixels
doesnt the gl mean that its an opengl fuction? or is that a prototype... or something

i understand the first bit, kind of, i think you are creating an empty surface

or is this pesudo(i think thats how you spell it) code

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!