Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
alecgdouglas
Posts: 3
Registered: ‎11-06-2011
My Device: Playbook

Using Images from the Camera as Textures

Hello there,

 

I'm currently working on an app in C++ using Cocos2dX (from here: https://github.com/blackberry/Cocos2D-X), and I'd like to be able to use the images taken with the camera as textures (think of something along the lines of the scrapbook app).

I am able to locate the camera pictures and get a list of images, but I'm a bit stuck when it comes to actually loading them as textures, as they are too large (max texture size is apparently 2048x2048, while the images from the back camera are 2592x1456) so in doing something like this:

 

CCSprite* photoSprite = CCSprite::spriteWithFile( filePath.c_str() );

 

a problem ocurs when the dimensions of the file is checked.

(This happens in CCTexture2D.cpp around line 243. I suspect it might be because the max texture size is not set properly (if at all) for the Playbook in Cocos2d because 2048x2048 appears to be the default max size. I tried temporarily commenting out the size-checking code to get around this but now the textures, when loaded, are just completely white.)

 

I also tried writing something in C using the bbutil function  "bbutil_load_texture" but that only seems to handle .png files, whereas the pictures from the camera are in jpeg format.

 

I'm open to any suggestions, and I appreciate your help!

 

Thanks,

Alec

Contributor
marlongame
Posts: 11
Registered: ‎11-01-2011
My Device: Playbook

Re: Using Images from the Camera as Textures

Hello if you try to upload a image bigger than 2048*2048 will cause several visual problems.

 

You need to apply a function that change the size of the image to a smaller one.

Retired
dtomilovskiy
Posts: 36
Registered: ‎10-26-2011
My Device: RIM Developer

Re: Using Images from the Camera as Textures

[ Edited ]

Bear in mind that bbutil works with bare GL. I'm not sure how cocos2dx implements its sprites on top of gl textures, but glTexImage2D/glTexSubImage2D will give GL_INVALID_VALUE in case width/height are less than 0 or bigger than GL_MAX_TEXTURE_SIZE. This is likely to be the cause for a white texture as no data is uploaded in your case.

 

I'd recomment resampling/clipping your camera texture to fit into the max texture size.

 

I am not sure if cocos2dx provides this sort of functionality though. Maybe jpg library can do this for you.