
Noob problem: Viewport clipping
Posted Wednesday, 6 May, 2009 - 12:11 by Jonas B inHi,
just started experimenting with OpenTK - seems like a very nice API!
I haven't worked with OpenGL before, and only superficially with other 3D APIs and engines (using them for 2D rendering mainly), so I'm not that good with the concepts.
I have a scene set up using the GameWindow, with orthographic projection, to which I render textured quads. Everything looks good, but the quads are only rendered in a (square) portion of the window, and are clipped outside of it.
I think it's set up properly, basically:
w = window width, h = window height
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Ortho2D(0,w,0,h);
GL.Viewport(0, 0, w, h);
Seems like the clipping occurs at approximately w/2 for both width and height.
Anything obvious I have missed here?
Thanks!


Comments
Re: Noob problem: Viewport clipping
Edit: I think the problem is that you specify the viewport after the projection matrix, not before.
Does this only occur always, or only when you change window size? If it's the latter, you should hook the Resize event and execute the code you listed.
I tend to use something like the following:
Re: Noob problem: Viewport clipping
Thanks for the quick answer!
Tried changing the order, but same result - however, after resizing the window manually (by just 1 pixel) it works properly! It occurs to me now that I do my setup directly after the GameWindow's construction, I don't wait for the Load event, which I know is a big no-no. My initialization is a bit complicated, that's why I didn't notice it before
Will try changing that and report back!
Re: Noob problem: Viewport clipping
To initialize on Load didn't make any difference - but when I programmatically re-set the size (to the same size it already is), it works fine!
Re: Noob problem: Viewport clipping
Interesting, the window Width and Height are supposed to be set before the Load event fires. I will have to ensure this works reliably in the gw-next branch.