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, or whatever.
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 stops working for every 10 or so pixels.
First of all, OpenGL doesn't guarantee pixel perfect placement in all cases. However, there is a very common gotcha: the center of each pixel will not have integer coordinates if you pixel coordinates.
Here's a diagram of the bottom-left pixel in an OpenGL viewport.
+Y
^
|
+-----+
| |
| o |
| |
+-----+---> +X
If your data is transformed so that each pixel has a width and height of 1 unit, then the center of the pixel is at (0.5, 0.5). If you draw a GL_POINT at that pixel, the coordinates should be (0.5, 0.5). If you draw a rectangle, it will go from (0,0) to (1,1). If you draw a vertical line through it, the line should have an x-coordinate of 0.5.
Et cetera.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With