Example usage for android.opengl GLES20 glViewport

List of usage examples for android.opengl GLES20 glViewport

Introduction

In this page you can find the example usage for android.opengl GLES20 glViewport.

Prototype

public static native void glViewport(int x, int y, int width, int height);

Source Link

Usage

From source file:helloopengles.example.com.MyGLRenderer.java

@Override
public void onSurfaceChanged(GL10 unused, int width, int height) {
    // Adjust the viewport based on geometry changes,
    // such as screen rotation
    GLES20.glViewport(0, 0, width, height);

}

From source file:com.google.fpl.liquidfunpaint.renderer.ParticleRenderer.java

private void drawParticleSystemToScreen(DrawableParticleSystem dps) {
    dps.onDrawFrame();//www  . j  a va  2  s .c  o  m

    // Draw the particles
    drawParticles(dps);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glViewport(0, 0, PhysicsLoop.getInstance().sScreenWidth, PhysicsLoop.getInstance().sScreenHeight);

    // Copy the water particles to screen
    mWaterScreenRenderer.draw(mTransformFromTexture);

    // Copy the other particles to screen
    mScreenRenderer.draw(mTransformFromTexture);
}

From source file:com.google.fpl.liquidfunpaint.ParticleRenderer.java

/**
 * This should only execute on the GLSurfaceView thread.
 *///from  w  w  w.java 2 s. c o  m
public void draw() {
    // Per frame resets of buffers
    mParticlePositionBuffer.rewind();
    mParticleColorBuffer.rewind();
    mParticleWeightBuffer.rewind();
    mParticleRenderList.clear();

    ParticleSystem ps = Renderer.getInstance().acquireParticleSystem();
    try {
        int worldParticleCount = ps.getParticleCount();
        // grab the most current particle buffers
        ps.copyPositionBuffer(0, worldParticleCount, mParticlePositionBuffer);
        ps.copyColorBuffer(0, worldParticleCount, mParticleColorBuffer);
        ps.copyWeightBuffer(0, worldParticleCount, mParticleWeightBuffer);

        GLES20.glClearColor(0, 0, 0, 0);

        // Draw the particles
        drawParticles();

        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
        GLES20.glViewport(0, 0, Renderer.getInstance().sScreenWidth, Renderer.getInstance().sScreenHeight);

        // Draw the paper texture.
        TextureRenderer.getInstance().drawTexture(mPaperTexture, Renderer.MAT4X4_IDENTITY, -1, -1, 1, 1);

        // Copy the water particles to screen
        mWaterScreenRenderer.draw(mTransformFromTexture);

        // Copy the other particles to screen
        mScreenRenderer.draw(mTransformFromTexture);
    } finally {
        Renderer.getInstance().releaseParticleSystem();
    }
}

From source file:com.google.fpl.liquidfunpaint.renderer.PhysicsLoop.java

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    sScreenWidth = width;//from   w  w w .  j a v a2 s. c o  m
    sScreenHeight = height;

    GLES20.glViewport(0, 0, width, height);

    mWorldLock.lock();

    try {
        mWorldLock.setWorldDimensions(width, height);

        mParticleRenderer.onSurfaceChanged(gl, width, height);
        mSolidWorld.onSurfaceChanged(gl, width, height);

        if (DEBUG_DRAW) {
            mDebugRenderer.onSurfaceChanged(gl, width, height);
        }
    } finally {
        mWorldLock.unlock();
    }
}

From source file:com.wlanjie.streaming.camera.CameraView.java

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    mSurfaceWidth = width;/*  ww  w  . jav  a  2  s .  com*/
    mSurfaceHeight = height;
    mFrameBuffer = ByteBuffer.allocate(width * height * 4);
    mCallbacks.onPreview(width, height);

    mEglCore.onInputSizeChanged(width, height);
    GLES20.glViewport(0, 0, width, height);
    mEglCore.onDisplaySizeChange(width, height);

    float outputAspectRatio = width > height ? (float) width / height : (float) height / width;
    float aspectRatio = outputAspectRatio / outputAspectRatio;
    if (width > height) {
        Matrix.orthoM(mProjectionMatrix, 0, -1.0f, 1.0f, -aspectRatio, aspectRatio, -1.0f, 1.0f);
    } else {
        Matrix.orthoM(mProjectionMatrix, 0, -aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
    }
}

From source file:com.watabou.noosa.Game.java

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

    //GLog.i("viewport: %d %d",width, height );

    Game.width(width);// w w  w.j a v  a2  s.  c  o m
    Game.height(height);
}