Results 1 to 5 of 5

Thread: Alpha Texture + Color

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    28

    Alpha Texture + Color

    Hi All,

    I'm trying to render some AA lines, so far I 've created a texture (RGBA) with a filled circle and a smooth boundary.

    I get a good result with this, however the lines get the texture color, and I want if possible, to use this texture as a Alpha Pattern, and get the RGB channels from the glColor4x primitive.

    I'm using GL_MODULATE, and from the documentation I read that it will mix the texture color with the light or primitive color.

    My lack of knowledge is:

    how to create an alpha texture, and if it will work after updating the texture with GL_ALPHA definition.

    basically something like this,

    Code :
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    // get a free texture
    glGenTextures(1, &textureId);
    // bind texture
    glBindTexture(GL_TEXTURE_2D, textureId);
    // send buffer  to opengl
    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 128, 128, 0, GL_ALPHA, GL_UNSIGNED_BYTE, circle->getBitmap());
     
     
    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterx(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    Because I've tried to use the current RGBA texture uploaded as GL_ALPHA but it didn't work.

    Thanks in advance,

    Victor

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

    Re: Alpha Texture + Color

    Then either change the external texture format to match the RGBA you have :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, circle->getBitmap());

    Or build an alpha-only texture, and do :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 128, 128, 0, GL_ALPHA, GL_UNSIGNED_BYTE, alphaTexture);

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Alpha Texture + Color

    Sticking to your first idea, with your RGBA texture. If the disc color is uniformly white you can directly affect the line color by setting the current color with glColor. The default GL_TEXTURE_ENV_MODE is GL_MODULATE so you should easily modulate the current color with the texture one.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    28

    Re: Alpha Texture + Color

    Hi,

    Thanks for your help.

    My circle is uniform, however it has a smooth boundary from 100% opacity to 10%.

    I will try both.

    Thanks,

    Victor

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    28

    Re: Alpha Texture + Color

    Hi,

    The first approach doesn't work. I have my triangle strip ( box + 2 quads for start and end caps)

    I've mapped a semi-circle in one caps and other semi-circle on the end caps.

    But with first approach my start and end caps are totally filled so I get a full rectangle.

    Should I change my glBlendFunc () ?

    Thanks,

    Victor

Similar Threads

  1. GBuffer (color texture) with NORMAL and SPECULAR: Update only alpha
    By RealtimeSlave in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-06-2015, 03:44 AM
  2. color alpha?
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-04-2013, 10:11 AM
  3. Replies: 3
    Last Post: 04-24-2009, 08:59 AM
  4. Replies: 3
    Last Post: 05-31-2003, 11:24 PM
  5. secondary color - alpha channel
    By zroobavela in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-04-2002, 08:14 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