setResizable and Graphics Remaining in Correct Place

Started by adamk33n3r, January 17, 2013, 06:01:51

Previous topic - Next topic

adamk33n3r

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?

Fool Running

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

adamk33n3r

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.

princec

You also need to set your projection matrix to a new projection that keeps the graphics orthographic with the viewport (glOrtho)

Cas :)

adamk33n3r

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

adamk33n3r

Anyone have an idea on what's wrong with fullscreen?

Fool Running

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

adamk33n3r

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

adamk33n3r

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?