Results 1 to 5 of 5

Thread: glCopyTexImage2D -and- Alpha Testing

  1. #1
    Member Newbie
    Join Date
    Nov 2006
    Location
    California
    Posts
    37

    glCopyTexImage2D -and- Alpha Testing

    hello,

    The glCopyTexImage2D() is working perfectly to render a small image to a texture. The one problem is that I cannot apply the GL_ALPHA_TEST to the texture to get some transparency.

    I'm using GL_RGBA, clearing to a black background, then drawing some light images on the viewport.

    What might be going wrong?

    Thanks.

  2. #2
    Member Newbie
    Join Date
    Nov 2006
    Location
    California
    Posts
    37

    Re: glCopyTexImage2D -and- Alpha Testing

    Here's some code

    //create an empty texture...
    GLuint texnum;
    glGenTextures(1, &texnum);
    glBindTexture(GL_TEXTURE_2D, texnum);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SIZEX, SIZEY, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

    //render to texture...
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glViewport (0, 0, SIZEX, SIZEY);
    glMatrixMode(GL_MODELVIEW); glLoadIdentity();
    glMatrixMode(GL_PROJECTION); glLoadIdentity();
    glOrtho(0, SIZEX, 0, SIZEY, -1, 1);
    draw_text(white, "Testing!");
    glBindTexture(GL_TEXTURE_2D, texnum);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, SIZEX, SIZEY, 0);

    //draw texture to screen...
    glColor4ub(255,255,0,255);
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.1f);
    glBindTexture(GL_TEXTURE_2D, texnum);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f,0.0f); glVertex2i(left, bottom);
    glTexCoord2f(0.0f,1.0f); glVertex2i(left, top);
    glTexCoord2f(1.0f,1.0f); glVertex2i(right,top);
    glTexCoord2f(1.0f,0.0f); glVertex2i(right,bottom);
    glEnd();
    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_ALPHA_TEST);


    I'm getting no transparency in my final draw-to-screen step, just white text on a solid black rectangle.

    I would like to see the white text areas, but no rectangle.

    Thanks.

  3. #3
    V-man
    Guest

    Re: glCopyTexImage2D -and- Alpha Testing

    That would mean the alpha value is larger than 0.1
    This depends on the TexEnv mode. Are you using GL_DECAL?
    Also, use glCopyTexSubImage2D instead just for updating a texture.

    I'm going to guess it would be better to have
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    And you have to know what draw_text does exactly. Good luck!

  4. #4
    Member Newbie
    Join Date
    Nov 2006
    Location
    California
    Posts
    37

    Re: glCopyTexImage2D -and- Alpha Testing

    I tried the things you mentioned, V-man, but no luck.

    My Alpha-testing works great in many other areas of the program. The draw_text() function even uses alpha-testing to get the white text to the texture viewport.

    I'll keep trying things until I get it to work.

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

    Re: glCopyTexImage2D -and- Alpha Testing

    Where do you call glEnable( GL_TEXTURE_2D ) ? Is blending disabled?

Similar Threads

  1. Alpha testing
    By nt in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 10-23-2007, 05:31 PM
  2. Occlusion Query, FBO and Alpha Testing
    By Husted in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 03-23-2007, 12:47 AM
  3. alpha testing & lighting don't go together
    By ctoa in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 04-15-2004, 11:19 AM
  4. alpha testing a blended texture
    By quynh_clone in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-31-2002, 10:13 AM
  5. Blending, alpha testing, clipping performance question...
    By MarcusL in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-07-2001, 10:27 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