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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glViewport() . 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: MyGLRenderer.java    From TikTok with Apache License 2.0 6 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) { // Prevent A Divide By Zero By
        height = 1; // Making Height Equal One
    }
    this.width = width;
    this.height = height;
    gl.glViewport(0, 0, width, height); // Reset The
    // Current
    // Viewport
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,
            100.0f);

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity();
}
 
Example 2
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 3
Source File: FftVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawFFT(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n,
        float yrange, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, 0, width, height);

    // X: [0:1], Y: [0:yrange]
    gl.glOrthof(0.0f, 1.0f, 0.0f, yrange, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 4
Source File: TouchSurfaceView.java    From retrobreaker with MIT License 6 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
	mScreenWidth = width;
	mScreenHeight = height;
	
	float ratio = (float) width / height;
	State.setScreenMeasures((2.0f * Config.SCREEN_RATIO) - Config.WALL, 2.0f - Config.WALL);

	// Define a fixed game screen ratio independently of the screen resolution
	if(ratio >= Config.SCREEN_RATIO) {
		int newWidth = Math.round(height * Config.SCREEN_RATIO);
		gl.glViewport((width - newWidth)/2, 0, newWidth, height);
	} else {
		int newHeight = Math.round(width/Config.SCREEN_RATIO);
		gl.glViewport(0, (height - newHeight)/2, width, newHeight);
	}
	gl.glMatrixMode(GL10.GL_PROJECTION);
	gl.glLoadIdentity();
	gl.glOrthof(-Config.SCREEN_RATIO, Config.SCREEN_RATIO, -1.0f, 1.0f, -1.0f, 1.0f);

	Matrix.orthoM(mUnprojectProjMatrix, 0, -Config.SCREEN_RATIO, Config.SCREEN_RATIO, -1.0f, 1.0f, -1.0f, 1.0f);
	Matrix.setIdentityM(mUnprojectViewMatrix, 0);
}
 
Example 5
Source File: HQFftVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawFFT(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n,
        int vposition, float yrange, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, (height / 2) * (1 - vposition), width, (height / 2));

    // X: [0:1], Y: [0:1]
    gl.glOrthof(0.0f, 1.0f, 0.0f, yrange, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 6
Source File: WaveformVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawWaveForm(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n, float ymin, float ymax, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, 0, width, height);

    // X: [0:1], Y: [ymin:ymax]
    gl.glOrthof(0.0f, 1.0f, ymin, ymax, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 7
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 8
Source File: VideoViewH264m3u8.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int w, int h) {
    try {
        VideoViewH264m3u8.this.mSurfaceHeight = h;
        VideoViewH264m3u8.this.mSurfaceWidth = w;
        LogTag.i("MyRenderer:onSurfaceChanged(), w=" + w + ", h=" + h + ", lastW=" + this.lastW + ", lastH=" + this.lastH);
        if (VideoViewH264m3u8.this.mMediaPlayer != null && VideoViewH264m3u8.this.mCurrentState >= 2) {
            if (this.lastW != w || this.lastH != h) {
                gl.glViewport(0, 0, w, h);
                VideoViewH264m3u8.this.mMediaPlayer.native_gl_resize(w, h);
                this.lastW = w;
                this.lastH = h;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 9
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 10
Source File: GLDrawerES1.java    From Building-Android-UIs-with-Custom-Views with MIT License 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if (height == 0) height = 1;
    float aspect = (float) width / height;

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(-10.f, 10.f, 10.f / aspect, -10.f / aspect, 0.1f, 100.f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

}
 
Example 11
Source File: LaserScanRenderer.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when the surface changed size.
 *
 * @param gl The GL interface.
 * @param width The width of the view
 * @param height The height of the view
 */
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    this.width = width;
    this.height = height;

    xStart = 0.0f;
    yStart = 0.0f;
    offX = 0.0f;
    offY = 0.0f;

    gl.glViewport(0, 0, width, height);
}
 
Example 12
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 13
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 14
Source File: CubeRenderer.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 15
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawOnscreen(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, 3, 7);

    gl.glClearColor(0,0,1,0);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTargetTexture);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

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

    gl.glActiveTexture(GL10.GL_TEXTURE0);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    gl.glRotatef(angle, 0, 0, 1.0f);

    mTriangle.draw(gl);

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

    gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 16
Source File: TriangleRenderer.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 17
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 18
Source File: FlipRenderer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
  gl.glViewport(0, 0, width, height);

  gl.glMatrixMode(GL_PROJECTION);
  gl.glLoadIdentity();

  float fovy = 20f;
  float eyeZ = height / 2f / (float) Math.tan(TextureUtils.d2r(fovy / 2));

  GLU.gluPerspective(gl, fovy, (float) width / (float) height, 0.5f,
                     eyeZ + height / 2); //set zFar be larger than eyeZ to fix issue #5

  gl.glMatrixMode(GL_MODELVIEW);
  gl.glLoadIdentity();

  GLU.gluLookAt(gl,
                width / 2f, height / 2f, eyeZ,
                width / 2f, height / 2f, 0.0f,
                0.0f, 1.0f, 0.0f
  );

  gl.glEnable(GL_LIGHTING);
  gl.glEnable(GL_LIGHT0);

  float lightAmbient[] = new float[]{3.5f, 3.5f, 3.5f, 1f};
  gl.glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient, 0);

  light0Position = new float[]{0, 0, eyeZ, 0f};
  gl.glLightfv(GL_LIGHT0, GL_POSITION, light0Position, 0);

  if (AphidLog.ENABLE_DEBUG) {
    AphidLog.d("onSurfaceChanged: %d, %d", width, height);
  }
}
 
Example 19
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
    checkGLError(gl);
    mSurfaceWidth = width;
    mSurfaceHeight = height;
    gl.glViewport(0, 0, width, height);
}
 
Example 20
Source File: VideoGLSurfaceView.java    From Socket.io-FLSocketIM-Android with MIT License 4 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

    //当surface的尺寸发生改变时,该方法被调用,。往往在这里设置ViewPort。或者Camara等。
    gl.glViewport(0, 0, width, height);
}