Scrolling Game Development Kit Forum

SGDK Version 2 => Help, Errors, FAQ => Topic started by: v6v on 2011-05-27, 10:57:47 PM

Title: Ingame Zooming
Post by: v6v on 2011-05-27, 10:57:47 PM
Hey, on developing a game and experimenting with resolutions, i wondered, is there and way to zoom in and out ingame? maybe some sort of screen manipulation?

Has anyone else tried to do this?
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-05-28, 06:55:14 AM
I haven't tried, but there is code in Display.cs in the OnResize function that is probably very close to something you could use to zoom in/out.  GL.Ortho determines the clipping rectangle I guess, and GL.ViewPort determines how coordinates are transformed onto the display (http://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml (http://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml)).  Besides GL.LoadIdentity, there is also GL.LoadMatrix (http://www.opengl.org/sdk/docs/man/xhtml/glLoadMatrix.xml (http://www.opengl.org/sdk/docs/man/xhtml/glLoadMatrix.xml), http://pastebin.com/PgW20psp (http://pastebin.com/PgW20psp)).  Let me know if you get anywhere with this, or get stuck.
Title: Re: Ingame Zooming
Post by: Vincent on 2011-05-30, 06:25:09 AM
Hi Pizzaman,

You can take a look at the source code of Legacy of Kain: Revival.  I do something very similar in my game.  (resize the display window to zoom in the game)  It should be quite easy to adapt to your code.  I used exactly what bluemonkmn is talking about. :)
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-01, 11:58:20 AM
Ah Ok thanks. I was actually going to wait until I had completed more but this might expedite zooming in my game. The only issue is LOK didnt work on my PC,After I tried compiling it in 2.1.9.... GL issues and such, but I will have to look into that. Another slightly off topic thing.... I get errors when trying to use FollowMouse on a sprite and the mouse isnt in the window- (To the left of the display before 0,0, Moving to the left past the window crashes). Desperately trying to solve this I havent  been able to solve it, Although the Error Reporting says it's an "If" IsOnTile error, the IsOnTile condition is vital to the gameplay process. PushSpriteIntoView also yieds no favorable results... I can recall getting this error 3 years ago when I was using Sgdk2, and the solution was using FullScreen, but the game Im making now is more favorable windowed. I hope theres no rule against posting something unrelated in a Topic ;p
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-01, 02:48:12 PM
It's probably necessary to manually apply the changes to the project source code (display.cs) that were introduced to fixed the OpenGL compatibility problems.  You can see those changes here:
http://sgdk2.svn.sourceforge.net/viewvc/sgdk2/trunk/SGDK2IDE/Template/Display.cs?r1=177&r2=185 (http://sgdk2.svn.sourceforge.net/viewvc/sgdk2/trunk/SGDK2IDE/Template/Display.cs?r1=177&r2=185)

Otherwise old projects continue to use their old source code.  Normally you could simply reset the source code, but LOK Revival has customizations in Display.cs so you would have to apply the changes manually to avoid losing the customizations.
Title: Re: Ingame Zooming
Post by: Vincent on 2011-06-02, 06:22:00 AM
As bluemonkmn said, you should do a code reset on Lok: Revival.  The changes I made are identified by my name, so there are easy to reproduce.  It might solve all your openGL problems with Lok: Revival. (hopefully)
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-02, 11:47:38 AM
Whoa... I feel like a noob for not knowing that. It worked! Which also means all the other projects I desperately wanted to play now work in 2.1.9 (Like the NetGameSample :)) The SplashScreen remains while loading music 12 but its not that big of an issue. Thanks! Now back to working on my stuff :)
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-02, 01:22:43 PM
Woohoo!  Glad it worked.  Playing the game is probably a lot better than watching a video of it.  Just remember to go to the options (while playing) and increase the screen size, so you don't have to play it in such a small window.  BTW, I have noticed that sometimes the splash screen goes away and sometimes it doesn't.  If you're lucky, when you try again, it will go away.
Title: Re: Ingame Zooming
Post by: Vincent on 2011-06-02, 02:13:47 PM
Yeah!!!  Great news! :)  Tell me what you think of the game when you get the time. :)
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-02, 02:58:39 PM
Yeah, its an amazing game! I was like OOOOO Im gonna do some Vampire Stuff but I got to this guy throwing Water Bottles at me and I died Twice lol. Its a fun game and Im still trying :). Love the Graphics and Music. The Options Menu for changing Screen Res for my PC only resizes the Window, Not the Actual Game lol  but its not an issue, the game works and as long as I can play it, its fine. Awesome game, Vincent.
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-03, 05:10:09 AM
To fix the game, did you simply reset the source code, or did you manually apply the changes as I suggested?  If you reset the source code, did you re-apply the changes Vincent had made to it?   If not, that could explain why the game doesn't resize with the window.  (Another explanation could be that I didn't fix 2.1.9 with that consideration in mind.)
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-09, 07:16:51 PM
I added/enabled Lighting and Ive been playing around with GL.Ortho... it zooms in certain areas but I cant get it to Pinpoint The Area in the Center of the Screen i need to Zoom into.

Code: [Select]
        GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate);
         GL.Enable(EnableCap.Blend);
         GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
         GL.Disable(EnableCap.PolygonSmooth);
         GL.Enable(texCap);
         GL.Disable(EnableCap.DepthTest);
        
        


GL.Ortho(-0.9999, /*2nd */1.0, -1.0, 0.9999, /*2nd */-1.0, 1.0);

GL.Light(LightName.Light0, LightParameter.Position, new float[] { 1.0f,1.0f, 1.0f });
GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 0.9f, 0.9f, 0.9f, 1.0f });
GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 1.0f, 0.5f, 0.5f, 1.0f });
GL.Light(LightName.Light0, LightParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Light(LightName.Light0, LightParameter.SpotExponent, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 0.9f, 0.9f, 0.9f, 1.0f });
GL.LightModel(LightModelParameter.LightModelTwoSide, 0);
GL.LightModel(LightModelParameter.LightModelLocalViewer, 0);
GL.Enable(EnableCap.Lighting);GL.Enable(EnableCap.Light0);
GL.Material(MaterialFace.Front, MaterialParameter.Ambient, new float[] { 0.9f, 0.9f, 0.9f, 1.0f });
GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Material(MaterialFace.Front, MaterialParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
GL.Material(MaterialFace.Front, MaterialParameter.Emission, new float[] { 0.9f, 0.9f, 0.9f, 1.0f });




@ Display.cs inside DrawFrame() right after Disabling DepthTest

And THIS: is the Result
http://www.youtube.com/watch?v=kXvLUh1pAhs (http://www.youtube.com/watch?v=kXvLUh1pAhs)

Not that big of an issue, my only concern is fixing those ugly lines between the textures. Seems that they dont appear when Gl.Ortho is only given an int, but, if given a double or float (Which is actually what gives the nice little zooming in effect) It has those ugly lines between the textures. I tried toying with PolygonSmooth and Dither... It doesnt matter as much as getting the game to Zoom in the center of the display, as much as finding a way to get rid of those ugly lines...
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-10, 05:06:29 AM
Were there lighting effects visible in that video or just zooming?

I think Vincent had problems with the lines too, and somehow got past them... maybe because he always used integers.
Maybe if you expand corners[] to be half a pixel larger or something the lines would go away.
The corners array is usually an array of points that forms a rectangle, but if you have a tile that is using a transformed frame, then it wouldn't be.  But it might be worth playing with just to see what happens.

Also, I know GDI+ has some pixel rounding mode thing; I wonder if OpenGL has something similar.  If it does, I can't find it.
Title: Re: Ingame Zooming
Post by: Vincent on 2011-06-10, 05:42:53 AM
Pizzaman: if you only reset the source code of Lok: revival without reapplying all the changes I did: the game will have many bugs and might crash.  I suspect you didn't reapply my changes, otherwise zooming would work with the window resize (since the Gl.Canvas is supposed to be docked inside the game window).  Thanks for your comments! :)

I had the same problems with lines during zooming.  I had to specify exact factors to avoid them.  it's okay if you zoom at factor x2, x3 or x4.  These are the options in LoKR.  I don't remember if I did other fixes, but if yes they are in LokR source.  :)
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-10, 08:58:35 AM
Yeah, Im going back to do that now, that whole **Added By Vincent** Comment Blocking helps alot :), And yeah Bluemonkmn, he lighting effects were present in the game. I enabled lighting to have better control of lighting ingame, rather than having to make tiles that darken. (EX Caves and Torches and Stuff) Im still looking into the DepthBuffer, I want to have some sort of 3D lighting, and I also need to look into light sources (Like Spotlights). Ah lots to do, lots to do. Ironically, applying all of the changes combined with the new code crashes my the game with a fatal error at Display.cs preventing game startup.... but that may just be MY computer. Ill try to look into the corners[] array. Thanks for the help and I'll come back with my results
Title: Re: Ingame Zooming
Post by: Vincent on 2011-06-11, 07:31:04 AM
I really had no choice to comment these blocks.  I upgraded SGDK2 version a couple of times during the project and I had to figure out a way not to forget any of my changes.  :)

I can't wait to see those light effects.  It would be an interesting addition to SGDK2!
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-11, 11:57:11 AM
yeah, the light is nice, but Im not even sure If I can add it in the game, it conflicts with a Sprites ModulateAlpha. When I use light, every sprite has an alpha of 255, no matter what its set to. Message Boxes behave the same way. I think Ill just enable lighting at night, and keep it dark for light sources. I dont see the use of it in the daytime especially with the above side effects.

EDIT: Found a reference... http://docs.mono-android.net/OpenTK.Graphics.ES20.EnableCap/Members (http://docs.mono-android.net/OpenTK.Graphics.ES20.EnableCap/Members) It has SOME members for enablecap... but I still kind of feel like Im missing some things... I tried GL.Enable(EnableCap.AlphaTest); with no good results
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-12, 07:07:09 AM
Were there lighting effects visible in that video or just zooming?
And yeah Bluemonkmn, he lighting effects were present in the game.

I can't see the lighting effects in that video.
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-12, 07:09:01 AM
Are you planning on doing lighting per tile or per pixel?  If you're just doing lighting per tile, would it make sense to have a layer in front that has black tiles with varying alpha to implement the lighting?
Title: Re: Ingame Zooming
Post by: v6v on 2011-06-12, 12:21:45 PM
Sorry about that, This is a video of all the lighting "effects" I have so far... This should how somewhat of a contrast between the effects Ive made. Im still trying to wrap my head fully around lighting. Its a pretty intresting thing.

http://www.youtube.com/watch?v=e8M5rNQUfYY (http://www.youtube.com/watch?v=e8M5rNQUfYY)

And I see what you mean with the layer with varying alpha... Im just trying to figure out how to make a sprite/tile on one layer Specifically change the alpha of certain tiles on another layer..

If the lighting effects you were looking for were torches and lightbulbs... I havent released (or even finished) that yet :/

Edit: Learned yet another GL function that could have saved me time... GL.Viewport... seems it does Zooming just as good, if not even better than GL.Ortho
Title: Re: Ingame Zooming
Post by: bluemonkmn on 2011-06-13, 05:18:44 AM
Learned yet another GL function that could have saved me time... GL.Viewport... seems it does Zooming just as good, if not even better than GL.Ortho

That was one of the functions I posted in my first post of this thread, right next to GL.Ortho.
Title: Re: Ingame Zooming
Post by: v6v on 2012-03-24, 06:36:40 PM
If anyone is interested in doing this, it follows either GL.Ortho and GL.Translate.

To get rid of the HIDEOUS gaps between the textures you can't use Linear in TexMin/Mag Filter, rather, you must use Nearest.

This however, will bring out any graphics that aren't aliased- so keep it in mind.  ???