Before the drawing

Member
Posts: 131
Joined: 2010.08
Post: #1
Could you explain why antialiasing a polygon does not work even though this method is called before the drawing.

Code:
- (void) prepareOpenGL
{
    glClearColor(0, 0, 0, 0);

    GLint vblSynch = 1;
    [[self openGLContext] setValues:&vblSynch forParameter:NSOpenGLCPSwapInterval];

    [self setupAnimationTimerWithInterval:(1.0f/60.0f)];

    [super prepareOpenGL];
    glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
    glEnable(GL_BLEND);
    glEnable(GL_POLYGON_SMOOTH);
    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
}
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Anti-aliased primitives are not always supported in OpenGL drivers. Sometimes you get anti-aliased points and lines, but anti-aliased polygons are a rarely supported feature IIRC.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #3
You are right, as when
Code:
    glPolygonMode(GL_FRONT, GL_LINE);
    glEnable(GL_LINE_SMOOTH);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
is used, antialiasing works. How can I antialias filled polygons if it is not supported on Macs?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
Arekusu had an old article about this very thing: http://homepage.mac.com/arekkusu/bugs/invariance/

He'll probably chime in with more.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #5
Can you explain why you want to antialias a polygon?

Or what type of polygon, or how many polygons?

GL_POLYGON_SMOOTH was only a good solution for certain types of scenes. There are alternate ways to antialias but they all have tradeoffs, so you'll have to describe what you're trying to do if you want a good answer.
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #6
I want to antialias a single circle that is moving. The reason is the obvious one: it looks better.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
Draw a quad with a mipmapped circle texture on it.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #8
(Aug 13, 2010 04:36 PM)Skorche Wrote:  Draw a quad with a mipmapped circle texture on it.

but what if he wants to to be crisp and smooth on those brand new 4096 x 3072 displays that better be coming out soon?

Skorche is right though for most applications. If your point is to draw a circle that looks pretty, the choices are GLprimitives or a texture. Texture will allow a crisper bitmapped look (while ultimately letting you to add animation and other effects).

Alternatively, for a circle, I recommend not using polygon and instead use triangle strip or triangle fan.

And lastly: I recommend you don't even bother at all. In learning game programming, the knowledge of graphics will come in time, but I wouldn't bother with the "making it pretty" until you can "make it work".

Not saying you shouldn't ask these questions, but they will not get you as far as others you should be asking.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #9
(Aug 13, 2010 05:47 PM)skyhawk Wrote:  but what if he wants to to be crisp and smooth on those brand new 4096 x 3072 displays that better be coming out soon?

It might seem a bit silly, but it's not like a 1024x1024 texture takes up that much VRAM if you really wanted a big circle. You can also effectively double the resolution by splitting it into 4 quads putting a 1/4 pie shaped piece into the texture.

You could also probably write a shader to make an AA circle. I've seen a couple GLSL examples that used the screenspace partial derivatives and smoothstep function to anti-alias. Not sure how widely supported the parts to do that in hardware is though.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
You don't even need to split the quads, you can use the MIRRORED_REPEAT extension.

The GLSL technique should work on everything that supports GLSL AFAIK (back about 5 or 6 years).
Quote this message in a reply
Post Reply