LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: adamk33n3r on January 17, 2013, 06:01:51

Title: setResizable and Graphics Remaining in Correct Place
Post by: adamk33n3r on January 17, 2013, 06:01:51
So I was experimenting with the setResizable function and when I resize the window horizontally it seems to be drawing fine (except for some reason the window gets 22px taller but that's another issue) but when i resize the window vertically things start messing up. The coordinate system is not moving vertically so when I drag the top of the window up, the things that I am drawing at a y of 100 stay put when they actually should be moving up with the window to stay 100 away. This doesn't happen when i drag the left side. It follows that side fine. Also if I drag the top window down it will cover over the renderings.

Anyone know what I am doing wrong?

Here are some screenshots (ignore the bottom menu's location. just referring to the Welcome message and the yellow box)
Default size
(http://i1167.photobucket.com/albums/q628/adamk33n3r/ScreenShot2013-01-17at04904_zps562baa6f.png)

Dragging top up
(http://i1167.photobucket.com/albums/q628/adamk33n3r/ScreenShot2013-01-17at04936_zps84b30020.png)

Draggin top down
(http://i1167.photobucket.com/albums/q628/adamk33n3r/ScreenShot2013-01-17at04943_zps5438b12f.png)

EDIT:

I started messing with fullscreen as well and I found some things out. If I change to fullscreen and dont change size at the same time everything works right. But if I change to fullscreen and change the size then the same behavior occurs with the drawing scales messed up. e.g. if I go from 800x600 windowed to 1680x1050 fullscreen the drawing is the same scale but drawn in the lower left corner. What does this mean?
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: Fool Running on January 17, 2013, 13:54:02
Some code would help.

Without code, I would guess you are not calling glViewport() (most likely) and/or glScissor() (less likely) when the size changes.
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: adamk33n3r on January 18, 2013, 06:31:11
I did some research earlier and found that someone said to do that. I added that part right after setting a new displaymode and it made the horizontal resize mess up and the vertical resize slightly better but it is still not 100px from the top. If i shrink the window vertically the welcome message gets closer to the top. I am willing to put some code up I just didn't know which would be the most helpful so here is some.

In the main update() function
if (Display.wasResized()) {
   width = Display.getWidth();
   height = Display.getHeight();
   glScissor(0, 0, width, height);
   glViewport(0, 0, width, height);
}


This is at the end of my setDisplayMode() function that I call when switching to fullscreen
Display.setDisplayMode(targetDisplayMode);
Display.setFullscreen(fullscreen);
glScissor(0, 0, width, height);
glViewport(0, 0, width, height);


Let me know if you would like any more code.

EDIT: Also, when I resize, the objects are stretching. They should be the same size, just moved around.
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: princec on January 18, 2013, 11:49:01
You also need to set your projection matrix to a new projection that keeps the graphics orthographic with the viewport (glOrtho)

Cas :)
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: adamk33n3r on January 18, 2013, 17:09:42
So I did this
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width, height);
glScissor(0, 0, width, height);
glOrtho(0,width,height,0,1,-1);
glMatrixMode(GL_MODELVIEW);

and it worked great for resizing. The problem was that when I added glOrtho I was trying to keep it at a 800x600 res so that my rendering would be in the same res but I didn't realize that that would be the cause of the stretching haha. I understand now.

One thing that still doesnt work, though, is fullscreen. If I ever do Display.setFullscreen(true); after the glViewport,Scissor, and Ortho set to a res of 1680x1050 everything is rendered in a 800x600 box in the lower left corner. Is there something special I need to do for fullscreen?

Thanks princec
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: adamk33n3r on January 21, 2013, 22:00:56
Anyone have an idea on what's wrong with fullscreen?
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: Fool Running on January 23, 2013, 13:25:41
I would guess the same thing. Going fullscreen is the same as resizing so you need to reset your viewport, etc.
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: adamk33n3r on January 23, 2013, 22:22:30
Well I have done that...I put the same code there that I put in the resizing. That's why I'm so confused ???
Like if I comment out the Display.setFullscreen() it works fine

EDIT: Also it is only when resizing and fullscreening because if change to 800x600 fullscreen it renders fine so idk
Title: Re: setResizable and Graphics Remaining in Correct Place
Post by: adamk33n3r on January 24, 2013, 02:37:15
BREAKTHROUGH!!! I just tried changing the size after pushing 'f' and then setting it to fullscreen after the second 'f' press....it works! Soooo...I'm thinking it must have to pass through a Display.update() first before changing? Does that make sense?