Take the 2-minute tour ×

I am having some trouble with full screen mode. I can set my window to be 800x600, but when I full screen that resolution, it stretches. I assume this is because of a change in aspect ratio. How can I fix this?

Edit #1

Here's a screen shot of what I see happening.


Left: 800x600

Right: 1366x768

Edit #2

My initGraphics function gets called every time I re-size the window (WM_SIZE).

void initGraphics(int width, int height) {
    float aspect = (float)width / (float)height;
    glViewport(0, 0, width, height);
    glEnable(GL_BLEND); //Enable alpha blending
    glClearColor(0.0, 0.0, 0.0, 1.0);
    gluOrtho2D(0.0, width, height * aspect, 0.0);
share|improve this question
What does your projection matrix look like? –  Thomas Jun 5 '12 at 5:24
add comment

2 Answers

up vote 4 down vote accepted

SOLUTION: The real problem ended up being that you were misusing the gluOrtho2D function. Instead of using this:


You needed to switch it to the correct form this:

gluOrtho2D(0.0, width, 0.0, height);

The latter creates a 2D orthographic projection, that fills the entire width and height of your viewport, so no stretching occurs.


You need to modify your projection in order to account for the new aspect ratio.

Make sure you first of all set glViewport to the new window size. After the viewport is set you will need to switch your matrix mode to projection with a call to glMatrixMode and then finally calculate your new aspect ratio with width / height and pass the new aspect ratio to gluPerspective. You can also use straight glFrustum instead of gluPerspective you can find source to gluPerspective to achieve that same effect with glFrustum.

Something like this:

    float aspectRatio = width / height;
    gluPerspective(fov, aspectRatio, near, far); 
share|improve this answer
don't forget a glLoadIdentity() or the projection matrix might apply the perspectives on top of each other –  cobbal Jun 5 '12 at 5:34
@cobbal good point ill add that –  Justin Meiners Jun 5 '12 at 5:34
I am using Ortho, but it's the same process. –  Storm Kiernan Jun 5 '12 at 16:48
@Storm Kiernan so with glOrtho I thought you just say glOrtho(0, width, 0, height, near, far) and that will take care of all aspect ratio –  Justin Meiners Jun 5 '12 at 19:23
@JustinMeiners but why I am I getting stretching? Is that normal? I am new to this, so I don't know exactly what I should be looking for here, but it seems that stretching would be bad. –  Storm Kiernan Jun 5 '12 at 20:30
show 5 more comments

After resizing the window, you need to adjust your projection matrix to reflect the new aspect ratio. If you're using classic OpenGL, switch the matrix mode to GL_PROJECTION, load the identity matrix, then call glOrtho or gluPerspective with the vertical dimension scaled by the aspect ratio (assuming you want the horizontal spread of the image to be the same as it was with the original window).

share|improve this answer
I'm doing this, but I don't see any results. gluOrtho2D(0.0, width, height * (width / height), 0.0); –  Storm Kiernan Jun 5 '12 at 5:45
Just a guess--are height & width integers? You probably want to cast one or both to doubles before computing that fraction or you'll likely end up mutiplying by 1. –  Drew Hall Jun 5 '12 at 5:51
No difference. The images just stretch in whatever direction i size the window. –  Storm Kiernan Jun 5 '12 at 6:08
I updated my original post to show a screen shot of what I see happening. –  Storm Kiernan Jun 5 '12 at 16:46
add comment

Your Answer


