glViewport/glOrtho problem?

I have a resizable window programmed into my game, and oddly enough, the coordinate (0,0) isn’t at the upper left of the screen when it’s maximized. Here’s a screenshot:

http://img13.imageshack.us/img13/6024/newbitmapimagemj.png

The mugshot of player should be in the corner, because it’s translated to 0,0 every step. Obviously, it didn’t move to the corner, so what’s up?

The viewport is reset in the “core” of the game, like this:

			glViewport(0, 0, Display.getWidth(), Display.getHeight());
			glClearColor(0,0,0,1);
			glClearDepth(1f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

and the ortho projection is elsewhere, (after the above, though)

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -CAMERA_NEARFAR, CAMERA_NEARFAR);
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

I’m at wits end, not exactly sure why he won’t draw in the corner, even after my demands to go there.

Are you resizing glViewport/glOrtho every time the game window is resized? Use Display.wasResized.

I managed to fix it. It seems that another transformation earlier was affecting it, even though I popped the matrix. Thanks anyway, though!

Okay, so I have another problem;

so let’s say, we have a viewport like this:

glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -CAMERA_NEARFAR, CAMERA_NEARFAR);

And, we place a quad at these coordinates:

int x = 0; int y = 0; int z = CAMERA_NEARFAR - 3;

DEPTH_TEST is functional, along with everything needed to make it work, other objects it works fine with it.

Now, my problem is, I have that quad placed there, but drawing anything ANYWHERE after it is drawn over, and Alpha/Z isn’t taken into consideration.
Here’s what I mean:

http://desmond.imageshack.us/Himg339/scaled.php?server=339&filename=3bda4759d5917503525423a.png&res=landing

The code after all of this initialization that draws the above uses glPushMatrix(); glLoadIdentity(); Draws then glPopMatrix();

So, it does this:
DrawMugshot at Z = CAMERA_NEARFAR - 3;
DrawBubble at Z = glTranslatef(0,0,1);
DrawBackSlider at Z = glTranslatef(0,0,-3);

and I get the pictured effect with DepthTesting enabled.

I would just leave it off for this situation but I NEED to know what’s wrong.

I did notice if I placed it’s Z below 10 it worked fine.

Please help. This is bothering the absolute shit out of me.

It’s 100% normal. Depth testing doesn’t care about what color it’s actually drawing.

The main problem is that blending does not work with depth testing. Something you can do is enable alpha testing, which discards pixels that do not have enough alpha, but it has to be used instead of blending. The problem is that the z-buffer only tracks the closest pixel, so if you draw transparent stuff in the wrong order it will be unable to blend it in the correct order. While alpha testing allows you to discard pixels completely transparent pixels, it still doesn’t really solve this problem since it will not allow you to have antialiased edges or semi-transparent surfaces. The best solution is probably to sort everything on the CPU, at least for a 2D game.

Well it’s odd because this works perfectly fine everywhere else, like I could draw the player in the same position and he’d work fine, just the GUI is being weird about this.

I think I’ll leave on Blending for drawing the entities, and just turn it off and do it the retarded way with the GUI like I did in the picture.

Normally you wouldn’t have depth testing enabled when drawing the GUI.

Oh? Cool then. I’m doing right. That’s even better.
It’s really odd doing the “draw first, draw over,” thing after all of this time, though. Hahah

I didn’t want to make a new thread for such a small question, so sorry for jacking yours

I draw a line that is x1 = 0, x2 = 800, so it spans 800 width across my window(display), which is also 800. Then I resize the window, to say 1000. I then figure I have 200 pixels of extra space, so I do
glViewport((width-800)/2,0,800,height) (I’m just ignoring Y for now, keeping it constant; also I use floats and finally cast to an int for accuracy)

I figured this would move the 800 line to the center of the new window, but for me it is slightly off center (too far to the left) and also its been squashed inwards horizontally a bit. What am I missing?

Well, you need to be sure to recall the perspective too along with your viewport or else it’s going to stretch.
That’s all I got.

glViewport() defines the part of the window that OpenGL can draw to. glOrtho() and gluPerspective() should not take the parts outside the viewport into account.


glViewport(100, 100, 800, 600);
glOrtho(0, 800, 600, 0, -1, 1); //Ignore that the viewport is offset by (100, 100)

That the screen is distorted could be due to an incorrect aspect ratio supplied to gluPerspective().