Jump to content

  • Log In with Google      Sign In   
  • Create Account

Double Screen Resolution


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 19 December 2013 - 02:48 AM

Is there a way to use SDL_BlitSurface multiple times to SDL_Surface *screen, but, before doing SDL_Flip(screen);, doubling the resolution of it? My game is meant to look pixelated, so I know this will not increase the quality or anything. The rendering is small due to small tiles, though, so a way to double the scale of anything immediately before SDL_Flip(screen); would be helpful. I would increase the scale of all of the graphics, but that would take more space and some people may prefer a smaller screen resolution, so increasing the scale before flipping the surface sounds like the best option. I prefer to not use OpenGL nor SDL_gfx. Any input would be helpful! Thanks!

Sponsor:

#2 exOfde   Members   -  Reputation: 809

Like
3Likes
Like

Posted 19 December 2013 - 02:54 AM

  • 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 ?

Edited by exOfde, 19 December 2013 - 04:15 AM.


#3 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 19 December 2013 - 03:19 AM

I made a new surface be a scaled version of the screen, blitted that surface to the screen, and used SDL_Flip! Thanks!

#4 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 19 December 2013 - 09:29 PM

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);

}


#5 exOfde   Members   -  Reputation: 809

Like
1Likes
Like

Posted 19 December 2013 - 09:51 PM

 

 

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.


Edited by exOfde, 19 December 2013 - 10:06 PM.


#6 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 19 December 2013 - 10:34 PM

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!


Edited by Tolito, 19 December 2013 - 10:51 PM.


#7 BeerNutts   Crossbones+   -  Reputation: 2941

Like
2Likes
Like

Posted 20 December 2013 - 09:25 AM

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)

#8 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 20 December 2013 - 10:34 AM

Thanks for the response! This is almost finished, so switching to something other than SDL 1.2 at the last minute may be more work than necessary. Is there some kind of way to scale screen and then do SDL_Flip(screen); instead of making a duplicate that is a scaled version of screen and then blitting to screen, flipping screen afterwards? I tried running the scaling code in the background without re-blitting and there was no slowdown. Blitting the duplicated and scaled surface to screen before doing SDL_Flip(screen); is what causes the major slowdown to occur.

#9 amrazek111   Members   -  Reputation: 692

Like
1Likes
Like

Posted 20 December 2013 - 12:44 PM

You're going about this the wrong way. You can
  • 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
Doing any kind of pixel manipulation is going to be very slow in SDL1.2 so offload as much of it as you can into one-time processes performed at startup.

#10 Tolito   Members   -  Reputation: 256

Like
0Likes
Like

Posted 20 December 2013 - 09:17 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS