Overlay PNG Transparency

Started by shabeepk, September 14, 2011, 02:34:22 PM

Previous topic - Next topic

shabeepk

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:


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


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:


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


EgonOlsen

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 new Texture(res.openRawResource(R.raw.texturename)) instead. Also make sure that you are blitting with transparent=true;

shabeepk

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.


K24A3

Quote from: 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 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.

EgonOlsen

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.

K24A3

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.