www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: shabeepk on September 14, 2011, 02:34:22 pm

Title: Overlay PNG Transparency
Post by: shabeepk on September 14, 2011, 02:34:22 pm
Hello all,

I am very new to JPCT. I am developing an application on android using JPCT and want to add some overlay textures to it.

I am adding the overlay in the onSurfaceChanged method like this:

Code: [Select]
public void onSurfaceChanged(GL10 gl, int w, int h)
{
if (fb != null)
{
fb.dispose();
}

fb = new FrameBuffer(gl, w, h);

int displayWidth = fb.getWidth();
int displayHeight = fb.getHeight();

int centerX = displayWidth / 2;
int centerY = displayHeight / 2;

Log.i(this.getClass().toString(), "Creating overlay crosshair at : [" + displayWidth + ", " + displayHeight + "]");
Overlay crosshairOverlay = new Overlay(world, centerX - 15, centerY - 15, centerX + 15, centerY + 15, "crosshair");

crosshairOverlay.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
}

My Activity's onCreate method looks like this

Code: [Select]
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

mGLView = new GLSurfaceView(getApplication());

mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser()
{
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
// Ensure that we get a 16bit framebuffer. Otherwise, we'll fall
// back to Pixelflinger on some device (read: Samsung I7500)
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);

return configs[0];
}
});

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

I am loading the texture (which is a PNG file with transparent pixels) in the onSurfaceCreated method like this:

Code: [Select]
Texture crosshair = new Texture(BitmapHelper.convert(getResources().getDrawable(R.drawable.crosshair)), true);

Now the issue is, when the overlay gets shown, it shows the transparent pixels as black.

Am I missing something? I was thinking I may need to enable opengl alpha blending somehow, but I don't know how to do that using JPCT.

Any help would be really appreciated ...

Thanks

Title: Re: Overlay PNG Transparency
Post by: EgonOlsen on September 14, 2011, 09:26:51 pm
Maybe the convert-method in the BitmapHelper doesn't take care of the alpha channel. It's not a good idea to put textures into /drawable anyway. Try to put them into /raw and load them via
Code: [Select]
new Texture(res.openRawResource(R.raw.texturename)) instead. Also make sure that you are blitting with transparent=true;
Title: Re: Overlay PNG Transparency
Post by: shabeepk on September 15, 2011, 02:16:11 am
I am using it in an overlay.

I am not manually blitting it. How do i set transparent = true when using an overlay. I tried searching something like that but didn't find it.

Please advise.
Title: Re: Overlay PNG Transparency
Post by: EgonOlsen on September 15, 2011, 06:54:37 am
Well...how about this one: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/Overlay.html#setTransparency(int) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/Overlay.html#setTransparency(int))?
Title: Re: Overlay PNG Transparency
Post by: K24A3 on September 17, 2011, 07:22:15 pm
Maybe the convert-method in the BitmapHelper doesn't take care of the alpha channel. It's not a good idea to put textures into /drawable anyway. Try to put them into /raw and load them via
Code: [Select]
new Texture(res.openRawResource(R.raw.texturename)) instead. Also make sure that you are blitting with transparent=true;

If the textures are placed in "drawable" or "drawable-nodpi", they should work fine since they will not be resized automatically.

If you place textures in drawable-hdpi, drawable-mdpi, or drawable-ldpi, Android may resize them to non-square texture sizes, causing textures to appear all white or appear corrupted. It basically depends on the DPI of the screen.
Title: Re: Overlay PNG Transparency
Post by: EgonOlsen on September 18, 2011, 11:09:58 am
Might be the case in newer version, but definitely not in some older ones. I've experienced that scaling problem myself on one device when using drawable only.
Title: Re: Overlay PNG Transparency
Post by: K24A3 on September 18, 2011, 02:52:44 pm
I guess it depends on the hardware or kernel modules. Textures in drawable-hdpi were auto resized on some newer Nexus devices and on my Tegra2 tablet, but it didn't affect the DesireHD and many other phones. I haven't had any problems with putting textures in 'drawable', but my app is limited to Android 2.1 and above so that cuts out a lot of earlier phones.