ZhouWeikuan / cocos2d

cocos2d for android, based on cocos2d-android-0.82, and now ported from cocos2d-iphone 0.99.4. The googlecode address is here: http://code.google.com/p/cocos2d-android-1/ . There are several demos to watch.
610 stars 291 forks source link

Blurry Texture When > 1024x1024 #35

Closed irwinb closed 12 years ago

irwinb commented 12 years ago

Is this normal behavior? Whenever I try to load a PNG with the size of 2048x1024 or 2048x2048, it appears blurry when rendered on the screen.

A 1024x1024 or smaller PNG works fine.

I'm loading these PNGs via CCSpriteFrameCache.addSpriteFrames(file.plist) and drawing CCSprites created by calling CCSprite.sprite("frame", true).

I'm pretty sure it's not because of the hardware, i'm testing on an Atrix 4G that has a GL_MAX_TEXTURE_SIZE of 2048..if that even matters.

dustinanon commented 12 years ago

This is by design actually... the image is downscaled if it's larger than 1024x1024 in order to save memory. Then the downscaled texture is scaled back up to the original proportion.

irwinb commented 12 years ago

Oh. Interesting. What are the relevant files that implement this behavior so that I may adjust them so suit my needs :).

Thanks again for your help dustin btw..

dustinanon commented 12 years ago

Check CCTexture2D, specifically kMaxTextureSize and initWithImage().

Note that on android, the largest texture that you can use is 2048 x 2048. I'm not exactly sure why they set kMaxTextureSize to 1024, but maybe that's just how they process... maybe that's more like kHalfMaxTextureSize instead, lol.

Anyway, just be careful. If you change it to 2048 and it crashes, well, know that it's just too large for Android's limit :)

I ran into this issue before when I was trying to use large textures on AndEngine.

My best advice to you is to downscale large images by hand. That way you can be sure of the quality and it's not just some rush job performed by Cocos2D.

irwinb commented 12 years ago

Ok, thanks for the info :)