Jump to content
  • Advertisement
Sign in to follow this  
biscuitz

Why does triangle look like that?

This topic is 4854 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

glVertex3f(0.0,1.0,0.0);
glVertex3f(1.0,0.0,0.0);
glVertex3f(-1.0,0.0,0.0);
That makes the triangle look like this: ( * = pixel )
   **
  ****
 ******
Why doesn't it look like this:
    *
   ***
  *****

Share this post


Link to post
Share on other sites
Advertisement
It's due to the way OpenGL rasterizes the triangles. It has to have a way of choosing which pixels to color and which not to. I don't know the exact algorithm, but it's something like if the center of the pixel is inside the triangle it's colored. This can result in some slightly unexpected behavior, but it's fast and it works.

Share this post


Link to post
Share on other sites
I'm not quite sure I follow your meaning. If by chance, you're asking why your triangle isn't equilateral, it's because the coordinates you're using don't compose an equliateral triangle :)

The length of your upright sides are ~1.41 units and the bottom length is 2

Share this post


Link to post
Share on other sites
i had the same problem a long time ago. my triangle was really small and i think i just changed the depth/field of view (whatever its called) to fix it. i was using Direct3D though, not OpenGL.

Share this post


Link to post
Share on other sites
Choice of coordinates can make a difference as well. You might want to read up on OpenGL's rasterization rules. A quick Google on the subject turns up this page on MSDN about the concept. The article is Direct3D-centric, but IIRC both OpenGL and DirectX apply the same top-left filling convention. At any rate, the article will serve as an adequate explanation of filling conventions, and why certain pixels are selected and others discarded when rasterizing a triangle.

In orthographic projections, for instance, it can be helpful to specify triangle vertices at half-coordinates (ie, 10.5, 154.5, and so on) rather than on integer boundaries, to tweak the selection of pixels for the desired results.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!