PDA

View Full Version : Polygon Antialiased



Manel Goucha
03-26-2011, 08:07 AM
Hi, I'm trying to use the polygon antialiasing but it doesn't seem to work

I'used all of these:

1:
glEnable(GL_POLYGON_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
2:
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_MULTISAMPLE_ARB);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
3:
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_MULTISAMPLE_ARB);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);

but it doesn't give antialiasing results

http://www.mediafire.com/imgbnc.php/338b033f6a3946576549afc2d59facb3f51dc3f88088a2eace 2bcd500ef697874g.jpg

Can someone please help me on this?
thks

Nowhere-01
03-26-2011, 08:28 AM
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=46

According to this, you need specific rendering context.

trinitrotoluene
03-26-2011, 08:29 AM
What is your video card? To have a multisample framebuffer, you need at least to tell the "window api" (glX glut SDL ...) that you want that. For example with SDL:



...
SDL_GL_SetAttribute( SDL_GL_SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_SDL_GL_MULTISAMPLESAMPLES, 8 );
...



Or,the easiest way to have a multisample buffer, change the settings of your video card driver to force multisampling for all OpenGL application (AMD video card => via catalyst control center).

I never used GL_POLYGON_SMOOTH because on very old hardware ( NVidia TnT2) it was really slow so maybe another people will tell.

ZbuffeR
03-26-2011, 08:54 AM
Old style antialiasing with the GL_*_SMOOTH need blending to be enabled.
http://glprogramming.com/red/chapter06.html#name2

New style AA with MULTISAMPLE need a specific rendering context, as explained by the 2 posts above.

Both AA styles can NOT be used at the same time.

Manel Goucha
03-26-2011, 09:00 AM
Yes I've read that page and this is what I'm using:

CreateViewport(Value, GLWidth^, GLHeight^);
CreateViewer(0, 0);
ColorDS(1, 1, 1, 1);

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_ALWAYS, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 0);
glClearDepth(1);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_MULTISAMPLE_ARB);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity;

I'm using alpha blend but it still doesn't give me antialias

what is the best way to get that then, GL_POLYGON_SMOOTH or GL_MULTISAMPLE_ARB?

I'm using an ATI Radeon HD 4600

thks

Manel Goucha
03-26-2011, 09:01 AM
Thanks and how can I use SDL? Is it a funcionality of OpenGL?

thks

Alfonse Reinheart
03-26-2011, 10:29 AM
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_MULTISAMPLE_ARB);

First, you don't use both polygon smoothing and multisampling; you use one or the other.

Second, you have to create a multisampled framebuffer, either manually with FBOs, or using whatever you use to create your window to ask for a multisampled framebuffer.

Manel Goucha
03-27-2011, 08:34 AM
Sure, but if I use only these two:

glEnable(GL_POLYGON_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

Shouldn't it be antialiased?
or is it the same than multisampling and do I need to set it in another way?

is there any example that really works because I've found many that didn't work across the net

thks again

Alfonse Reinheart
03-27-2011, 01:12 PM
Shouldn't it be antialiased?

Did you also turn on blending? Did you also z-sort your triangles from farthest to nearest? Because if you don't do both of those, you won't get any "antialiasing".


is there any example that really works because I've found many that didn't work across the net

Examples of which, multisampling, or polygon smoothing?

Manel Goucha
03-27-2011, 10:40 PM
This is what I'm using:

- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_ALWAYS, 0);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glShadeModel(GL_SMOOTH);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glEnable(GL_POLYGON_SMOOTH);
- glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

even with blending enabled it wont give me any antialising, and I only have one object with 4 vertices to render on a black background, shoudn't it be smooth?

An Example for GL_POLYGON_SMOOTH or the one that is easier to use

thks again

Dan Bartlett
03-28-2011, 05:16 AM
AFAICT, it doesn't seem to be supported in recent hardware. It's hard to find any details on when they were dropped. But here's a couple of links I found:

http://www.opengl.org/wiki/Common_Mistak...LYGON_SMOOTH.29 (http://www.opengl.org/wiki/Common_Mistakes#glEnable.28GL_POINT_SMOOTH.29.2C_g lEnable.28GL_LINE_SMOOTH.29_and_glEnable.28GL_POLY GON_SMOOTH.29)
http://lists.apple.com/archives/mac-opengl/2007/Aug/msg00020.html

Can't find any NVidia/ATI confirmation of these though, but it doesn't appear to work on my Geforce 9500GT, or ATI Mobility Radeon HD 5650.

Another thing that could potentially affect it (although unlikely), is that if you do have hardware that supports it, the spec says:


If MULTISAMPLE is enabled and the value of SAMPLE BUFFERS is one, then polygons are rasterized using the following algorithm, regardless of whether polygon antialiasing (POLYGON SMOOTH) is enabled or disabled.

Manel Goucha
03-28-2011, 10:38 AM
Thanks again for all the time, but it seems to hard to use it in my code, I thought it was simpler and just need to call a function for polygon smooth
I've tried to read all the articles but most of them didn't wotk and the otheres were to hard to implement

But I know that my graphics card have antialiasing because of another library that uses opengl wich can make it at 2 and 4 times

Dan Bartlett
03-28-2011, 11:47 AM
It's harder to implement multi-sampling initially, due to WGL being a pain, but all you need to do once it's set up, is enable/disable GL_MULTISAMPLE, whereas GL_POLYGON_SMOOTH requires further sorting etc of your scene objects.

If you're using an OpenGL helper library, it's typically just a case of setting a couple of properties at context creation time, but if you choose to do it yourself, you will need to do something like this in MS Windows (since you are only allowed to call SetPixelFormat once for a window):

1) Create temporary window
2) Choose/Set OpenGL compatible pixel format
3) Create temporary context + make current
4) Retrieve OpenGL extensions used for context creation/multisampling
5) Choose/Set a multisampled pixel format for your actual window using OpenGL extensions (http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt + http://www.opengl.org/registry/specs/ARB/multisample.txt)
6) Create context for your actual window using OpenGL extension (http://www.opengl.org/registry/specs/ARB/wgl_create_context.txt) if it's available, or wglCreateContext otherwise
7) Delete temporary context (or keep it around for further use)
8) Delete temporary window (or keep it around for further use)
9) Use your actual context to retrieve any extensions you need for rendering
10) Render using actual context

The lesson that S1ngular mentioned: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=46 shows how to do this in various programming languages/IDEs

Manel Goucha
03-28-2011, 02:09 PM
Ha, But wich var do I need to set it up in the pixelformat?


but even that, I've used the nehe.gamedev.net (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=46 ) examples for c and delphi and it didn't worked with antialiasing, is it from my graphics card?


Image of the example:

http://www.mediafire.com/imgbnc.php/cbdba12f4bd447dbb65336a5037fdcb53a8b74aab73db562ac 053aa98554cb285g.jpg

Manel Goucha
03-29-2011, 05:06 PM
Can someone please help me? I realy need this

is there a simple example of ARB_MULTISAMPLE that really works? in c or anohter language?

thks

Dan Bartlett
03-30-2011, 02:59 AM
Well, the Delphi version has a bug, it should be:


valid := wglChoosePixelFormatARB(h_dc,@iattributes[0],@fattributes[0],1,@pixelFormat,@numFormats);

instead of:


valid := wglChoosePixelFormatARB(h_dc,@iattributes,@fattrib utes,1,@pixelFormat,@numFormats);


Also, it's usually possible to override multisample settings in your graphics card driver control panel. If the multisample demo is having no effect, check these settings. Usually there are options to force it on/off or let applications decide.