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 1041089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:18:19+00:00 2026-05-16T15:18:19+00:00

I’ve been using this method (I think I got it from one of Apple’s

  • 0

I’ve been using this method (I think I got it from one of Apple’s example code projects):

- (void)loadTexture:(NSString *)name intoLocation:(GLuint)location
{ 
 CGImageRef textureImage = [UIImage imageNamed:name].CGImage;

 if(textureImage == nil)
 {
  NSLog(@"Failed to load texture!");
  return;
 }

 NSInteger texWidth = CGImageGetWidth(textureImage);
 NSInteger texHeight = CGImageGetHeight(textureImage);
 GLubyte *textureData = (GLubyte *)malloc(texWidth * texHeight * 4);
 CGContextRef textureContext = CGBitmapContextCreate(textureData,
              texWidth,
              texHeight,
              8,
              texWidth * 4,
              CGImageGetColorSpace(textureImage),
              kCGImageAlphaPremultipliedLast);

 //The Fix:
 //CGContextClearRect(textureContext, CGRectMake(0.0f, 0.0f, texWidth, texHeight));

 CGContextDrawImage(textureContext, CGRectMake(0, 0, (float)texWidth, (float)texHeight), textureImage);
 CGContextRelease(textureContext);

 glBindTexture(GL_TEXTURE_2D, location);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);

 free(textureData);

 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

I then load in my textures like so in the initWithCoder method:

glGenTextures(NUM_OF_TEXTURES, &textures[0]);
[self loadTexture:@"1.png" intoLocation:textures[0]];
[self loadTexture:@"2.png" intoLocation:textures[1]];
[self loadTexture:@"3.png" intoLocation:textures[2]];
[self loadTexture:@"4.png" intoLocation:textures[3]];
[self loadTexture:@"5.png" intoLocation:textures[4]]; 

Now this works great for me, but when the images loaded contain transparent areas, they will show the previous images behind them.

For example, if all five images have transparent areas on them:

  • 1.png will show as it should.
  • 2.png will show with 1.png in the background.
  • 3.png will show with 2.png in the background with 1.png in the background.
  • etc…

I thought this would be in my drawing code, but even when I disable GL_BLEND this still happens. I am drawing using vertex arrays using GL_TRIANGLE_FAN.

EDIT: Further explanation

Here are the 3 textures I’m using in my game:

alt text

Using the code to load the textures and after binding them and drawing, this is what happens:

alt text

Surely this is not transparency functioning as intended. If anyone could help that would be great.

Thanks

  • 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-16T15:18:20+00:00Added an answer on May 16, 2026 at 3:18 pm

    I had this same problem. You need to clear the CGContextRef before drawing the texture into it. It just happens to hold the last image, it could just as well be uninitialized memory or something.

    CGContextClearRect( cgContext, CGRectMake( 0.0f, 0.0f, width, height ) );
    

    Call this right before your CGContextDrawImage.

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

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.