Extreme newbie alert - Blending question

Hi,

New to this board :slight_smile: I am working in LWJGL but i’m positive that this question isn’t specific to that implementation.

I am trying to achieve a simple effect of having 3 transparent quads on top of each other. The first two use simple colour values which is fine, but when i try to apply a texture to the third quad (PNG with alpha channel) i begin to have problems. As it is, the third quad displays the texture on top of the other quads, but does not utilise the alpha channel.

I am sure something is not right with the way i am enabling and disabling GL_TEXTURE_2D. If i enable it once-only in glInit(), the 1st two boxes don’t show up. Or is it something to do with the blend function i’m callling – or both? :slight_smile:

Ultimately i intend to move these simple quads into objects of their own – are there any major things i need to consider when adopting an OOP approach? (regarding gl_Enable calls etc)

Thanks for reading.

 main routine:
 
   // Clear the screen
   GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);  
   
   // red square
   GL11.glPushMatrix();  
   {          
    // select texture    
       GL11.glTranslatef(200f, 200f, 0.0f);  
       GL11.glColor4f(1f, 0f, 0f, 0.5f);  
       GL11.glBegin(GL11.GL_QUADS);      
       {
        // anti clock wise          
        GL11.glVertex2f(0.0f, 0.0f);      // top left
        GL11.glVertex2f(250.0f, 0.0f);   // top right
        GL11.glVertex2f(250.0f, -250.0f);  // bottom right
        GL11.glVertex2f(0.0f, -250.0f);   // bottom left
       }
       GL11.glEnd();
   }
   GL11.glPopMatrix();    
   
   // white square
   GL11.glPushMatrix();  
   {          
    // select texture    
       GL11.glTranslatef(300f, 300f, 0.0f);  
       GL11.glColor4f(1f, 1f, 1f, 0.5f);
       GL11.glBegin(GL11.GL_QUADS);      
       {
        // anti clock wise        
        GL11.glVertex2f(0.0f, 0.0f);      // top left
        GL11.glVertex2f(250.0f, 0.0f);   // top right
        GL11.glVertex2f(250.0f, -250.0f);  // bottom right
        GL11.glVertex2f(0.0f, -250.0f);   // bottom left
       }
       GL11.glEnd();
   }
   GL11.glPopMatrix();    
   
   
   // textured square
   GL11.glPushMatrix();  
   {    
       // select texture
   GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[0]); // Select Our Texture
     
      GL11.glEnable(GL11.GL_TEXTURE_2D);    
       
       GL11.glTranslatef(400f, 400f, 0.0f);    
       GL11.glColor4f(1f, 0f, 0f, 0.8f);
       GL11.glBegin(GL11.GL_QUADS);        
       {      
        GL11.glTexCoord2f(0.0f, 0.0f);
        GL11.glVertex2f(0.0f, 0.0f);      // top left
     
        GL11.glTexCoord2f(1.0f, 0.0f);
        GL11.glVertex2f(250.0f, 0.0f);   // top right
     
        GL11.glTexCoord2f(1.0f, -1.0f);
        GL11.glVertex2f(250.0f, -250.0f);  // bottom right
     
        GL11.glTexCoord2f(0.0f, -1.0f);
        GL11.glVertex2f(0.0f, -250.0f);   // bottom left
       }
       GL11.glEnd();
       
      GL11.glDisable(GL11.GL_TEXTURE_2D);    
   }
   GL11.glPopMatrix();
 glInit:
 
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
     
GL11.glOrtho(0, mode.getWidth(), 0, mode.getHeight(), -100, 100);
       
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
 
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  
   
GL11.glEnable(GL11.GL_BLEND);    
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

You blend by Alpha as me.

Do you have problem with the last object matrix?

Hi Dol,

Sorry i don’t quite understand what you mean by ‘blend by Alpha as me’ – but yes, i am having trouble with the last object matrix :confused:

Check out the FAQ.

http://www.opengl.org/resources/faq/technical/#indx0150

http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=017373

Help me my problem. My problem about blending object if I enable blend object 2 the object 1 is show but the object 3, 4, 5… is not show.

Why?

DOL AI WITH 3D BONE SYSTEM:

Would you PLEASE stop hijacking other peoples threads.

Thank you very much.