🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lines at Edge of Viewport

Started by
3 comments, last by Keybot 17 years, 4 months ago
I'm trying to draw a one pixel border at the edge of a 20x20 Viewport using GL_LINES. The lines at the left and the bottom of the Viewport show up but the lines at the right and top of the Viewport aren't showing up. I thought maybe it has something to do with clipping but I'm not really sure. Anyone have any ideas on how to fix this?
Advertisement
What coordinates are you using, i bet they are variations of 0 and 20.
But the top right corner in an glViewport(0,0,20,20); is (19,19) not (20,20).

I'm using the following to set up the projection and the viewport:

glViewport(0, 0, 640, 480);
glOrtho(0.0f, 20.0f, 0.0f, 20.0f, -1.0f, 1.0f);

So the origin is in the bottom left of the window.

And I'm drawing the border lines with this:

//left
glVertex2i(0, 0);
glVertex2i(0, 20);

//bottom
glVertex2i(0, 0);
glVertex2i(20, 0);

//right
glVertex2i(20, 0);
glVertex2i(20, 20);

//top
glVertex2i(0, 20);
glVertex2i(20, 20);

The left and the bottom lines show up but the right and top lines don't.

Also, if I shift the right and the top lines by just 0.1 units they seem to show up but this doesn't produce a symmetrical border and is not what I want.
This is because you have a viewport of (640,480) and a ortho projection with a width and height of 21.
This means that each openGL unit in the x axis corresponds with 30,47619047619047619047619047619 pixels, not exactly a good number, so if you round that off to the nearest float and then multiply it with 21 you get a value slightly higher than 640 and that means it clips, try using glOrtho(0.0f, 19.0f, 0.0f, 19.0f, -1.0f, 1.0f); and likewise with the vertex coordinates.
Thanks!
You're so smart!

This topic is closed to new replies.

Advertisement