PDA

View Full Version : Pixel Perfect Plot



openfoobar
03-30-2013, 07:55 PM
I need to plot a pixel on the window, according to its position in pixels in integers, not floats. like, for example, if I was to plot 0, 0 it would be the very top left corner of the window, 1,1 would be one pixel to the right of 0, 0, and 1 pixel below 0. I guess what I need is it to be kind of like I grid. I don't care if 0, 0 is the origin like how it normally is, but I need it to count by pixels, not having 1 as the max and -1 as the min.

Things I have already tried: I thought I could just do something like this Window Width ^-1 * X for plotting, and that actually does work, but not all the time. Anyways, how would I go by doing this? I have also done X position / Screen Width, and that works the best, but it starts messing up for every 10 or so pixels.

float size = .0025; // = 1/400 (400 = width and height of window)

for(int i = -400 ; i < 400 ; i++)
{
glBegin(GL_POINTS);
glVertex2f(size * i, size * i);
glEnd();
}

What this code should so is draw a straight diagonal line across the screen, but it messes up.

Alfonse Reinheart
03-30-2013, 07:57 PM
Messes up in what way?

openfoobar
03-30-2013, 08:06 PM
Messes up in what way?

I'll post you a screen shot.
As you can see, it doesn't count up every pixel around the middle.

Edit: Never mind, it doesn't allow me to post URL's, I have no idea why not, but I can't visually show you. It should be a perfect diagonal line, but it isn't.

cireneikual
03-31-2013, 06:49 AM
Did you set up an orthographic projection matrix?

openfoobar
03-31-2013, 07:15 AM
Did you set up an orthographic projection matrix?

I've seen glOrtho, and gluOrtho2d in google, when I was searching how to do it, I guess I just don't know how to use it. I'm guessing that this code should put a 1x1 pixel in either the center of the window, or in the corner, but it doesn't do it.

glOrtho(0, 800, 600, 0, 0, 1);