Android GLSurfaceView - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android GLSurfaceView class.

This code example shows how to use the following methods:setRenderer
 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
 
        mGLSurfaceView = new GLSurfaceView(this);
 
        // Set an OpenGL ES 1.x-compatible renderer. 
        mGLSurfaceView.setRenderer(new GLBenchRenderer(this));
        setContentView(mGLSurfaceView);
 
    } 
 
    private GLSurfaceView mGLSurfaceView;
} 
7
CodeRank
This code example shows how to use the following methods:setEGLConfigChooser, setEGLContextClientVersion, setRenderer
public class StencilTest extends Activity {
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        if (detectOpenGLES20())  
        { 
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible 
            // context, and set an OpenGL ES 2.0-compatible renderer. 
            mGLSurfaceView.setEGLContextClientVersion(2);
            // Request an 565 Color buffer with 16-bit depth and 8-bit stencil 
            mGLSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
            mGLSurfaceView.setRenderer(new StencilTestRenderer(this));
        }  
        else 
        { 
        	Log.e("StencilTest", "OpenGL ES 2.0 not supported on device.  Exiting...");
        	finish();
            
7
CodeRank
This code example shows how to use the following methods:setEGLContextClientVersion, setRenderer
 */ 
public class GLES20Activity extends Activity {
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        if (detectOpenGLES20()) { 
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible 
            // context, and set an OpenGL ES 2.0-compatible renderer. 
            mGLSurfaceView.setEGLContextClientVersion(2);
            mGLSurfaceView.setRenderer(new GLES20TriangleRenderer(this));
        } else { 
            // Set an OpenGL ES 1.x-compatible renderer. In a real application 
            // this renderer might approximate the same output as the 2.0 renderer. 
            mGLSurfaceView.setRenderer(new TriangleRenderer(this));
        } 
        setContentView(mGLSurfaceView);
    } 
 
    private boolean detectOpenGLES20() { 
7
CodeRank
This code example shows how to use the following methods:setEGLContextClientVersion, setRenderer
public class MipMap2D extends Activity {
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        if (detectOpenGLES20())  
        { 
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible 
            // context, and set an OpenGL ES 2.0-compatible renderer. 
            mGLSurfaceView.setEGLContextClientVersion(2);
            mGLSurfaceView.setRenderer(new MipMap2DRenderer(this));
        }  
        else 
        { 
        	Log.e("MipMap2D", "OpenGL ES 2.0 not supported on device.  Exiting...");
        	finish();          
        } 
        setContentView(mGLSurfaceView);
    } 
7
CodeRank
This code example shows how to use the following methods:setEGLContextClientVersion, setRenderer
public class TextureWrap extends Activity {
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        if (detectOpenGLES20())  
        { 
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible 
            // context, and set an OpenGL ES 2.0-compatible renderer. 
            mGLSurfaceView.setEGLContextClientVersion(2);
            mGLSurfaceView.setRenderer(new TextureWrapRenderer(this));
        }  
        else 
        { 
        	Log.e("TextureWrap", "OpenGL ES 2.0 not supported on device.  Exiting...");
        	finish();          
        } 
        setContentView(mGLSurfaceView);
    } 
7
CodeRank
This code example shows how to use the following methods:setRenderer
        // Go fullscreen 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
         
        GLSurfaceView view = new GLSurfaceView(this);
        view.setRenderer(new OpenGLRenderer());
        setContentView(view);
    } 
 
	@Override 
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present. 
		getMenuInflater().inflate(R.menu.open_gldemo, menu);
		return true; 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:setEGLConfigChooser, setRenderer, getHolder
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        // Create our Preview view and set it as the content of our 
        // Activity 
        mGLSurfaceView = new GLSurfaceView(this);
        // We want an 8888 pixel format because that's required for 
        // a translucent window. 
        // And we want a depth buffer. 
        mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
        // Tell the cube renderer that we want to render a translucent version 
        // of the cube: 
        mGLSurfaceView.setRenderer(new CubeRenderer(true));
        // Use a surface format with an Alpha channel: 
        mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(mGLSurfaceView);
    } 
 
    @Override 
    protected void onResume() { 
7
CodeRank
This code example shows how to use the following methods:setEGLContextClientVersion, setRenderer
public class SimpleTextureCubemap extends Activity {
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        if (detectOpenGLES20())  
        { 
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible 
            // context, and set an OpenGL ES 2.0-compatible renderer. 
            mGLSurfaceView.setEGLContextClientVersion(2);
            mGLSurfaceView.setRenderer(new SimpleTextureCubemapRenderer(this));
        }  
        else 
        { 
        	Log.e("SimpleTextureCubemap", "OpenGL ES 2.0 not supported on device.  Exiting...");
        	finish();          
        } 
        setContentView(mGLSurfaceView);
    } 
7
CodeRank
This code example shows how to use the following methods:setRenderer
        mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
 
        // Create our Preview view and set it as the content of our 
        // Activity 
        mRenderer = new MyRenderer();
        mGLSurfaceView = new GLSurfaceView(this);
        mGLSurfaceView.setRenderer(mRenderer);
        setContentView(mGLSurfaceView);
    } 
 
    @Override 
    protected void onResume() { 
        // Ideally a game should implement onResume() and onPause() 
        // to take appropriate action when the activity looses focus 
        super.onResume(); 
        mRenderer.start();
        mGLSurfaceView.onResume();
    } 
 
    @Override 
7
CodeRank
This code example shows how to use the following methods:setEGLConfigChooser, setEGLContextClientVersion, setPreserveEGLContextOnPause, setRenderer
     * 
     * @param usePhysics    true to enable physics simulation 
     */ 
    protected void createEngine(boolean usePhysics) {
        // create and initialize the GLSurfaceView 
        GLSurfaceView glView = new GLSurfaceView(this);
        createEngine(glView, usePhysics);
 
        // set the GL view as Activity's only content 
        setContentView(glView);
    } 
 
    /** 
     * Call this method from your Activity's onCreate() method and pass the GLSurfaceView from your 
     * layout. 
     * 
     * @param glView        GLSurfaceView to use for graphics output 
     * @param usePhysics    true to enable physics simulation 
     */ 
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)

6
CodeRank

Related Android GLSurfaceView Questions & Answers:

See Code Examples for Android GLSurfaceView Methods: