Loading PNG to GLuint

Apprentice
Posts: 14
Joined: 2010.01
Post: #16
I'm very sorry for the bump, but the following code freezes the app:

Code:
GLuint LoadTextureWithAlpha(NSString *imageFileName)
{
    GLuint            texID;
    CGImageRef        image;
    void            *pixels;
    unsigned        width, height;
    CGContextRef    context;
    CGColorSpaceRef    colorSpace;
    
    image = [[UIImage imageNamed:imageFileName] CGImage];
    if (image == nil)
    {
        NSLog(@"could not find %@", imageFileName);
        return 0;
    }
    width = CGImageGetWidth(image);
    height = CGImageGetHeight(image);
    
    pixels = calloc(width * height * 4, 1);
    colorSpace = CGImageGetColorSpace(image);
    context = CGBitmapContextCreate(pixels, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
    
    glGenTextures(1, &texID);
    glBindTexture(GL_TEXTURE_2D, texID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    
    CGImageRelease(image);
    CGContextRelease(context);
    free(pixels);
    
    return texID;
}
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #17
wademcgillis Wrote:I'm very sorry for the bump, but the following code freezes the app:

I just tested it and it works for me in the sim for 3.1.2.

Need more info. Does it crash on the device or the sim? Which OS? Where exactly does it crash? What size is the image you are loading?
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2010.01
Post: #18
AnotherJake Wrote:I just tested it and it works for me in the sim for 3.1.2.

Need more info. Does it crash on the device or the sim? Which OS? Where exactly does it crash? What size is the image you are loading?

It doesn't crash, it freezes. There's a difference. Vista has frozen for me, but Ubuntu has crashed.

I'm using the Simulator version 3.1 on OS X 10.5.7. The image is 64x64.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #19
wademcgillis Wrote:It doesn't crash, it freezes. There's a difference. Vista has frozen for me, but Ubuntu has crashed.
Okay, I wasn't aware of that. What particular line of that code causes it to "freeze"?

What version of iPhone OS are you building for?
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2010.01
Post: #20
AnotherJake Wrote:Okay, I wasn't aware of that. What particular line of that code causes it to "freeze"?

What version of iPhone OS are you building for?

I am no longer experiencing this problem.
I now have a new one: http://www.idevgames.com/forum/showthrea...post155404
Quote this message in a reply
Post Reply