Strange artifact on rendered image.. (is it png premultiply?)

Apprentice
Posts: 10
Joined: 2009.01
Post: #1
Hello,

Sorry for thoses that might already have seen this message in the cocos2D mailing list.

I'm using Quartz to pre-render an image composed of several drawAtPoint calls using UIImages (pngs), then used as a texture for a cocos2d sprite.

#### PRE RENDERING CODE (simplified) #####
UIGraphicsBeginImageContext( CGSizeMake(w, h) );
// BG
[[UIImage imageNamed: @"bg-r.png"] drawAtPoint: ccp(0,0)];
// Clan bg
[[UIImage imageNamed: @"coin.png"] drawAtPoint: ccp(0, 0)];
UIImage *cardTexture = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
#######

I am pretty sure it has nothing to do with cocos itself, but it looks like a tricky png format & iphone stuff.
Everything works fine on the simulator, but on the iphone, I got a very strange artifact that it's bothering me...

Simulator:
http://img.skitch.com/20090503-gdwfxqn35...ctp6ty.jpg

Device:
http://img.skitch.com/20090503-d239xhj7p...m3nj51.jpg

I have been trying differents things to pinpoint the cause, none of them worked:
- re-save the bogus files (maybe i missed something there)
- draw directly the clan without the BG (to see if it was a blending issue because I was drawing 2 on top of anothers)

Does anyone knows what is happening there?

Is it the premultiply issue? I am expecting that the iphone will handle everything correctly since I'm using the high level functions to do the drawing..

In other news, I'm totally in love with cocos2d and I plan to write a post-mortem of the game with details of implementation.

Thanks for your help,

Sebastien
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2009.01
Post: #2
Found the answer:

http://developer.apple.com/iPhone/librar...Q/faq.html

Last Q/A.

Indeed the premultiply..
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #3
Premultiplying won't produce those artifacts - my only guess is that you're not clearing the CGContext before drawing, but I don't do much work with CG/UIkit so I couldn't tell ya for sure...
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #4
That's what I was thinking too. I've only seen those strange little artifacts when using less than 64x64 tiles with alpha in them. Like you said, for small stuff, you gotta clear the CGContext first before loading the image from disk into memory. Don't know how they'd show up for larger stuff, but I'd put my money on un-initialized memory.
Quote this message in a reply
Post Reply