PDA

View Full Version : Aliasing



nt
08-31-2007, 11:01 AM
I woulld like to know how to turn on aliasing and turn off aliasing after the aliasing is done in each frame.

What I am trying is to draw a compass card in to a predefined location that contains other images. I only want to blend the compass card and don't want to affect any other images on the screen. But what I am getting is a diagonal line across the screen and the aliasing is affecting all other models on the screen.

I am attaching the code here.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluOrtho2D(-112, 112, -112, 112);

//turn on the aliasing = during every frame
glShadeModel(GL_FLAT);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);

glPushMatrix();

glColor3f (1.0, 1.0, 1.0);

glBegin(GL_POLYGON);
glVertex3f (-220, 220, 0.0);
glVertex3f (220, 220, 0.0);
glVertex3f (220,-220,0.0);
glVertex3f (-220,-220, 0.0);
glEnd();
glColor3f (0.0, 0.0, 0.0);
glBegin(GL_LINES);
glLineWidth( (GLfloat)(50));
glVertex2f(-100,-100);
glVertex2f(100,100);
glEnd();

//trying to turn off aliasing after draw
glPopMatrix();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
glDisable(GL_BLEND);

appreciate any help.

Trenki
08-31-2007, 02:22 PM
First off all I think you have your terminology mixed up. I believe you realy mean anti-aliasing and not aliasing!

I see a few problems in your code.
You load your ortho matrix into the modelview matrix and not into your projection matrix. While this will still work it is conventional to load a projection matrix (e.g. ortho matrix) into the GL_PROJECTION matrix. You just draw a square polygon that is larger than what you specified in your ortho call so it should fill the whole screen. Then you explicitly draw a diagonal line across the screen. This is why you get it! Not all implementation must support lines wider than 1 pixel. You specify 50. Make sure to check the maximum line with with glGetInteger. Using POLYGON_SMOOTH might cause seams between adjacent polygons (at least it did for me I think). You probably are better of initializing a multisampled OpenGL context and enabling/disable multisampling on demand.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

Lindley
08-31-2007, 06:52 PM
If you want to apply a given effect to only part of a render, you can mask out the rest with a stencil buffer or special depth-only pass.

Alternatively, you can use render-to-texture to create complex effects on textures you later applying to other objects in the scene.

nt
09-06-2007, 07:21 AM
Hi Trenki

thanks for the reply, I changed my ortho so that it is greater than the square. On the square I am drawing a diagonal line, when there is no aliasing, there is only one diagonal line, with anti-aliasing, there is one shaded line diagonaly from the other two corners, which I am not drawing. This line is annoying

Joseph Steel
09-07-2007, 12:01 AM
As Trenki says using POLYGON_SMOOTH might cause the seam between adjacent polygons to become visible. You may end up with two triangles as a result of the triangulation of your polygon. Can you use GL_QUAD rather that GL_POLYGON in your call to glBegin()? This may help.