Results 1 to 5 of 5

Thread: Aliasing

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2007
    Posts
    23

    Aliasing

    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.
    nt

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2005
    Location
    South Tyrol, Italy
    Posts
    107

    Re: Aliasing

    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 | vector_math (3d math library) | software renderer ]

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2007
    Location
    Fairfax, VA
    Posts
    252

    Re: Aliasing

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2007
    Posts
    23

    Re: Aliasing

    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
    nt

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2007
    Posts
    21

    Re: Aliasing

    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.
    Joseph Steel

Similar Threads

  1. Aliasing
    By gnitsuk in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-18-2014, 04:08 AM
  2. Replies: 0
    Last Post: 02-09-2012, 05:58 PM
  3. Terrible aliasing.. how to fix?
    By bill2727 in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 07-21-2004, 04:29 PM
  4. anti-aliasing
    By mdog1234 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-28-2003, 09:31 PM
  5. anti-aliasing
    By imported_aNt in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 03-07-2001, 06:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean