views:

189

answers:

1

I am doing my iphone graphics using Opengl. In one of my projects i need to use an image, which i need to be used as a texture in opengl. The png image is 512 * 512 in size, its background is transparent and the image has a thick blue line in its center.

When i apply my image to a polygon in opengl, the texture appears as if, the transparent part in the image as black and the thick blue line is seen as itself. Inorder to remove the black part i used Blending.

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

Then my black part of the texture in the polygon is removed. Now only the blue band is seen. Thus the problem is solved.

But, i want to add many such images and make many objects in opengl. I am able to do that, but the frame rate per second is very slow when i add more and more images to objects. But when i comment blending, fps is normal, but the images are not seen.

Since i do not have good fps, the graphics is bit slow and got a shaky effect.

So anyone please help me

1) Is there any other method than Blending to solve my problem?

2) How can i improve the fps of opengl app? What all steps need to be taken inorder to work my graphics properly?

Thanks in advance...

A: 

If you want to have transparent parts of an object, the only way is to blend to pixel data for the triangle with what is currently in the buffer (what you are currently doing). Normally, when using solid textures, the new pixel data for a triangle just overwrites what ever was in buffer (as long as it is closers, ie z-buffer). But with transparency, it has start looking at the transparency of that part of the texture, look at what is behind it, all the way back to something solid. Then has combine all of those over lapping layers of transparent stuff till you get the final image.

If all you are wanting your transparency for is something like a simple tree sprite, and removing the 'stuff' form the sides of the trunk etc. Then you may be better of providing more complex geometry that actually defines the shape of the trunk and thus not need to bother with transparency.

Sadly, I don't think there is much you can do to try to speed up your FPS, other then cut down the amount of transparency you are calculating. Maybe even adding some optimization that checks images to see if it can turn of alpha blending for this image or not. Depending on how much you are trying to push through, may save time in the long wrong.

thecoshman
Thanks for your reply. Here in my project i am using 512 * 512 textures, with which almost 90% are transparent part. So by your words it seems if i can reduce the transparent percentage of the texture i can increase the speed.. That is a good information for me.But by doing so, i get my objects little bigger in the iphone screen as we see. So it seems there is no other way than blending in opengl inorder to remove the black part of textures..?
quint
Instead of blending you can try alpha testing, which could be slightly faster when you don't need to blend, and just want full-opaque and full-transparent regions. `glEnable(GL_ALPHA_TEST); glAlphaTest(GL_LESS, 1.0)` discards all pixels that aren't 100% opaque. I wouldn't expect this to give great performance gains, since the tile-based renderer still can't discard hidden pixels the way it can when there's no alpha going on.
codewarrior
Essentially, transparency is expensive on the iPhone because the hardware is optimized for fully opaque textures. You need to minimize your use of blending and alpha in order to increase performance. If you can't proceed using only fully-opaque textures, you need to break things up so that only the parts that really need blending use it, and the rest of the scene is rendered first with blending disabled.
codewarrior