SDL, create a new surface

Started by
6 comments, last by sdlprorammer 19 years, 10 months ago
After i create the "screen" surface, ( which is obviously used for the screen ), i want to create another surface, that will contain what "screen" contained at the beginning of the program. I want to do that because i want to save somewhere the initial pixels of the screen, because throught the program the pixels will change value, and i want to have the initiale state of them. That's how it will look like:

SDL_Surface *screen, *initialScreen;
screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF); 

/* initialScreen = ... ??? - creating the new surface  */

SDL_BlitSurface( screen, NULL, initialScreen, NULL );

... // now i can change the pixels of "screen"

So, what am i gonna use to create the new ( empty ) surface? Am i allowed to use StVideoMode() again? I think i should use SDL_CreateRGBSurface(), but i don't know how ??? thanks [edited by - sdlprorammer on May 28, 2004 6:32:59 AM]
Advertisement
I don''t think SDL allows you to access the original display mode. When you create a video surface it sets the pixel buffer to full black at creation, so you can''t just blit the starting data. I don''t think SDL can do what you want here, but I may be wrong.

--------------------------------------------------------
Life would be so much easier if we could just get the source code.
--------------------------------------------------------Life would be so much easier if we could just get the source code.
What do you mean ... "screen at the beginning of the program"?

Not sure if that answers the question ... but this is how it usually works:

You create a backbuffer (your screen Surface) and then you create other surfaces (for example render a font to a new surface, or load an image as surface).
You blit the other surfaces in each frame (afaik this adds the pixels of that surface to the backbuffer).
SDL_BlitSurface( newSurface, 0, screen, &rcDest );

At the beginning the backbuffer is empty of course.
You usually draw a rectangle to fill it with an ugly green(everybody does that ALWAYS):
SDL_FillRect( screen, 0, SDL_MapRGB( screen->format, 95, 130, 95 ) );

Then you show the backbuffer
SDL_Flip( screen );
and clear it again for the next frame.

Not sure but
initialScreen = screen;
Might work for capturing the content of the backbuffer!?
But usually your program will recreate the content of the backbuffer when you need it ...

To lazy for proofreading ... take this post with a grain of salt

---
If nothing works the way it should ... maybe you need a break!?
Get cracking and double-check the switch statements!!
Tolop|Andyart.de

[edited by - Clueless on May 28, 2004 8:39:23 AM]
Writing errors since 10/25/2003 2:25:56 AM
Have you tried reading the documentation that comes with SDL? I believe it has examples on surface creation. Including a mini-tutorial.

A little hunting, otherwise, will turn up "SDL_CreateSurface" in the list of functions. It should be pretty obvious what it''s for...
thanks for the reply everybody i managed to do what i wanted.. i used creatRGABSurface() and it worked

thanks for the help!
Since you guys seem to know about SDL, can you tell me how to specify the frame rate in SDL? I have poured over the docs and can''t seem to find it.
Thanks
There''s no built in frame rate control in SDL, if you want to lock the FPS to a certain value then you will need to modify your main game loop to take this into account.
Specify framerate?
Not sure I understand what you mean.
I think the only time I have seen something like that was an opengl framework for games with a function that did a lot of stuff.
Creating a window, starting a gameloop and setting a fixed frame rate ...
I don'' think there is a way to do that in SDL.

If you want that for timing maybe a frame rate independent solution would be better!?

Maybe the first example there might be interesting:
http://olofson.net/examples.html
Writing errors since 10/25/2003 2:25:56 AM

This topic is closed to new replies.

Advertisement