Java Code Examples for javax.microedition.khronos.opengles.GL10#glFrustumf()

The following examples show how to use javax.microedition.khronos.opengles.GL10#glFrustumf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubeRenderer.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);

    /*
     * Set our projection matrix. This doesn't have to be done
     * each time we draw, but usually a new projection needs to be set
     * when the viewport is resized.
     */

    float ratio = (float)width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12);

    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);
    gl.glActiveTexture(GL10.GL_TEXTURE0);
}
 
Example 2
Source File: SpriteTextRenderer.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int w, int h) {
    mWidth = w;
    mHeight = h;
    gl.glViewport(0, 0, w, h);
    mProjector.setCurrentView(0, 0, w, h);

    /*
    * Set our projection matrix. This doesn't have to be done
    * each time we draw, but usually a new projection needs to
    * be set when the viewport is resized.
    */

    float ratio = (float) w / h;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
    mProjector.getCurrentProjection(gl);
}
 
Example 3
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) 
{
    gl.glViewport(0, 0, width, height);

    float aspectRatio;
    float zNear =.1f;
    float zFar =1000;
    float fieldOfView = 30.0f/57.3f;                                                                       
    float size;
    	
    gl.glEnable(GL10.GL_NORMALIZE);
    	
    aspectRatio=(float)width/(float)height;                       
	    	
    gl.glMatrixMode(GL10.GL_PROJECTION);                                  
    	
    size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));   

    gl.glFrustumf(-size, size, -size /aspectRatio,                    
                           size /aspectRatio, zNear, zFar);
    	
    gl.glMatrixMode(GL10.GL_MODELVIEW);                              
}
 
Example 4
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) 
{
    gl.glViewport(0, 0, width, height);

    float aspectRatio;
    float zNear =.1f;
    float zFar =1000;
    float fieldOfView = 30.0f/57.3f;                                                                       
    float size;
    	
    gl.glEnable(GL10.GL_NORMALIZE);
    	
    aspectRatio=(float)width/(float)height;                       
	    	
    gl.glMatrixMode(GL10.GL_PROJECTION);                                  
    	
    size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));   

    gl.glFrustumf(-size, size, -size /aspectRatio,                    
                           size /aspectRatio, zNear, zFar);
    	
    gl.glMatrixMode(GL10.GL_MODELVIEW);                              
}
 
Example 5
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {//11
	gl.glViewport(0, 0, width, height); //12
	float ratio = (float) width / height;
	gl.glMatrixMode(GL10.GL_PROJECTION); //13
	gl.glLoadIdentity();
	gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); //14
}
 
Example 6
Source File: CubeMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
    checkGLError(gl);
    gl.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
    checkGLError(gl);
}
 
Example 7
Source File: MatrixPaletteRenderer.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int w, int h) {
    gl.glViewport(0, 0, w, h);

    /*
    * Set our projection matrix. This doesn't have to be done
    * each time we draw, but usually a new projection needs to
    * be set when the viewport is resized.
    */

    float ratio = (float) w / h;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);
}
 
Example 8
Source File: TouchRotateActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);

     /*
      * Set our projection matrix. This doesn't have to be done
      * each time we draw, but usually a new projection needs to
      * be set when the viewport is resized.
      */

     float ratio = (float) width / height;
     gl.glMatrixMode(GL10.GL_PROJECTION);
     gl.glLoadIdentity();
     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}
 
Example 9
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawOffscreenImage(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glEnable(GL10.GL_DEPTH_TEST);

    gl.glClearColor(0,0.5f,1,0);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0, 0, -3.0f);
    gl.glRotatef(mAngle,        0, 1, 0);
    gl.glRotatef(mAngle*0.25f,  1, 0, 0);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

    mCube.draw(gl);

    gl.glRotatef(mAngle*2.0f, 0, 1, 1);
    gl.glTranslatef(0.5f, 0.5f, 0.5f);

    mCube.draw(gl);

    mAngle += 1.2f;

    // Restore default state so the other renderer is not affected.

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
 
Example 10
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
    // set view-port
    gl.glViewport(0, 0, width, height);
    // set projection matrix
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}
 
Example 11
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int w, int h) {
	gl.glViewport(0, 0, w, h);
	float ratio = (float) w / h;
	gl.glMatrixMode(GL10.GL_PROJECTION);
	gl.glLoadIdentity();
	gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);
}
 
Example 12
Source File: Graph3DRenderer.java    From ncalc with GNU General Public License v3.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}
 
Example 13
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);

     /*
      * Set our projection matrix. This doesn't have to be done
      * each time we draw, but usually a new projection needs to
      * be set when the viewport is resized.
      */
     
 	float aspectRatio;
	float zNear =.1f;
	float zFar =1000f;
	float fieldOfView = 30.0f/57.3f;
	float	size;
	
	gl.glEnable(GL10.GL_NORMALIZE);
	
	aspectRatio=(float)width/(float)height;				//h/w clamps the fov to the height, flipping it would make it relative to the width
	
	//Set the OpenGL projection matrix
	
	gl.glMatrixMode(GL10.GL_PROJECTION);
	
	size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));
	gl.glFrustumf(-size, size, -size/aspectRatio, size /aspectRatio, zNear, zFar);
	
	//Make the OpenGL modelview matrix the default
	
	gl.glMatrixMode(GL10.GL_MODELVIEW);
}
 
Example 14
Source File: VortexRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // preparation
    Log.i(LOG_TAG, "onSurfaceCreated()");
    gl.glMatrixMode(GL10.GL_PROJECTION);
    float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2); 
    float ratio = _width / _height;
    // perspective:
    gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
    // orthographic:
    //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
    gl.glViewport(0, 0, (int) _width, (int) _height);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    
// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(0f, 0f, 0f, 1.0f);

// enable the differentiation of which side may be visible 
gl.glEnable(GL10.GL_CULL_FACE);
// which is the front? the one which is drawn counter clockwise
gl.glFrontFace(GL10.GL_CCW);
// which one should NOT be drawn
gl.glCullFace(GL10.GL_BACK);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

initTriangle();
}
 
Example 15
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {//11
	gl.glViewport(0, 0, width, height); //12
	float ratio = (float) width / height;
	gl.glMatrixMode(GL10.GL_PROJECTION); //13
	gl.glLoadIdentity();
	gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); //14
}
 
Example 16
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);

     /*
      * Set our projection matrix. This doesn't have to be done
      * each time we draw, but usually a new projection needs to
      * be set when the viewport is resized.
      */
     
 	float aspectRatio;
	float zNear =.1f;
	float zFar =1000f;
	float fieldOfView = 30.0f/57.3f;
	float	size;
	
	gl.glEnable(GL10.GL_NORMALIZE);
	
	aspectRatio=(float)width/(float)height;				//h/w clamps the fov to the height, flipping it would make it relative to the width
	
	//Set the OpenGL projection matrix
	
	gl.glMatrixMode(GL10.GL_PROJECTION);
	
	size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));
	gl.glFrustumf(-size, size, -size/aspectRatio, size /aspectRatio, zNear, zFar);
	
	//Make the OpenGL modelview matrix the default
	
	gl.glMatrixMode(GL10.GL_MODELVIEW);
}
 
Example 17
Source File: VortexRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // preparation
    Log.i(LOG_TAG, "onSurfaceCreated()");
    gl.glMatrixMode(GL10.GL_PROJECTION);
    float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2); 
    float ratio = _width / _height;
    // perspective:
    gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
    // orthographic:
    //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
    gl.glViewport(0, 0, (int) _width, (int) _height);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    
// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(0f, 0f, 0f, 1.0f);

// enable the differentiation of which side may be visible 
gl.glEnable(GL10.GL_CULL_FACE);
// which is the front? the one which is drawn counter clockwise
gl.glFrontFace(GL10.GL_CCW);
// which one should NOT be drawn
gl.glCullFace(GL10.GL_BACK);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

initTriangle();
}
 
Example 18
Source File: CubeRenderer.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * Update view-port with the new surface
 * 
 * @param gl the surface
 * @param width new width
 * @param height new height
 */
public void onSurfaceChanged(GL10 gl, int width, int height) {
    // set view-port
    gl.glViewport(0, 0, width, height);
    // set projection matrix
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}
 
Example 19
Source File: GLUES.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
public static void gluPerspective(GL10 gl, float fovy, float aspect, float zNear, float zFar) {
    float halfHeight = zNear * (float) Math.tan(fovy * 0.5f * PI_OVER_180);
    float halfWidth = halfHeight * aspect;
    gl.glFrustumf(-halfWidth, halfWidth, -halfHeight, halfHeight, zNear, zFar);
}
 
Example 20
Source File: GLUES.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
public static void gluPerspective(GL10 gl, float fovy, float aspect, float zNear, float zFar)
{	
	float halfHeight = zNear * (float)Math.tan(fovy * 0.5f * PI_OVER_180);
	float halfWidth = halfHeight * aspect;
    gl.glFrustumf(-halfWidth, halfWidth, -halfHeight, halfHeight, zNear, zFar);
}