Saturday, May 14, 2011

glBlendFunc example c c++ objc

[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_ONE, GL_ZERO);  //  Just the source image.
  glBegin(GL_TRIANGLES);  // Drawing Using Triangles
  glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
  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); 

 // Alpha blending.
  glBegin(GL_QUADS);  // Draw A Quad
  glColor4f(0.0f, 0.0f, 1.0f, 0.5f);
  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);