Hello Guest

setResizable and Graphics Remaining in Correct Place

  • 8 Replies
  • 5574 Views
setResizable and Graphics Remaining in Correct Place
« 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


Dragging top up


Draggin top down


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?
« Last Edit: January 18, 2013, 06:36:24 by adamk33n3r »

Re: setResizable and Graphics Remaining in Correct Place
« Reply #1 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.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: setResizable and Graphics Remaining in Correct Place
« Reply #2 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
Code: [Select]
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
Code: [Select]
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.
« Last Edit: January 18, 2013, 06:36:00 by adamk33n3r »

*

Offline princec

  • *****
  • 1932
    • Puppygames
Re: setResizable and Graphics Remaining in Correct Place
« Reply #3 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 :)

Re: setResizable and Graphics Remaining in Correct Place
« Reply #4 on: January 18, 2013, 17:09:42 »
So I did this
Code: [Select]
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
Code: [Select]
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

Re: setResizable and Graphics Remaining in Correct Place
« Reply #5 on: January 21, 2013, 22:00:56 »
Anyone have an idea on what's wrong with fullscreen?

Re: setResizable and Graphics Remaining in Correct Place
« Reply #6 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.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: setResizable and Graphics Remaining in Correct Place
« Reply #7 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
« Last Edit: January 23, 2013, 23:10:52 by adamk33n3r »

Re: setResizable and Graphics Remaining in Correct Place
« Reply #8 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?