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.

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 on other sites
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 on other sites
Is it possible to create this:
  * ********

Share on other sites
just off the top of my head, draw it on a textured quad?

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 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 on other sites
Try using a few more pixels

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.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• Forum Statistics

• Total Topics
633368
• Total Posts
3011531
• Who's Online (See full list)

There are no registered users currently online

×