Jump to content


Photo

Pixel Perfect Resizing


  • Please log in to reply
69 replies to this topic

#1 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 22 December 2008 - 05:33 PM

Posted Image

This is for everyone who makes a low-res game and is annoyed by that blur that happens if you size up the screen or gets graphical glitches if they use tiles and use the viewport to size up the view.

LINK
MIRROR

IMPORTANT!
  • ALWAYS MAKE THIS OPTIONAL. ALWAYS!
    Apparently not all computers handle surfaces with no problems and even if they usually do, if the video memory is messed up, it'll glitch until the computer is being restarted.
    Don't look at me I have no idea why that is the case, it's a game maker related problem I have no explanation for. See this post.
    It's alright though, it only takes one script call to switch it on and off. But make sure you actually use it in the options somewhere in your game!
    The resizing is on by default, to switch it off simply call "scr_toggle_resize();" after initializing it, before going to the menu room (that your game undoubtedly has, right? Right?)
  • Don't activate"Use synchronization to avoid tearing" if you use this! It'll tremendously slow the game down!
    Once again, game maker related issue that I have no clue why it happens.
  • Also due to the view being resetted, the native gm object following won't work. You have to make your own system for view handling.
  • I'm not entirely sure about it but I think gm-native transitions won't work propperly with this either.
  • If you get a black screen, that's probably because of your game deactivating the screen controlling instance.
    Call:
    instance_activate_object(global.screencontroller);
    right after de-activating all instances to solve that.
    That should always keep the controller object activated, regardless of what sprite or position it has.

How to use the scripts:

scr_resize_init(w,h): Initializes the system.
Call it when your game starts.
w: view width, h: view height.

scr_resize_init_gm7(w,h): If you use gamemaker 7 or 8, use this script to initialize the system because gm7+ handles surfaces differently.

scr_room_goto_resize(room,w,h,wport,hport): Always use this instead of room_goto and use it at least once so the system has an effect!
wport: width of the screen hport: height of the screen room: room to go to.
wport and hport are how big you want the screen to be, not how big the view is so you want to make it bigger than width and height to increase the size of the view.

scr_toggle_resize(w,h): Toggles the resizing.
Always call scr_room_goto_resize() directly after that for it to have an effect.
Otherwise the view won't resize which can lead to your game being displayed in the top left corner of the much larger screen.

scr_texture_set_interpolation(interpolation): Use this instead of texture_set_interpolation()!
Sets 'interpolate colors between pixels' without blurring the resized surface.
It's off by default because usually hard pixels is what you want if you use this.

-----------------

The next few scripts are specifically for while-loops that freeze the game and do some drawing within them (pause menus and such).
If your game doesn't do that, you won't need them.

scr_screen_redraw(): Completely replaces screen_redraw()!
It draws the stretched surface to the screen or acts like the normal 'screen_redraw' if the system isn't active.

scr_resize_start_drawing()/scr_resize_stop_drawing(): For drawing when the game is frozen by a while loop (paused).
Use scr_screen_redraw() BEFORE calling scr_resize_start_drawing(), IF you use it to redraw the screen because everything between start and stop will be drawn to the surface to stretch it properly.
If you redraw the screen within that, it cancels that effect and your game suddenly becomes a tiny speck in the top left corner of the screen.
Call scr_resize_start_drawing(), draw the stuff, then call scr_resize_stop_drawing().
Keep in mind that this does NOT replace screen_refresh(), you still have to call that afterwards to update the screen.


Hope this helps someone.

Edited by 9_6, 26 September 2010 - 04:16 PM.

  • 2

#2 Anon

Anon

    GMC Member

  • GMC Member
  • 447 posts

Posted 24 December 2008 - 07:15 PM

Nifty.
I used it to replace the built in full screen function, and it works perfectly.
Only thing that would be better is commenting on your code, and saying which each function does.

Cool!
Anon
  • 0

#3 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 25 December 2008 - 06:49 PM

Update. See first post.
  • 0

#4 Fede-lasse

Fede-lasse

    AI Programmer

  • GMC Member
  • 2009 posts
  • Version:Unknown

Posted 26 December 2008 - 06:42 PM

Any screenshots?
  • 0

#5 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 26 December 2008 - 06:53 PM

You know this is no game but I added a 'screenshot' anyway so you can see what this is all about with one look.

Edited by 9_6, 26 December 2008 - 06:55 PM.

  • 0

#6 XpressO

XpressO

    GMC Member

  • New Member
  • 184 posts

Posted 28 December 2008 - 12:32 AM

This is very nice but wouldn't it be easier using views?
  • 0

#7 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 28 December 2008 - 01:10 PM

This is very nice but wouldn't it be easier using views?

Do you really think I wrote that sort of complicated stuff without being aware of viewports?
It even does resize the viewport to enlarge the window at some point! (and then sizes it back down to let the surface do the job)
I even mentioned viewports and their flaws in the first post!
It would be so much easier if it would be as simple as abusing the viewports but gamemaker is a total ***** with those because if you simply size up the viewport:

-tiles might be drawn with graphical errors (depends on the graphics card)
-primitives and circles are drawn in the high resolution which makes them stick out in a bad way
-it sometimes looks weird because of different sized pixels

The only way to get flawless resizing is through an upsized surface and this is why I wrote this system!

Edited by 9_6, 28 December 2008 - 01:17 PM.

  • 0

#8 edmunn

edmunn

    GMC Member

  • New Member
  • 1298 posts

Posted 05 January 2009 - 01:37 PM

Fantastic idea, and great execution.
  • 0

#9 TheMyst

TheMyst

    GMC Member

  • New Member
  • 166 posts

Posted 08 January 2009 - 05:14 PM

fffffffffffffffffffffffffffffffffffffffff, the links are broken! Think you can fix them mate? I could get alot of use out of these.

Edited by TheMyst, 08 January 2009 - 05:57 PM.

  • 0

#10 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 11 January 2009 - 10:11 AM

Since 64D deciced to die permanently and willhostforfood works again but ate my files, I've re-uploaded it to willhostforfood.
First link should work now. THe second will too... some day.
  • 0

#11 Schtauffen

Schtauffen

    GMC Member

  • New Member
  • 80 posts

Posted 13 January 2009 - 12:33 AM

Very nice 9_6 :(
  • 0

#12 toopz

toopz

    Spriter

  • New Member
  • 782 posts
  • Version:GM:Studio

Posted 13 January 2009 - 04:41 PM

This is awesome man. Pixel perfect, and it solves a weird glitch I've been getting from GM trying to scale games up on Vista. I'll be using this for sure.
  • 0

#13 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 13 January 2009 - 05:09 PM

Thanks.
A thing I've recently discovered is that -because it overwrites the view settings- gms native object following doesn't work if you set it to follow a certain object in the room editor.
Unfortunately there's nothing I can do about this because there seems to be no way to retrieve the view settings from rooms you're currently not in.
  • 0

#14 toopz

toopz

    Spriter

  • New Member
  • 782 posts
  • Version:GM:Studio

Posted 13 January 2009 - 07:32 PM

Yeah, I noticed that as well. I may have noticed a tile glitch when changing between rooms, but that may just because my game has become a huge beast code-wise, and I haven't gotten it all meshed together yet. I'll probably mess with it some more later today, and see if I can't find a way around those problems for me.
  • 0

#15 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 13 January 2009 - 10:32 PM

I may have noticed a tile glitch when changing between rooms

Wait what?
That's not supposed to happen. That's actually the whole purpose of this system.
How did it look? Did you just use tiles placed in the room editor?
Does the same happen when not resized? Screenshot of the glitch?
  • 0

#16 toopz

toopz

    Spriter

  • New Member
  • 782 posts
  • Version:GM:Studio

Posted 14 January 2009 - 05:54 AM

I was seeing lines between tiles. That said it was doing numerous strange things, such as scaling down instead of up when I changed rooms. I think it either has to do with me not changing room_goto() in all of it's previous uses, or persistence. I left it persistent, so it may not have the init stuff in the new rooms. Or it may be doubling up with other ones, since I forgot to create some code to destroy one when there's more than one. Come to think of it...that's probably why it scales down. I'll let you know sometime tomorrow how it goes when I try to fix it.
  • 0

#17 toopz

toopz

    Spriter

  • New Member
  • 782 posts
  • Version:GM:Studio

Posted 17 January 2009 - 06:05 AM

I finally got this to work (seemingly) perfectly with my game. It took a while for me to get certain things working, like changing all of my room_goto()'s to scr_room_goto_resize(), but I finally did. It also took me a while to figure out how to set the view to follow my player via the script; at first I was under the impression that this broke gm's native view handling.

Don't worry about the tile glitches, they were my fault. I found out in another random little test of mine that it was actually one of my rooms causing the glitch. Said room could not be modified by the room_set functions, which was causing the ports and other things to wig out whenever it attempted to. The solution in that case was to recreate the room.

Now that I got it fully working, this thing is amazing. I'll definitely be using this now!
  • 0

#18 Drewdelz

Drewdelz

    GMC Member

  • GMC Member
  • 1027 posts

Posted 25 January 2009 - 07:45 AM

EDIT: Had some problems, then realized I forgot to toggle the scaling... lmao Works now.

Thanks for the script, saved my game from an annoying glitch on some graphic cards that drew a gray grid between in-game tiles.
Good job. :D

Edited by Drewdelz, 25 January 2009 - 08:33 AM.

  • 0

#19 Drewdelz

Drewdelz

    GMC Member

  • GMC Member
  • 1027 posts

Posted 11 February 2009 - 03:51 AM

I seem to be getting a weird error when switching rooms. :/
For some reason, it randomly decides to not 2x scale certain rooms when switching to them. It seems completely random, and I can't predict a pattern with the error.

And no, I'm not using room_goto, so I have no idea why it's doing this. . .

Any ideas?
  • 0

#20 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 11 February 2009 - 06:08 PM

Well I have no idea.
Maybe you could pm me the source so I can see what you're doing?
  • 0

#21 Drewdelz

Drewdelz

    GMC Member

  • GMC Member
  • 1027 posts

Posted 14 February 2009 - 08:06 AM

nvm, I'm an idiot. I didn't realize you had to call "scr_toggle_resize(w,h)" everytime you transfered rooms. lol
Why not just have it the room_goto script then? I mod'd it into it myself now, since I want it resized at all times.
  • 0

#22 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 14 February 2009 - 07:23 PM

you don't need toggle resize all the time!
You must be doing something wrong, you only call the toggle script if you want to -as the name says- toggle the resizing and call scr_room_goto right after it to have an effect.
You must be calling the toggle script somewhere else if calling it again 'fixed' the problem.
  • 0

#23 Drewdelz

Drewdelz

    GMC Member

  • GMC Member
  • 1027 posts

Posted 15 February 2009 - 10:11 AM

you don't need toggle resize all the time!
You must be doing something wrong, you only call the toggle script if you want to -as the name says- toggle the resizing and call scr_room_goto right after it to have an effect.
You must be calling the toggle script somewhere else if calling it again 'fixed' the problem.


Oh.
I don't really see how, but I guess that must be what's going on. O.o

Oh well, as long as it works.
  • 0

#24 Magdiel

Magdiel

    GMC Member

  • New Member
  • 161 posts

Posted 02 March 2009 - 04:01 PM

This is really useful =D
  • 0

#25 necKro23

necKro23

    GMC Member

  • New Member
  • 2 posts

Posted 05 June 2009 - 04:02 AM

Am I the only one having huge problems with this script? Neither the example GM6 file nor trying to implement the script in my own program is working properly at all (under GM7).

With the example, running it without changing anything shows the sample graphic at 1:1 size in the corner of a larger window. Toggling resize just makes the window the same size as the graphic. If I set the game to run fullscreen, toggling resize does fill the screen with the graphic, but it's blurry.

Putting it in my own program, it seemingly doesn't have any effect at all (GM interpolates the screen as usual).

Can someone shed some light on this?
  • 0

#26 UltimateWalrus

UltimateWalrus

    GMC Member

  • New Member
  • 2 posts

Posted 27 June 2009 - 01:54 AM

Am I the only one having huge problems with this script? Neither the example GM6 file nor trying to implement the script in my own program is working properly at all (under GM7).

With the example, running it without changing anything shows the sample graphic at 1:1 size in the corner of a larger window. Toggling resize just makes the window the same size as the graphic. If I set the game to run fullscreen, toggling resize does fill the screen with the graphic, but it's blurry.

Putting it in my own program, it seemingly doesn't have any effect at all (GM interpolates the screen as usual).

Can someone shed some light on this?


I think you have to go into the "Create" script and change scr_resize_init to scr_resize_init_gm7.
  • 0

#27 UltimateWalrus

UltimateWalrus

    GMC Member

  • New Member
  • 2 posts

Posted 27 June 2009 - 02:29 AM

This is awesome! You are awesome! Thanks a bunch!

I'm glad I'm not the only one who notices that Game Maker's full-screen mode looks like crap.
  • 0

#28 deformed thought

deformed thought

    GMC Member

  • GMC Member
  • 133 posts
  • Version:GM7

Posted 17 August 2009 - 06:39 PM

all it seems to do is resize the room...
  • 0

#29 Yal

Yal

    Gun Princess

  • Global Moderators
  • 8168 posts
  • Version:GM:Studio

Posted 13 November 2009 - 10:59 AM

I'll download this to make Gun-Princess work better on those graphic cards too many people seem to get nowadays (got tipped off about your solution by Head Removalist)... one question, wouldn't setting the monitor size, drawing region size, and view size to the same values, avoid this problem? At least, I think it works on electron beam based screens, but for flat and liquid crystal ones, I can't tell. This guy in my topic said something about bilinear upscaling, but I don't know what that is (english's my second language).

Anyway, I'll try download this. It seems very quite complicated to implement / adapt (the game I will use it for is a huge project; it has already near 200 rooms. I researched how to make a stage editor just to minimize the .exe size by having external rooms, but it's always more work changing stuff you've made before than just append something new)... so I'm asking, is there a simplier soloution (like the one I suggested, resizing the monitor to match the view) that would be easier to implement, but have a con (in this case, changing the monitor resolution - the actual method - would count as one, since windows open while playing would be resized by the swap) that might put people off?
  • 0

#30 9_6

9_6

    Guest

  • GMC Member
  • 3627 posts

Posted 17 November 2009 - 03:47 PM

Sure, you can also scale up the viewport for the same-ish effect but it'll glitch out and look completely messed up on some computers and vector drawings like draw_line will work in another, higher, actual screen resolution which looks out of place so it's not really a reliable solution.
The only other option is to mess with the resolution.
Now while this gets the job done pretty well, gamemaker likes to mess with more than just the the resolution, it also resizes windows, re-positions desktop icons and all that fun little stuff which is pretty painful for most people.
On top of that, if the game crashes, the computer is also stuck in the set resolution and you have to change it manually.
You have a lot of fun doing that when the resolution has been set to something like 320x240 so this is pretty much a no-go.

I wish there was a simpler method that works reliably, believe me I searched, but it looks like this issue is regarded as such a minor thing that not even gamemaker 8 will finally come with a native fix for this...

Edited by 9_6, 17 November 2009 - 03:55 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users