Blending troubles

This is a discussion on Blending troubles within the Game Programming forums, part of the General Programming Boards category; Alright, I'm working on checkers in opengl. The user will use the arrow keys to move a cursor around the ...

  1. #1
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175

    Blending troubles

    Alright, I'm working on checkers in opengl. The user will use the arrow keys to move a cursor around the board to select and move the pieces. I want the cursor to be blue at the bottom, and slowly move up to be completely transparent

    http://files.gtanet.com/gtasa/walkth...ssantos043.jpg

    Here is a mediocre example of the effect i am aiming for, but I am having trouble with Blending.

    my call to glBlendfunc:

    Code:
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    and when i draw the cursor:

    Code:
              glEnable(GL_BLEND);
    	  glBegin(GL_QUADS);
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f); 
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f); 
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f); 
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f); 
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f);  glVertex3f(-1.0f, -1.0f,  1.0f);
    
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f); 
    		glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    		glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    	  glEnd();
    	  glDisable(GL_BLEND);
    and the results:
    http://img455.imageshack.us/img455/5669/ck1jy.png

    hopefully you can see what is going on in that picture

    How can i get the effect i want?

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Draw the cursor last. If you draw it before the pieces (which seems to be what you're doing) they will fail the Z test because your cursor is already there. But since it has alpha, it shows through to the back buffer.

    Also, you probably want to use ONE_MINUS_SRC_ALPHA, not ONE

  3. #3
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    Quote Originally Posted by skorman00
    Draw the cursor last. If you draw it before the pieces (which seems to be what you're doing) they will fail the Z test because your cursor is already there. But since it has alpha, it shows through to the back buffer.

    Also, you probably want to use ONE_MINUS_SRC_ALPHA, not ONE
    Yep, that was it.

    Thanks alot man.

  4. #4
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    I get so confused with which blending method to use:

    GL_ONE_MINUS_SRC_ALPHA
    GL_ONE
    GL_SRC_ALPHA
    etc.

    What's the difference between all of these? I've used them all before, but I can never see the diffference. OpenGL documentation just gives some weird math results:

    (f, f, f, 1); f=min(As, 1-Ad)
    (1, 1, 1, 1)-(Ad, Ad, Ad, Ad)

    Maybe they expect people to know this, but it just confuses me further.

  5. #5
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    It's hard to say "this is how it's going to look" so the math is the best way to explain it. I don't remember what they each get me (despite the fact that the name implies that) so I always wind up looking them up, and experimenting with each. Just know that ONE_MINUS_SRC_ALPHA is most likely what you'll want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Blending Problem
    By IdioticCreation in forum Game Programming
    Replies: 1
    Last Post: 02-16-2008, 05:13 PM
  2. Replies: 4
    Last Post: 01-15-2006, 04:14 AM
  3. Alpha blending
    By SMurf in forum Game Programming
    Replies: 3
    Last Post: 08-29-2003, 06:50 PM
  4. More Program Troubles...
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 05:40 AM
  5. having troubles
    By neandrake in forum C++ Programming
    Replies: 7
    Last Post: 03-07-2002, 08:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21