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

  • SEARCH
  • Home
  • 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 350425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:32:57+00:00 2026-05-12T11:32:57+00:00

I have two layers being drawn. A static background texture and a texture(png) with

  • 0

I have two layers being drawn. A static background texture and a texture(png) with transparent parts. I can correctly see the background with no problems. What I would like to do is modify the top layer by drawing a polygon(rectangle) with size that will change at run time to make that portion of the top layer transparent so you just see that static background.

I am using Cocos2d on for the iphone and found a nice solution by the author (see #6) but in his example he is using another PNG file as the mask. Since my transparent parts will be created at run time with variable heights and widths an image does not work. The overhead of drawing the image(mask) over and over would be to much as well I think.

I have been researching this for awhile now and found a few people talk about drawing a polygon to only the alpha channel and I have been able to get the polygon to draw to this channel it does not make it transparent just a slightly brighter color.

I am hoping that I am just missing something simple:

        RenderTexture *mBurnLayer = [RenderTexture renderTextureWithWidth:512 height:512];
    Sprite *burn = [Sprite spriteWithFile:@"bg-new.png"];
    [burn setPosition:cpv(480/2,320/2)];
    [mBurnLayer setPosition:cpv(256,256)];
    [mBurnLayer begin];
    glColorMask(TRUE, TRUE, TRUE, TRUE);
    [burn visit];
    glColorMask(TRUE, TRUE, TRUE, FALSE);
    [mBurnLayer end];
    [self addChild:mBurnLayer];

    [mBurnLayer begin];
    glColorMask(FALSE, FALSE, FALSE, TRUE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glColor4ub(1, 1, 1, 0.5);
    glLineWidth(10);
    CGPoint vertices[] = { ccp(100,100), ccp(100,200), ccp(200,200), ccp(200,100) };
    drawPoly( vertices, 4, YES);
    glColorMask(TRUE, TRUE, TRUE, TRUE);

I have tried a ton of diffrent combinations of GL_ONE GL_ZERO GL_ALPHA_FROM_SRC etc….

Further reading maybe I need to just clip the texture? Is this possible without a shader? I know iPhone 3GS can do shaders but earlier ones can not.

  • 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-12T11:32:58+00:00Added an answer on May 12, 2026 at 11:32 am

    I figured it out, here is the code for future reference by anyone needing it.

    RenderTexture *bigBackgroundLayer = [RenderTexture renderTextureWithWidth:512 height:512];
    Sprite *bigBackgroundSprite = [Sprite spriteWithFile:@"big_bg.png"];
    [bigBackgroundSprite setPosition:cpv(240,150)];
    [bigBackgroundLayer setPosition:ccp(240,150)];
    [bigBackgroundLayer begin];
    glColorMask(TRUE, TRUE, TRUE, TRUE);
    [bigBackgroundSprite visit];
    glColorMask(TRUE, TRUE, TRUE, FALSE);
    [bigBackgroundLayer end];
    [self addChild:bigBackgroundLayer z:0];
    
    RenderTexture *gameBoardLayer = [RenderTexture renderTextureWithWidth:512 height:512];
    Sprite *gameBoardSprite = [Sprite spriteWithFile:@"bg-new.png"];
    [gameBoardSprite setPosition:cpv(480/2,320/2)];
    [gameBoardLayer setPosition:cpv(256,256)];
    [gameBoardLayer begin];
    glColorMask(TRUE, TRUE, TRUE, TRUE);
    [gameBoardSprite visit];
    glColorMask(TRUE, TRUE, TRUE, FALSE);
    [gameBoardLayer end];
    [self addChild:gameBoardLayer];
    
    [gameBoardLayer begin];
    glColorMask(FALSE, FALSE, FALSE, TRUE);
    glBlendFunc(GL_ONE, GL_ZERO);
    glColor4ub(1, 1, 1, 0.0);
    glLineWidth(10);
    CGPoint vertices[] = { ccp(100,100), ccp(100,300), ccp(300,300), ccp(300,100) };
    drawPoly( vertices, 4, YES);
    glColorMask(TRUE, TRUE, TRUE, TRUE);
    [gameBoardLayer end];
    

    This blends gameBoardSprite to bigBackgroundSprite. Using built in drawPoly function this will only draw the rectangle as lines, I modifed the function to take an extra parameter for GLEnum mode(not in this code) and set it to GL_TRIANGLE_FAN to fill in the poly.

    Hope this is helpful to someone else.

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

Sidebar

Ask A Question

Stats

  • Questions 267k
  • Answers 267k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well the first thing I'd try is setCursorVisible(true) Also you… May 13, 2026 at 12:55 pm
  • Editorial Team
    Editorial Team added an answer If I'm understanding you correctly, this is what you want:… May 13, 2026 at 12:55 pm
  • Editorial Team
    Editorial Team added an answer Here's the code of ObjectUtils.equals(..): public static boolean equals(Object object1,… May 13, 2026 at 12:55 pm

Related Questions

I have a class that represents the state of the world. The class has
If I have two layers on a page, split horrizontally, with the second layer
I have a swf with four frames. The first frame loads an external class
I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.