Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved]glOrtho and window size  (Read 3267 times)
0 Members and 1 Guest are viewing this topic.
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Posted 2012-04-17 22:07:54 »

I'm attempting to make my LWJGL window resizeable. When  I draw, lets say a quad, I get the middle of the drawing area, then for a 100x100 quad I go 50 left, 50 up, and so on for the other points. (I have set my window up to have (0,0) bottom left, (800,600) top right)

1  
2  
3  
4  
5  
glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0,width,0,height,1,-1);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_TEXTURE_2D);


width = 800 height = 600

Then if(Display.wasResized())

I work out how much it has been resized, calculating a float called scale, and In my render loop I 'draw(scale);' so everything can be resized. So x co-ords are calculated:
1  
2  
middlex - (scale*50)
middlex + (scale*50)
(I take into account it may of been increased in width and not height etc).

This works perfectly, except it cannot draw beyond 800 width, I'm believe because of the clipping plane set by
1  
glOrtho(0,width,0,height,1,-1);
with width = 800. Its at this point I would like to re-run glOrtho() with the new width and height, but when I do this, its stops working perfectly, and starts drawing in crazy places (I have printed the floats it is trying to draw at, they are correct at least for how I would like it drawn with 0,0 as the origin)

Is changing the window size a problem, and how can I re-run glOrtho()? I feel like doing it twice is causing some effect I've overlooked...
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2012-04-17 22:32:24 »

Are you remembering to switch back go GL_PROJECTION, clear it with glLoadIdentity(), then call glOrtho() and finally switching back to GL_MODELVIEW?

Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Reply #2 - Posted 2012-04-17 22:40:44 »

Aye, this is the block of code used after I get the new height and width

1  
2  
3  
4  
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0,width,0,height,1,-1);
        glMatrixMode(GL_MODELVIEW);
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-04-17 23:21:00 »

Don't forget to reset the viewport too:
1  
GL11.glViewport(0,0,width,height);

Offline lhkbob

JGO Knight


Medals: 32



« Reply #4 - Posted 2012-04-17 23:40:26 »

Yes you will want to update the viewport if LWJGL doesn't take care of that for you.  If this wasn't happening, it would explain why things were being clipped when you'd scale the window up.

Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Reply #5 - Posted 2012-04-17 23:55:18 »

Thanks, viewport solved the problem
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 22:13:29

Pippogeek (31 views)
2014-09-24 22:12:22

Pippogeek (21 views)
2014-09-24 22:12:06

Grunnt (47 views)
2014-09-23 20:38:19

radar3301 (29 views)
2014-09-22 05:33:17

BurntPizza (65 views)
2014-09-21 08:42:18

BurntPizza (37 views)
2014-09-21 07:30:30

moogie (44 views)
2014-09-21 06:26:15

UprightPath (53 views)
2014-09-21 02:14:06

BurntPizza (55 views)
2014-09-19 09:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!