Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6366491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:25:40+00:00 2026-05-25T00:25:40+00:00

I am creating a polygon filled with texture using opengl in cocos2d framework. I

  • 0

I am creating a polygon filled with texture using opengl in cocos2d framework. I have used PRKit(link) and modified the draw method with the code shown below.

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);

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.

transparent png

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.

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:25:41+00:00Added an answer on May 25, 2026 at 12:25 am

    If you have a texture with full opaque / full transparent pixel (alpha = 1.0 or 0.0 only), you can keep GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA to keep the transparency.

    Else you can use alpha test with GL_GREATER, 0.0 (or discard keyword in fragment shader if you use opengl es 2.0).

    But on ios, alpha test is less performant than alpha blending.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Physics Editor for creating the Polygon in Box2d. It generates
I need to draw polygon using mouse and mark a particular area on Google
I'm creating a 2D game using OpenGL and C++. I want it so that
I am creating 2D game with OpenGL. Everytime I move my object, I have
In C++ OpenGL, I want to draw each pixel manually (as a texture I
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
When creating a web application, and lets say you have a User object denoting
Is OpenGL, given a series of points, able to fill in a polygon or
I'm creating a drawing application with OpenGL. I'v created an algorithm that generates gradient
how to draw a circle in openlayer map? i have tried in diff way,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.