Double Screen Resolution
- Of course you can use SDL_BlitSurface mulitple times to "screen". the "screen" is just an ordinary SDL_Surface.
- You can blitted so often like you want
- you can rescale it so often like you want
- And that all before you use SDL_Flip
- Why don't you just try it ?
"Hello World"
It works well on something that I made that is a lower resolution, but the processor or something gets loud when trying to use this method with anything of a larger resolution, the processor gets loud and the entire computer slows down. I know it isn't the scaling code, since using the same smaller resolution with the scaled screen does not do this. When I comment out the function for doubling the actual viewing resolution of the screen, those glitches are eliminated, although only the upper-left-hand corner of the screen can be seen due to having not updated the window dimensions. The scaling isn't slow, nor is the blitting, but trying to blit the surface after scaling it is probably double the work for the processor. Doesn't SDL have some kind of display option for doubling the resolution? Are there any user-made functions online for this? A function for doubling the screen itself instead of doubling a duplicate of it, then blitting that would work better. SDL seems to edit the scaling in real time when in fullscreen, but that may be the hardware. Can anyone shed some light on this? Thanks!
Here is the code for the function:
void zoom_surface(SDL_Surface *original, float aspect, float zoom, unsigned int xloc, unsigned int yloc, unsigned int new_screen_w, unsigned int new_screen_h) {
SDL_Surface *scaled;
Uint8 *targ, bpp;
int x, y;
bpp = original->format->BytesPerPixel;
scaled =
SDL_CreateRGBSurface (original->flags, original->w * aspect * zoom,
original->h * zoom,
original->format->BitsPerPixel,
original->format->Rmask,
original->format->Gmask,
original->format->Bmask,
original->format->Amask);
if (bpp == 1)
SDL_SetPalette (scaled, SDL_LOGPAL, original->format->palette->colors,
0, original->format->palette->ncolors);
targ = ((Uint8 *) scaled->pixels);
for (y = 0; y < scaled->h; y++) {
for (x = 0; x < scaled->w; x++) {
#if 1
switch (bpp) {
case 1:
*((Uint8 *) (targ)) =
*((Uint8 *) (original->pixels)+((int)(y/zoom))*original->w+(int)(x/(aspect*zoom)));
targ++;
break;
case 4:
*((Uint32 *) (targ)) =
*((Uint32 *) (original->pixels)+((int)(y/zoom))*original->w+(int)(x/(aspect*zoom)));
targ += 4;
break;
}
#else
memcpy(targ,original->pixels+(int)(y/zoom)*original->pitch+
(int)(x/(aspect*zoom))*bpp,bpp);
targ+=bpp;
#endif
}
targ += scaled->pitch - scaled->w*bpp;
}
if(new_screen_w && new_screen_h && (stored_res_x!=new_screen_w || stored_res_y!=new_screen_h) ) screen=SDL_SetVideoMode( new_screen_w, new_screen_h, 32, SDL_SWSURFACE ),stored_res_x=new_screen_w,stored_res_y=new_screen_h;
SDL_Rect dest={xloc,yloc};
SDL_BlitSurface(scaled,NULL,screen,&dest);
SDL_FreeSurface(scaled);
}
A function for doubling the screen itself instead of doubling a duplicate of it [...]
Dependet on which Version you use:
- SDL2 : SDL_SetWindowSize or in Fullscreen SDL_SetWindowDisplayMode
- SDL1.2 : SDL_SetVideoMode
The difference between them is that the first one really change the resoultion and the second on just set a new video mode to the resolution you want IT doesn't scale anything what on the screen is from what i know.
"Hello World"
if(new_screen_w && new_screen_h && (stored_res_x!=new_screen_w || stored_res_y!=new_screen_h) ) screen=SDL_SetVideoMode( new_screen_w, new_screen_h, 32, SDL_SWSURFACE ),stored_res_x=new_screen_w,stored_res_y=new_screen_h;
That's what I was saying. The problem was probably not occurring because it only had to blit for one fourth of the size of the window. With that line of code enabled, however, it must do four times the blitting, which led to an entire system slowdown.
Instead of scaling and blitting a duplicate, how can I scale the screen itself and use SDL_Flip on that? For example, this:
scale(screen);
SDL_Flip(screen);
Instead of this:
SDL_Surface *scaled=scale(screen);
SDL_BlitSurface(scaled,NULL,screen,NULL);
SDL_Flip(screen);
I tried running the code with scaling going on in the background with no re-blitting. There was no lag. Blitting without scaling also results in no lag. With both scaling and blitting, however, the entire system slows down. Thanks again!
SDL1.2 does not take advantage of hardware acceleration, and, in your code above, you are manually zoom. My suggesiton would be to use a multimedia API that uses the GFX hardware to do all the scaling, rotating, etc. that you need in hardware. I know SFML does; SDL2.0 is supposed to, but I've never used it.
My Gamedev Journal: 2D Game Making, the Easy Way
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
- reduce the screen resolution and use your graphics at their current size, or
- scale your graphics up as part of the resource loading process rather than trying to scale the entire screen (or individual surfaces) on every frame, or
- scale your graphics up in whatever you're using to create them so that they're the correct size relative to your desired resolution
I added code to work with surfaces that are double their original scale and made them be scaled after being loaded. It took a while to implement, but the doubled resolution renders more quickly now. The original, doubled, and fullscreen resolutions are now all available to the user. Hopefully storing the scaled surfaces will not be a problem for the system requirements! Thanks for the input! I was hoping there was a way to render at double the resolution without having to scale the surfaces, but this will do.