Results 1 to 9 of 9

Thread: antialias and sprite masking

  1. #1
    Member Contributor
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    63

    antialias and sprite masking

    Hi,

    I'm trying to draw masked sprites with antialias. For example, let say I have a texture which is letter A, it has two colors, white for the solid pixels (alpha=1.0), and magenta for the background (alpha=0.0), then I render this texture as a 2D texture quad using GL_LINEAR as filters (for antialias), and I use the Alpha Test to skip background pixels, the problem is that the antialiased parts is a mix of white and magenta scaled colors.. how can I render this sprite (texture) with both masking and antialias ??, the antialias I want it to be mixed with the scene background not with the sprite's mask color..

    Thanks in advance.

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: antialias and sprite masking

    It's very simple actually. When you load an image from disk you process it to add alpha channel right? Simply fill your texture with white color during that process so there are no more magenta pixels. Only white+alpha=1.0 and white+alpha=0.0

  3. #3
    Member Contributor
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    63

    Re: antialias and sprite masking

    thanks for your reply k_szczech, sure that will work, but what if the sprite has more than one color (many solid colors) ??

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: antialias and sprite masking

    Either 'dilate' the colors on the letter egde (best), or 'erode' the alpha (easy).

  5. #5
    Member Contributor
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    63

    Re: antialias and sprite masking

    I did not understand the 'erode' alpha way...

    is there any other way without image processing (except for the background color conversion) ???..

    Thanks.

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: antialias and sprite masking

    Dilate : (see example with text)
    http://www.norman.k12.ok.us/002/doc/...h05s07s03.html
    Erode is simple the inverse operation.
    Either you 'enlarge' the color channel, either you 'shrink' the alpha channel.

    There is no other way.
    You have to understand that both alpha and color channels are interpolated.
    This is what you want, else there would be hard blocky edges around your letters.

    If your are lazy, find the average color of your "sprite" and use that as background. Use Medium grey if you are really lazy...

  7. #7
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: antialias and sprite masking

    There is no other way.
    There is one and I'm using it - I paint images with alpha channel and save to PNG (it supports alpha cannels). I do all necessary color bleeding in Paint Shop Pro - my application just loads these images and oesn't have to do anything with it - just display.

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: antialias and sprite masking

    Fine you do the dilate by hand, but you still need to dilate

  9. #9
    Member Contributor
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    63

    Re: antialias and sprite masking

    thanks for your replies guys, I'll try to implement some 'dilate' algorithm similar to the one ZbuffeR said.

Similar Threads

  1. Replies: 4
    Last Post: 06-16-2016, 04:47 AM
  2. antialias on arc
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-05-2006, 12:46 AM
  3. Antialias steps...
    By halo in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-18-2005, 02:14 PM
  4. antialias
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-25-2003, 12:09 PM
  5. multisampling antialias?
    By lgnnn in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 10-14-2002, 09:30 PM

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