Saturday, May 14, 2011

glBlendFunc example - 2

[glBlendFunc example] Following code fragment shows a glBlendFunc example. When drawing GL shapes, you can control how to blend images by calling glBlendFunc() function. To enable blending, you should call glEnable(GL_BLEND) before calling glBlendFunc() function. [glBlendFunc example]

 glEnable(GL_BLEND);  // Enable blending.
  glBlendFunc(GL_SRC_ALPHA,GL_ONE); 
 
  glBegin(GL_TRIANGLES);  // Drawing Using Triangles
  glColor4f(1.0f, 1.0f, 1.0f, 0.33333f);
  glVertex4f( 0.0f, 1.2f, 0.0f, 1.0f); 
  glVertex4f(-1.2f,-1.0f, 0.0f, 1.0f); 
  glVertex4f( 1.2f,-1.0f, 0.0f, 1.0f); 
  glEnd(); 
 
  glBegin(GL_QUADS);  // Draw A Quad
  glColor4f(1.0f, 1.0f, 1.0f, 0.33333f);
  glVertex4f(-1.0f, 1.0f, 0.0f, 1.0f); 
  glVertex4f( 1.0f, 1.0f, 0.0f, 1.0f); 
  glVertex4f( 1.0f,-1.0f, 0.0f, 1.0f); 
  glVertex4f(-1.0f,-1.0f, 0.0f, 1.0f); 
  glEnd(); 

  glColor4f(1.0f, 1.0f, 1.0f, 0.33333f);
  glutSolidSphere(1.0f, 36, 36);