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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glClear() . 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: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    checkGLError(gl);
    if (mContextSupportsFrameBufferObject) {
        GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
        if (DEBUG_RENDER_OFFSCREEN_ONSCREEN) {
            drawOffscreenImage(gl, mSurfaceWidth, mSurfaceHeight);
        } else {
            gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, mFramebuffer);
            drawOffscreenImage(gl, mFramebufferWidth, mFramebufferHeight);
            gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
            drawOnscreen(gl, mSurfaceWidth, mSurfaceHeight);
        }
    } else {
        // Current context doesn't support frame buffer objects.
        // Indicate this by drawing a red background.
        gl.glClearColor(1,0,0,0);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    }
}
 
Example 2
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadIdentity();
	
     gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -4.0f);
	
     gl.glRotatef(mAngle, 1, 0, 0);
     gl.glRotatef(mAngle, 0, 1, 0);
		
     mPlanet.draw(gl);
	     
     mTransY+=.075f; 
     mAngle+=.4;
}
 
Example 3
Source File: FlipRenderer.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
  if (cards.isVisible() && cards.isFirstDrawFinished())
    gl.glClearColor(1f, 1f, 1f, 1f);
  else
    gl.glClearColor(0f, 0f, 0f, 0f);
  gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  synchronized (postDestroyTextures) {
    for (Texture texture : postDestroyTextures) {
      texture.destroy(gl);
    }
    postDestroyTextures.clear();
  }

  cards.draw(this, gl);
}
 
Example 4
Source File: BaseAudioVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl, int width, int height) {
    CapturedDataHolder capData = null;

    capData = mDoubleBufferingManager.getAndSwapBuffer();

    if (capData != null && capData.valid()) {
        // clear background
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        onRenderAudioData(gl, width, height, mRendererWorkObj, capData);
    }
}
 
Example 5
Source File: OpenGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
	// Clears the screen and depth buffer.
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | // OpenGL docs.
                          GL10.GL_DEPTH_BUFFER_BIT);
	// Replace the current matrix with the identity matrix
	gl.glLoadIdentity(); // OpenGL docs

	// Translates 4 units into the screen.
	gl.glTranslatef(0, 0, -4); // OpenGL docs

	// Draw our square.
	square.draw(gl); // ( NEW )
	

}
 
Example 6
Source File: AndroidOpenGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
   
    if (!fAnimPaused) {
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | 
            GL10.GL_DEPTH_BUFFER_BIT);
        gl.glRotatef(1f, 0, 0, 1f);

        if (mTriangle != null) {
            mTriangle.drawColorful(gl);
        }
    }
}
 
Example 7
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {//4
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);//5
	gl.glMatrixMode(GL10.GL_MODELVIEW); //6
	gl.glLoadIdentity(); //7
	gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -3.0f); //8
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //9
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	mSquare.draw(gl); //10
	mTransY += .075f;
}
 
Example 8
Source File: AndroidOpenGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
   
    if (!fAnimPaused) {
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | 
            GL10.GL_DEPTH_BUFFER_BIT);
        gl.glRotatef(1f, 0, 0, 1f);

        if (mTriangle != null) {
            mTriangle.drawColorful(gl);
        }
    }
}
 
Example 9
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
	gl.glDisable(GL10.GL_DITHER);
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	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);
	draw(gl);
}
 
Example 10
Source File: BaseAudioVisualizerSurfaceView.java    From android-openslmediaplayer 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);

    // clear background
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    mWidth = width;
    mHeight = height;
}
 
Example 11
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 12
Source File: PLBlankPanorama.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    gl.glClearColor(mColor.red, mColor.green, mColor.blue, 1.0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
 
Example 13
Source File: PageRenderer.java    From PlayLikeCurl with MIT License 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {

		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);	
		gl.glLoadIdentity();

		gl.glPushMatrix();
		gl.glTranslatef(0.0f, 0.0f, -2.0f);
		gl.glTranslatef(-0.5f, -0.5f, 0.0f);

		leftPage.draw(gl,context);
		gl.glPopMatrix();

		gl.glPushMatrix();
		gl.glTranslatef(0.0f, 0.0f, -2.0f);
		gl.glTranslatef(-0.5f, -0.5f, 0.0f);

		frontPage.draw(gl, context);
		gl.glPopMatrix();

		gl.glPushMatrix();
		gl.glTranslatef(0.0f, 0.0f, -2.0f);
		gl.glTranslatef(-0.5f, -0.5f, 0.0f);
		rightPage.draw(gl,context);

		gl.glPopMatrix();

	}
 
Example 14
Source File: PLBlankPanorama.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**render methods*/

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer)
{
	gl.glClearColor(mColor.red, mColor.green, mColor.blue, 1.0f);
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
 
Example 15
Source File: GLFieldView.java    From homescreenarcade with GNU General Public License v3.0 5 votes vote down vote up
void endGLElements(GL10 gl) {
    vertexListManager.end();

    gl.glEnable(GL10.GL_DITHER);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    gl.glLineWidth(2);

    vertexListManager.render(gl);
}
 
Example 16
Source File: VideoGLSurfaceView.java    From Socket.io-FLSocketIM-Android with MIT License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {

    //每帧都需要调用该方法进行绘制。绘制时通常先调用glClear来清空framebuffer。
    //然后调用OpenGL ES其他接口进行绘制
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
 
Example 17
Source File: BobRenderer.java    From BobEngine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Execute a frame. <br />
 * <br />
 * This method will update game logic and update the graphics.
 */
@Override
public void onDrawFrame(GL10 gl) {
	Room current = myOwner.getCurrentRoom();       // Current room
	long now = SystemClock.uptimeMillis();         // Current time
	long timeElapsed = (long) OPTIMAL_TIME;        // Amount of time the frame took

	gl.glClear(GL10.GL_COLOR_BUFFER_BIT);                              // Get rid of the previous frame
	gl.glClearColor(red, green, blue, alpha);                          // BG color

	myOwner.getGraphicsHelper().handleGraphics((GL11) gl);

	if (current != null) {
		current.update(1/*averageDelta / OPTIMAL_TIME*/);   // Update game logic
		current.draw(gl);                              // Draw graphics
	}

	if (lastTime > 0) {
		timeElapsed = now - lastTime;                  // The amount of time the last frame took
	}

	if (frames < OPTIMAL_FPS) {
		frames++;
		averageDelta = (timeElapsed + averageDelta * (frames - 1)) / frames;     // Update the average amount of time a frame takes
	} else {
		averageDelta = (timeElapsed + averageDelta * (OPTIMAL_FPS - 1)) / OPTIMAL_FPS;           // Update the average amount of time a frame takes
	}

	lastTime = now;

	if (outputFPS && frames % 60 == 0) {
		double fps = (double) 1000 / (double) averageDelta;

		if (1000.0 / timeElapsed < low || low == -1) {
			low = 1000.0 / timeElapsed;
		}

		if (1000.0 / timeElapsed > high || high == -1) {
			high = 1000.0 / timeElapsed;
		}

		if (1000.0 / timeElapsed < FRAME_DROP_THRES) {
			Log.d("fps", "FRAME DROPPED. FPS: " + (1000.0 / timeElapsed));
		}

		if (SystemClock.uptimeMillis() % 100 <= 10) {
			Log.d("fps", "FPS: " + fps + "    LOW: " + low + "    HIGH: " + high); // Show FPS in logcat
		}
	}

}
 
Example 18
Source File: CubeMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    checkGLError(gl);
    if (mContextSupportsCubeMap) {
        gl.glClearColor(0,0,1,0);
    } else {
        // Current context doesn't support cube maps.
        // Indicate this by drawing a red background.
        gl.glClearColor(1,0,0,0);
    }
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    gl.glRotatef(mAngle,        0, 1, 0);
    gl.glRotatef(mAngle*0.25f,  1, 0, 0);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    checkGLError(gl);

    if (mContextSupportsCubeMap) {
        gl.glActiveTexture(GL10.GL_TEXTURE0);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP);
        checkGLError(gl);
        gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, mCubeMapTextureID);
        checkGLError(gl);
        GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
        gl11ep.glTexGeni(GL11ExtensionPack.GL_TEXTURE_GEN_STR,
                GL11ExtensionPack.GL_TEXTURE_GEN_MODE,
                GL11ExtensionPack.GL_REFLECTION_MAP);
        checkGLError(gl);
        gl.glEnable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
        checkGLError(gl);
        gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL);
    }

    checkGLError(gl);
    mGrid.draw(gl);

    if (mContextSupportsCubeMap) {
        gl.glDisable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
    }
    checkGLError(gl);

    mAngle += 1.2f;
}
 
Example 19
Source File: TriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    /*
     * 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.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_MODULATE);

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    /*
     * Now we're ready to draw some 3D objects
     */

    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);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_REPEAT);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_REPEAT);

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

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

    mTriangle.draw(gl);
}
 
Example 20
Source File: GLRender.java    From LiveBlurListView with Apache License 2.0 4 votes vote down vote up
private void process(Bitmap bitmap, boolean fast) {
	final GL10 gl = mGL;
	
	gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glClearDepthf(1.0f);
	gl.glDepthFunc(GL10.GL_LEQUAL);
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
	gl.glEnable(GL10.GL_TEXTURE_2D);
	gl.glEnable(GL10.GL_LEQUAL);
	
	float[] color = new float[16];
	FloatBuffer colorBuffer;
	float[] texVertex = new float[12];
	FloatBuffer vertexBuffer;
	
	ByteBuffer texByteBuffer = ByteBuffer.allocateDirect(texVertex.length * 4);
	texByteBuffer.order(ByteOrder.nativeOrder());
	vertexBuffer = texByteBuffer.asFloatBuffer();
	vertexBuffer.put(texVertex);
	vertexBuffer.position(0);
	
	ByteBuffer colorByteBuffer = ByteBuffer.allocateDirect(color.length * 4);
	colorByteBuffer.order(ByteOrder.nativeOrder());
	colorBuffer = colorByteBuffer.asFloatBuffer();
	colorBuffer.put(color);
	colorBuffer.position(0);
	
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	gl.glPushMatrix();
	gl.glTranslatef(0.0f, 0.0f, 0.0f);
	

	
	colorBuffer.clear();
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	vertexBuffer.clear();
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
	

	
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
	
	gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
	gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
	
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glPopMatrix();
}