PDA

View Full Version : glViewport from top left, not bottom left



sol
06-19-2007, 07:51 PM
Bonjour.

The program I am writing is completely 2D. All
the math and logic assumes a coordinate system
where x = 0 is the left and y = 0 is the top of
the window.

The problem:

glViewport, which I expect to use a lot, in
various parts of the code, expects the y value to
be the bottom of the window. Sooner or later,
I'm bound to forget to adjust y and end up with
a blank screen or other hard to track down visual
error.

Essentially I'm looking for something like this:


void cam_viewport(int x, int y, int w, int h)
{
glViewport(x, adjust_y(y), w, h);
}Any ideas how this can be implemented? I'm sure
the solution is simple but I can't quite seem to
get it.

k_szczech
06-19-2007, 10:44 PM
glWievport(x, y - h, w, h);

sol
06-19-2007, 11:14 PM
Yes, I tried that and got a totally blank screen.

There's probably something suspect in my code
elsewhere.

sol
06-19-2007, 11:19 PM
If I do this:


void cam_viewport(int x, int y, int w, int h)
{
glViewport(x, y - h, w, h);
}

cam_viewport(0, 0, 640, 480);GL_INVALID_VALUE is generated by passing a
negative value to glViewport().

k_szczech
06-19-2007, 11:55 PM
Sorry, it should be:
glViewport(x, sh - y - h, w, h);
where sh = screen height (in pixels)

sol
06-20-2007, 12:07 AM
Yes, that's it.

Why I couldn't work this out alone, I'll never
know. I seem to be having one of those weeks.

Thank you.