-
Notifications
You must be signed in to change notification settings - Fork 211
Home
ChillingVan edited this page Nov 29, 2020
·
7 revisions
Welcome to the android-openGL-canvas wiki!
- Custom your view.
public class MyGLView extends GLTextureView {
public MyGLView(Context context) {
super(context);
}
public MyGLView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onGLDraw(ICanvasGL canvas) {
// draw things with canvas here
}
}
- Continuous rendering view
public class MyGLView extends GLContinuousTextureView {
public MyGLView(Context context) {
super(context);
}
public MyGLView(Context context, AttributeSet attrs) {
super(context, attrs);
}
// This will call continuously and won't stop untill onPause() is called
@Override
protected void onGLDraw(ICanvasGL canvas) {
// draw things with canvas here
}
}
...
// Remember to call this in activity lifecycle
@Override
protected void onResume() {
super.onResume();
myGLView.onResume();
}
@Override
protected void onPause() {
super.onPause();
myGLView.onPause();
}
- Canvas
canvas.drawBitmap(textBitmap, left, top);
// transform
canvas.save();
canvas.rotate(rotateDegree, x, y);
canvas.drawBitmap(bitmap, left, top);
canvas.restore();
// or
CanvasGL.BitmapMatrix matrix = new CanvasGL.BitmapMatrix();
matrix.postScale(2.1f, 2.1f);
matrix.postRotate(90);
canvas.drawBitmap(bitmap, matrix);
// apply filter to the bitmap
textureFilter = new ContrastFilter(2.8f);
canvas.drawBitmap(bitmap, left, top, textureFilter);
And there are many filters:
- PixelationFilter
- HueFilter
- SaturationFilter
- TwoTextureFilter : The base filter that handles mix of two bitmap.
- LightenBlendFilter
- FilterGroup : Has a filter list that handles multiple filters.
See the example FilterActivity and CompareCanvasActivity for more details.
- OffScreenCanvas, see the OffScreenActivity for more detail.
OffScreenCanvas offScreenCanvas = new OffScreenCanvas(400, 400) {
@Override
protected void onGLDraw(ICanvasGL canvas) {
//draw things
}
};
offScreenCanvas.start();
// call offScreenCanvas.getDrawingBitmap to fetch bitmap
- The usage of GLSurfaceTextureProducerView GLSharedContextView
// or glSurfaceTextureProducerView.getCurrentEglContext() if the context has been created.
glSurfaceTextureProducerView.setOnCreateGLContextListener(new GLThread.OnCreateGLContextListener() {
@Override
public void onCreate(EGLContext eglContext) {
glSharedContextView.setSharedEglContext(eglContext);
}
});
glSurfaceTextureProducerView.setOnSurfaceTextureSet(new GLSurfaceTextureProducerView.OnSurfaceTextureSet() {
@Override
public void onSet(SurfaceTexture surfaceTexture, RawTexture surfaceTextureRelatedTexture) {
glSharedContextView.setSharedTexture(surfaceTextureRelatedTexture, surfaceTexture);
});
- So the view extends BaseGLTextureView can produce eglContext.
- The view extends GLSurfaceTextureProducerView can produce surfaceTexture.
- The view extends GLSharedContextView can use eglContext from other place.
- This is useful for camera, see the TextureCameraActivity for more details.
The preview from camera is default flipped. If you want to flip it, try setIsFlippedVertically from the RawTexture provided.
For rotation, first you should know what your camera rotation is and use camera.setDisplayOrientation in right way. Or if you want to rotate the preview, try ICanvasGL.BitmapMatrix. Or use ICanvasGL.rotate.(With canvas.save() and canvas.restore). See AnimActivity sample code.