Jump to content
  • Advertisement
Sign in to follow this  
svnstrk

OpenGL OpenGL drawing between pixel

This topic is 3168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, if for example i have 800*800 pixel with int index and then i ask opengl to draw for example at (4.3 , 4.5), which pixel will be drawn? how does it determine which pixel to draw if it falls in between? thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
The rules for pixel exact rendering is well defined in the specification, so you can read it there. But in short, it's the nearest pixel center.

Share this post


Link to post
Share on other sites
hi,

kinda new to this. can you provide me the link? :)
or maybe can i presume 0.5 and less is to 0, above 0.5 is 1 like common rounding?

thanks

Share this post


Link to post
Share on other sites
You can find the specification here. Section 3.4 and onwards concerns pixel perfect rendering (among other things).

But there's one thing you need to be aware of. The pixel-space is not a discrete axis, it is a continuous axis ranging between the outer edges of the outer piels. Pixel centers are therefore located at half-integer coordinates. So the bottom left pixel center has its coordinate at (0.5, 0.5). Integer coordinates are located on pixel corners. I'm not sure the specification forces a specific rounding on exact integer coordinates, but I couldn't find anything about if from looking quickly at it.

So your (4.3, 4.5) coordinate actually renders the pixel at (4.5, 4.5).

Share this post


Link to post
Share on other sites
hi,

so to sum up, +0.5 and floored is the same thing as i mentioned before right?
and im a little bit confuse about your previous statement. let me make it simpler to say my intention.
i created a 800*800 OpenGL window using glut by calling

glutInitWindowSize(width,height);

both widht and height are 800. and also stated

glViewport (0, 0, (GLsizei) w, (GLsizei) h);

in onReshape function. when i call the glReadPixel(..) function and it returns an array, does it correspond one-to-one to each 800*800 pixel, ie my array size is 640000 elements?

if yes, imagine i have a triangle drawn in pixel (4.5, 6.7). can i get the right pixel by accessing array[6*row+4]?

ps: ignoring all glPerspective, glLookAt etc2 kind of transformation.


thanks a lot in advance

Share this post


Link to post
Share on other sites
Quote:
so to sum up, +0.5 and floored is the same thing as i mentioned before right?


The formula to get the pixel (zero-based) would be floor(coordinate), with the exception that pixel borders (i.e. integer coordinates) don't seem to be specified (though I assume it's just floor(coordinate), i.e. floor(5) would mean the 6th pixel).

Quote:

i created a 800*800 OpenGL window using glut by calling

glutInitWindowSize(width,height);

both widht and height are 800. and also stated

glViewport (0, 0, (GLsizei) w, (GLsizei) h);

in onReshape function. when i call the glReadPixel(..) function and it returns an array, does it correspond one-to-one to each 800*800 pixel, ie my array size is 640000 elements?

if yes, imagine i have a triangle drawn in pixel (4.5, 6.7). can i get the right pixel by accessing array[6*row+4]?

Unless I missed somehting, yes that's correct.

Share this post


Link to post
Share on other sites
For me:
If I use
glViewport (0, 0, w, h);
glOrtho(0, w, 0, h,near,far);


and I draw with integer coordinates (for example 3,5), the the pixels are perfectly placed (3th and 5th pixel; note, that 0,0 means the 0th,0th pixel)

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
For me:
If I use
glViewport (0, 0, w, h);
glOrtho(0, w, 0, h,near,far);


and I draw with integer coordinates (for example 3,5), the the pixels are perfectly placed (3th and 5th pixel; note, that 0,0 means the 0th,0th pixel)

Well, that implies floor(coordinate) for your driver.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
Quote:
Original post by szecs
For me:
If I use
glViewport (0, 0, w, h);
glOrtho(0, w, 0, h,near,far);


and I draw with integer coordinates (for example 3,5), the the pixels are perfectly placed (3th and 5th pixel; note, that 0,0 means the 0th,0th pixel)

Well, that implies floor(coordinate) for your driver.
Are you saying it can be driver/hardware dependent?
I mean I'm happy about my pixel perfect stuff, which is just screwed on an other system?

Oh...

Share this post


Link to post
Share on other sites
There are only ambiguities if you place your points on exact pixel edges. Otherwise, the result is well defined. With the setup you posted, the coordinate (3, 5) is located exactly on the corner between four pixels. If you want to hit the center of the 3:rd by 5:th pixel, you need the coordinate (3.5, 5.5).

edit: This applies to individual coordinates only, such as points and lines (its endpoints for example). For filled primitives, the rules are a little bit different, but then we're talking about an areas to cover, not a point to place somewhere on the screen.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!