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

Re: bbutil_load_texture

http://i48.tinypic.com/rh2tqe.png
I tried to use lots of colour/shapes to try and find which part of the image is rendering.
Developer
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

IMAGEpointer->vertices[0] = 0.0f+150;
IMAGEpointer->vertices[1] = 0.0f + 500;
IMAGEpointer->vertices[2] = IMAGEpointer->width+150;
IMAGEpointer->vertices[3] = 0.0f + 500;
IMAGEpointer->vertices[4] = 0.0f+150;
IMAGEpointer->vertices[5] = IMAGEpointer->height + 500;
IMAGEpointer->vertices[6] = IMAGEpointer->width+150;
IMAGEpointer->vertices[7] = IMAGEpointer->height + 500;

I added some constants on the end to try and centre the image on the view a bit.
I will use my IMAGEpointer->x and ->y instead of 0.0f eventually to allow positioning.
note: I scaled the image down in the render sequence.

Im using Paint.NET to save the image file in 24bit png format.
I would assume it is writing an alpha channel as well as usual rgb but to make sure I deleted the white part of "bgcolour.png" so it definitely has alpha parts and will upload the playbook image asap
Developer
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

http://i47.tinypic.com/2h4wzua.jpg

This is the new image. I removed some parts and replaced with transparency so should have an alpha channel
Trusted Contributor
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: bbutil_load_texture


MikePembo951 wrote:
http://i47.tinypic.com/2h4wzua.jpg

This is the new image. I removed some parts and replaced with transparency so should have an alpha channel

Is this the image from your screenshot or is this the image you use to generate the texture?

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

Re: bbutil_load_texture

this is the screenshot. This http://i48.tinypic.com/rh2tqe.png is the image. The background is cyan/blue and the weird pink/orange is supposed to be the image http://i47.tinypic.com/2h4wzua.jpg
Developer
Posts: 107
Registered: ‎02-15-2012
My Device: Blackberry Playbook 32GB

Re: bbutil_load_texture

Just read this:

Texture upload and pixel reads

You create a texture and upload the pixels with glTexImage2D (or glTexImage1D, glTexImage3D). However, the program crashes on upload, or there seems to be diagonal lines going through the resulting image. This is because the alignment of each horizontal line of your pixel array is not multiple of 4. That is, each line of your pixel data is not a multiple of 4. This typically happens to users loading an image that is of the RGB or BGR format (in other words, 24 bpp image).

Example, your image width = 401 and height = 500. The height doesn't matter. What matters is the width. If we do the math, 401 pixels x 3 bytes = 1203. Is 1203 divisible by 4? In this case, the image's data alignment is not 4. The question now is, is 1203 divisible by 1? Yes, so the alignment is 1 so you should call glPixelStorei(GL_UNPACK_ALIGNMENT, 1). The default is glPixelStorei(GL_UNPACK_ALIGNMENT, 4). Unpacking means sending data from client side (the client is you) to OpenGL.

And if you are interested, most GPUs like chunks of 4 bytes. In other words, RGBA or BGRA is prefered. RGB and BGR is considered bizarre since most GPUs, most CPUs and any other kind of chip don't handle 24 bits. This means, the driver converts your RGB or BGR to what the GPU prefers, which typically is BGRA.

 

This could be the problem and would explain why it looks kinda diagonal instead of straight.

Im going to look in to my PNG files see if alpha if definitely being exported

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

Re: bbutil_load_texture

I used your image in one of my apps and it rendered fine.

 

I haven't taken a deep look at your coordinates.  But remember that when you use GL_TRIANGLE_STRIP, your vertex array needs to go in a zigzag instead of matching the order you specify them for the texture coordinates.

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

Re: bbutil_load_texture

I was wrong,

Alpha is being imported correctly,

http://i50.tinypic.com/23h4t2o.jpg

 

I replaced some colours with transparency and a colour or two have dissappeared and been replaced the with cyan/blue background. 

(Image size 1024x1024)

 

I am really confused... what am I doing wrong?

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

Re: bbutil_load_texture

I checked my vertices and they are fine. Swapped them round (instead of lowerleft, lowerright, topleft, topright I tried lowerleft, top left, lower right, top right.) but it made no difference.

 

What did you use to load the RGBA values from the png file to a rgba array?

Did you write your own png parser or use anothers or did you use bbutil load texture which loads the whole file in to a texture id for you.

 

I think this is the problem. Probably writing my own png parser is a better idea than using bbutil_load_texture.

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

Re: bbutil_load_texture

[ Edited ]

I have never used bbutil_load_texture and I have never looked into that part of the code so I don't know what it does.

 

Here is my code for loading the image into texture:

 

	int rc;


	img_t img;
	img_lib_t ilib = NULL;

	if ((rc = img_lib_attach(&ilib)) != IMG_ERR_OK) {
	                fprintf(stderr, "img_lib_attach() failed: %d\n", rc);
	                return -1;
	        }

	/* initialize an img_t by setting its flags to 0 */
	img.flags = 0;
	img.format = IMG_FMT_RGBA8888;
	img.flags |= IMG_FORMAT;

	if ((rc = img_load_file(ilib, "app/native/rh2tqe.png", NULL, &img)) != IMG_ERR_OK) {
	   fprintf(stderr, "failed to load paper.png");
	}

	glEnable(GL_TEXTURE_2D);

	glGenTextures(4, texture);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.w, img.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.access.direct.data);

 

 

Sucroid.com
Sweet Apps for the Fans