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
Developer
MikePembo951
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB
Accepted Solution

bbutil_load_texture

Hi,

I was trying to use bbutil_load_texture to render a png image, however the image isnt rendering correctly. I have tried loading other images as well to check if it's a problem with my pngs. The images rendered are messed up; some colours from the image are there just not in the correct positions. Are there any functions I need to call before using bbutil_load_texture? Is my rendering code correct? What parameters should I provide when using bbutil_load_texture()?

 

Im thinking it might be best to write my own png parser, anyone got any tips?

 

Rendering code:

glEnable(GL_TEXTURE_2D);
//glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBindTexture(GL_TEXTURE_2D, imagepointer->tex);

//supply pointers
glVertexPointer(2, GL_FLOAT, 0, imagepointer->vertices);
glTexCoordPointer(2, GL_FLOAT, 0, imagepointer->texcoords);
//draw
glPushMatrix();
//apply transformations
glScalef(0.4f,0.4f,0.4f); //just scaled it down a bit to be able to see the whole image.
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
//finish up
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);

 

my texcoords used: 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f

 

 

Load:

float u,v;

u =  1.0f, v = 1.0f;

bbutil_load_texture((char*)CONTENT.Images[0][0].filename.c_str(), NULL, NULL, &u, &v, &CONTENT.Images[0][0].tex))

 

Why does bbutil_load_texture require a pointers to a pair of uv coordinates? What is it doing with them?

When I looked through the code in the bbutil source it seems to do almost nothing with width and height.

 

 

 

Developer
MikePembo951
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

im clearing the screen with

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 250, 100, 1);

which is where the blue/green background comes from.

Posting an image asap...
Developer
MikePembo951
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

[ Edited ]

This is the screenshot from the playbook: (cyan background)

http://i46.tinypic.com/2zxms0n.jpg

 

And the image should look like this:

http://i48.tinypic.com/1el2iq.png

 

Looks to me like im getting only the lower part of the image, and stretched/rotated.7

 

Doesnt seem to be a problem loading unless its my parameters used for bbutil_load_texture.

Probably a problem with my rendering

Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: bbutil_load_texture

What are the dimensions of your image?  It needs to be a power of 2 I think.  E.g. 256 x 256, 512 x 512, or 1024 x 1024.

Sucroid.com
Sweet Apps for the Fans
Developer
MikePembo951
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

[ Edited ]

i've heard about the powers of 2 requriement but didnt take notice since the GoodCitizen tutorial I looked at used images of resolution 42x44 which neither is a power of 2 (this is the radio buttons it uses).

 

Is this a requirement of Opengles1.1 or bbutil_load_texture?

 

this is my first venture into opengl as I've always used directx, so any tips for opengl beginners would be greatly appreciated. :smileyhappy:

 

thanks,

 

ps I also found I has to save my pngs in 24bit form as the bbutil_load_texture didnt like 32bit pngs. 

Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: bbutil_load_texture

On regular OpenGL, there might be an arbitrary rectangle extension to handle non-power-of-two images.

 

I don't think you have such luxury with OpenGL ES.  So test with a power-of-two image (take something 128 x 128) and see if it works.

Sucroid.com
Sweet Apps for the Fans
Developer
MikePembo951
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

debugging now, expanded the image to 1024x1024 from 1024x600.
Im guessing I can choose not to render the extra 424 pixels?
Developer
MikePembo951
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

[ Edited ]

ok now I got this:
http://i48.tinypic.com/16bx1f4.jpg

The image is still messed up :/
Any ideas?

 

Is it my texture coordinates? 

Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: bbutil_load_texture

Could you also post your 1024 x 1024 picture?

 

Does it have an alpha channel?

Sucroid.com
Sweet Apps for the Fans
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: bbutil_load_texture

What are your values in  imagepointer->vertices?

Sucroid.com
Sweet Apps for the Fans