title: Transparent png texture in cocos2d using opengl iphone
body: <p>I am creating a polygon filled with texture using opengl in cocos2d framework. I have used PRKit(<a href="https://github.com/asinesio/cocos2d-PRKit" rel="nofollow noreferrer">link</a>) and modified the draw method with the code shown below. </p>
  
  <pre><code>glBlendFunc(GL_ONE, GL_ZERO);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glBindTexture(GL_TEXTURE_2D, self.texture.name);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  glVertexPointer(2, GL_FLOAT, 0, polyTriangulatedPoints);
  glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates);
  glDrawArrays(GL_TRIANGLES, 0, trianglePointCount);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  </code></pre>
  
  <p>When I use transparent png as texture I get a bit weird result. The transparent area is not black, but some random colors with black. Here is the output I get with the above code.</p>
  
  <p><img src="https://i.stack.imgur.com/vuxg0.png" alt="transparent png"></p>
  
  <p>I had to keep glBlendFunc(GL_ONE, GL_ZERO) which is same as disabling blending. If I don't do so, my background layer in cocos2d gets added with my texture image resulting in a very bright looking texture. To add more information, I have set texture mode so that all images are loaded with the following. </p>
  
  <p>glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);</p>
  
  <p>My question is that why do I see this kind of random colors in transparent area and what are the ways to solve this? I have a feeling that I must be doing something wrong since I am new to opengl.</p>