In the renderer of OpenGL I try the following code:
ByteBuffer buf = ByteBuffer.allocate(1 * 1 * 4);
GLES20.glReadPixels(60, 100, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
float red = buf.get()/255.0f;
float green = buf.get()/255.0f;
float blue = buf.get()/255.0f;
float alpha = buf.get();
EngineX.show("red: " + red + " green: " + green + " blue: " + blue + " alpha: " + alpha);
The alpha value always returns -1.0
.
//Implementation of Class SurfaceView //I do not do anything special with this implementation
public class GLSurfaceViewX extends GLSurfaceView
{
BaseActivity activity;
public GLSurfaceViewX(Context context)
{
super(context);
activity = (BaseActivity) context;
getHolder().setFormat(PixelFormat.RGBA_8888);
}
}
//This is the activity //Here the view of drawing is created
public abstract class BaseActivity extends Activity
{
private EngineX engine;
GLSurfaceViewX view;
@Override
protected void onCreate(final Bundle pSavedInstanceState)
{
super.onCreate(pSavedInstanceState);
if (!isOGLES20Compatible())
{
view = null;
showErrorDialogBox();
return;
}
engine = new EngineX(this);
view = new GLSurfaceViewX(this);
view.setEGLContextClientVersion(2);
view.setRenderer(engine);
// Render the view only when there is a change in the drawing data
view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
setContentView(view);
}
@Override
protected void onResume()
{
EngineX.show("BaseActivity: onResume");
super.onResume();
if (view != null)
{
view.onResume();
}
}
@Override
protected void onPause()
{
EngineX.show("BaseActivity: onPause");
super.onPause();
if (view != null)
{
view.onPause();
}
}
@Override
protected void onDestroy()
{
if (engine != null)
{
engine.closeGame();
}
super.onDestroy();
}
/* This method verify that your Phone is compatible with OGLES 2.x */
private boolean isOGLES20Compatible()
{
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return (info.reqGlEsVersion >= 0x20000);
}
/* show an error message */
private void showErrorDialogBox()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Sorry! OpenGL ES 2.0 not supported on device.").setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}