Jump to content
  • Advertisement
Sign in to follow this  
Zakwayda

OpenGL Antialiasing causing rendering artifacts at edge of viewport

This topic is 3939 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an OpenGL window with dimensions 1000x480, and I've set up the viewport to be horizontally centered and of dimensions 640x480 (the actual dimensions are incidental - the important bit is that the window is wider than the viewport, so there are 'unused' areas on the left and right sides). In the viewport I'm rendering some vector graphics (lines only). When antialiasing is off, all is well. When antialiasing is on, the graphics 'bleed' over the edge of the viewport (to the left and right) onto the 'unused' areas of the window by about one pixel width. I'm not clearing the screen each frame (there's a background image, so it isn't necessary), which means that the two 1-pixel-wide columns of 'bleed' pixels at the left and right edges of the viewport just kind of hang around. I was under the impression that all OpenGL rendering is restricted to the current viewport, so I'm not quite clear on why pixels outside the viewport are being affected. I've tried the program with the following configurations: - OS X, GeForce2 Twinview: bleeding - OS X, ATI Rage 128: bleeding - Linux, Intel 82845G: bleeding - Windows, GeForce3 Ti 200: no bleeding Am I missing something obvious? Or is the behavior of OpenGL undefined in this area? Here is a short example program demonstrating the behavior:
#include "SDL.h"
#include "SDL_opengl.h"

int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_SetVideoMode(800, 480, 0, SDL_OPENGL);

    glMatrixMode(GL_PROJECTION);
    glOrtho(0., 640., 0., 480., -1., 1.);
    glViewport(80, 0, 640, 480);
    
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glClear(GL_COLOR_BUFFER_BIT);

    bool quit = false;
    while (!quit) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT ||
                (event.type == SDL_KEYDOWN &&
                 event.key.keysym.sym == SDLK_ESCAPE))
            {
                quit = true;
            }
        }

        // Render a quad to clear the rendering area:
        glColor3f(0.f, 0.f, 0.f);
        glBegin(GL_QUADS);
        glVertex2f(0.f, 0.f);
        glVertex2f(640.f, 0.f);
        glVertex2f(640.f, 480.f);
        glVertex2f(0.f, 480.f);
        glEnd();

        // Render a moving, antialiased line:
        float xTime = static_cast<float>(SDL_GetTicks() % 2147) / 1000.f;
        float yTime = static_cast<float>(SDL_GetTicks() % 1733) / 1000.f;
        float x = 800.f - xTime * 400.f;
        float y = 480.f - yTime * 480.f;
        glColor3f(1.f, 1.f, 1.f);
        glBegin(GL_LINES);
        glVertex2f(x, y);
        glVertex2f(x + 50.f, y + 50.f);
        glEnd();

        SDL_GL_SwapBuffers();
    }

    SDL_Quit();
    return 0;
}

Any input or hints will be appreciated...

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure (since not worked w/ AA yet), but perhaps setting the scissor box may help, due to
Quote:
from man-page
... To enable and disable the scissor test, call glEnable and glDisable with argument GL_SCISSOR_TEST. The test is initially disabled. While the test is enabled, only pixels that lie within the scissor box can be modified by drawing commands...


[Edited by - haegarr on January 7, 2008 2:40:08 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by haegarr
I'm not sure (since not worked w/ AA yet), but perhaps setting the scissor box may help, due to
Quote:
from man-page
... To enable and disable the scissor test, call glEnable and glDisable with argument GL_SCISSOR_TEST. The test is initially disabled. While the test is enabled, only pixels that lie within the scissor box can be modified by drawing commands...
Thanks, haegarr. Apparently I've been laboring under a misconception about the OpenGL viewport - in fact, I seem to have stumbled directly into Common OpenGL Pitfall #10. (I did read that article at some point in the past, but it's been a while, and my Google searches this time around didn't turn it up for some reason.)

So I'm a bit chagrined, but nevertheless quite happy to have the problem solved :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!