Author Topic: Ingame Zooming  (Read 8423 times)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Ingame Zooming
« 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?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Ingame Zooming
« Reply #1 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).  Besides GL.LoadIdentity, there is also GL.LoadMatrix (http://www.opengl.org/sdk/docs/man/xhtml/glLoadMatrix.xml, http://pastebin.com/PgW20psp).  Let me know if you get anywhere with this, or get stuck.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Ingame Zooming
« Reply #2 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. :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Ingame Zooming
« Reply #3 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

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Ingame Zooming
« Reply #4 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

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.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Ingame Zooming
« Reply #5 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)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Ingame Zooming
« Reply #6 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 :)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Ingame Zooming
« Reply #7 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.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Ingame Zooming
« Reply #8 on: 2011-06-02, 02:13:47 PM »
Yeah!!!  Great news! :)  Tell me what you think of the game when you get the time. :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Ingame Zooming
« Reply #9 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.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Ingame Zooming
« Reply #10 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.)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Ingame Zooming
« Reply #11 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

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...
« Last Edit: 2011-06-09, 08:24:54 PM by Pizzaman »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Ingame Zooming
« Reply #12 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.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Ingame Zooming
« Reply #13 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.  :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Ingame Zooming
« Reply #14 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