Public Group

Archived

This topic is now archived and is closed to further replies.

SDL, create a new surface

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

Recommended Posts

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]

Share on other sites
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.

Share on other sites
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]

Share on other sites
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...

Share on other sites
thanks for the reply everybody i managed to do what i wanted.. i used creatRGABSurface() and it worked

thanks for the help!

Share on other sites
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

Share on other sites
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.

Share on other sites
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

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 18
• 35
• 9
• 16
• 22