0

I have a normal UIKit Application but I want to use cocos2d for a little job. I want to use the function glReadPixels, for that I need a cocos2d image -> CCSprite.

I am working for 2 days now on this problem, because I am getting this error:

2012-08-08 16:58:50.673 iBlaulicht 2[11801:16a03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' +[NSString stringWithCString:encoding:]: NULL cString' ** First throw call stack: (0x1f88022 0x1b9bcd6 0x1f30a48 0x1f309b9 0x16050c7 0x62687 0x62589 0x62317 0x86979 0x47c5c 0x2d63 0xdc5a1e 0x222d 0xcfc386 0xcfd274 0xd0c183 0xd0cc38 0xd00634 0x338cef5 0x1f5c195 0x1ec0ff2 0x1ebf8da 0x1ebed84 0x1ebec9b 0xcfcc65 0xcfe626 0x20cb 0x2065) terminate called throwing an exception(lldb)

this is my code:

    - (id)initWithImage:(UIImage *)drawnImage{

    if (self == [super init]) {



        CCTexture2D *tex = [[[CCTexture2D alloc] initWithImage:drawnImage resolutionType:kCCResolutionRetinaDisplay] autorelease];
        CCSprite *imageSprite = [CCSprite spriteWithTexture:tex];


        imageSprite.position = CGPointMake(0, 0 );
        [self addChild:imageSprite];



    }


    return self;
}


- (NSArray *)determinePixels{


    for (int y_direction = 0; currentImage.size.height > y_direction; y_direction += 20) {


        for (int x_direction = 0; currentImage.size.width > x_direction; x_direction += 20) {

            Byte pixelColor[4];
            glReadPixels(x_direction, y_direction, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixelColor[0]);

            // Just to test
            NSLog(@"0");
        }
    }

    return 0;
}

I appreciate any help...Thanks. Chris

2 Answers 2

1

Look at Ray Wenderlich's post on this topic;

http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit

4
1

I found the solution myself !

I added a EAGLView and used a CCDirector to set it as OpenGl View.

- (id)initWithImage:(UIImage *)drawnImage{

    if (self == [super init]) {

        EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0, 0, 250,350)];


        CCDirector *director = [CCDirector sharedDirector];
        [director setOpenGLView:glview];

        CCTexture2D *tex = [[CCTexture2D alloc] initWithImage:drawnImage resolutionType:kCCResolutionRetinaDisplay];
        imageSprite = [KKPixelMaskSprite spriteWithTexture:tex];


        imageSprite.position = CGPointMake(0, 0 );
        [self addChild:imageSprite];



    }


    return self;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.