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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glClearColor() . 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: TouchRotateActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * 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);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
             GL10.GL_FASTEST);


     gl.glClearColor(1,1,1,1);
     gl.glEnable(GL10.GL_CULL_FACE);
     gl.glShadeModel(GL10.GL_SMOOTH);
     gl.glEnable(GL10.GL_DEPTH_TEST);
}
 
Example 2
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
	gl.glClearColor(0.0f,0.5f,0.5f,1.0f);
    gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL11.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -7.0f);

    gl.glRotatef(mAngle, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(mAngle, 1.0f, 0.0f, 0.0f);

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

    mCube.draw(gl);

    mTransY += .075f;
    mAngle+=.4;
}
 
Example 3
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 4
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 5
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) 
{

    gl.glDisable(GL11.GL_DITHER);

    gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,
             GL11.GL_FASTEST);

    if (mTranslucentBackground) 
    {
         gl.glClearColor(1,0,0,0);
    } 
    else 
    {
         gl.glClearColor(1,1,1,1);
    }
    
    gl.glEnable(GL11.GL_CULL_FACE);
    gl.glShadeModel(GL11.GL_SMOOTH);
    gl.glEnable(GL11.GL_DEPTH_TEST);
}
 
Example 6
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 7
Source File: CubeRenderer.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * 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);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
     gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
             GL10.GL_FASTEST);

     if (mTranslucentBackground) {
         gl.glClearColor(0,0,0,0);
     } else {
         gl.glClearColor(1,1,1,1);
     }
     gl.glEnable(GL10.GL_CULL_FACE);
     gl.glShadeModel(GL10.GL_SMOOTH);
     gl.glEnable(GL10.GL_DEPTH_TEST);
}
 
Example 8
Source File: LaserScanRenderer.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when the surface is created or recreated.
 *
 * @param gl the GL interface.
 * @param config the EGLConfig of the created surface. Can be used
 */
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glDisable(GL10.GL_DITHER);
}
 
Example 9
Source File: KubeRenderer.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
     if (mCallback != null) {
         mCallback.animate();
     }

    /*
     * 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(). However we must make sure to set the scissor
     * correctly first. The scissor is always specified in window
     * coordinates:
     */

    gl.glClearColor(0.5f,0.5f,0.5f,1);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

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

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0, 0, -3.0f);
    gl.glScalef(0.5f, 0.5f, 0.5f);
    gl.glRotatef(mAngle,        0, 1, 0);
    gl.glRotatef(mAngle*0.25f,  1, 0, 0);

    gl.glColor4f(0.7f, 0.7f, 0.7f, 1.0f);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);

    mWorld.draw(gl);
}
 
Example 10
Source File: CubeRenderer.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // dither is enabled by default, we don't need it
    gl.glDisable(GL10.GL_DITHER);
    // clear screen in black
    gl.glClearColor(0, 0, 0, 1);
}
 
Example 11
Source File: MyGLRenderer.java    From TikTok with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl,
                             javax.microedition.khronos.egl.EGLConfig arg1) {
    glBitmap.loadGLTexture(gl, this.context);

    gl.glEnable(GL10.GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
    gl.glShadeModel(GL10.GL_SMOOTH); // Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
    gl.glClearDepthf(1.0f); // Depth Buffer Setup
    gl.glEnable(GL10.GL_DEPTH_TEST); // Enables Depth Testing
    gl.glDepthFunc(GL10.GL_LEQUAL); // The Type Of Depth Testing To Do

    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
 
Example 12
Source File: OpenGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	// Set the background color to black ( rgba ).
	gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);  // OpenGL docs.
	// Enable Smooth Shading, default not really needed.
	gl.glShadeModel(GL10.GL_SMOOTH);// OpenGL docs.
	// Depth buffer setup.
	gl.glClearDepthf(1.0f);// OpenGL docs.
	// Enables depth testing.
	gl.glEnable(GL10.GL_DEPTH_TEST);// OpenGL docs.
	// The type of depth testing to do.
	gl.glDepthFunc(GL10.GL_LEQUAL);// OpenGL docs.
	// Really nice perspective calculations.
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, // OpenGL docs.
                         GL10.GL_NICEST);
}
 
Example 13
Source File: AndroidOpenGL.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);

    // configure projection to screen
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
    float aspect = (float) width / height;
    GLU.gluPerspective(gl, 45.0f, aspect, 1.0f, 30.0f);
}
 
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 onSurfaceCreated(GL10 gl, EGLConfig config) {//15
	gl.glDisable(GL10.GL_DITHER); //16
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, //17
			GL10.GL_FASTEST);
	if (mTranslucentBackground) {//18
		gl.glClearColor(0,0,0,0);
	} else {
		gl.glClearColor(1,1,1,1);
	}
	gl.glEnable(GL10.GL_CULL_FACE); //19
	gl.glShadeModel(GL10.GL_SMOOTH); //20
	gl.glEnable(GL10.GL_DEPTH_TEST); //21
}
 
Example 16
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // dither is enabled by default, we don't need it
    gl.glDisable(GL10.GL_DITHER);
    // clear screen in white
    gl.glClearColor(1,1,1,1);
}
 
Example 17
Source File: MatrixPaletteRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * 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);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
            GL10.GL_FASTEST);

    gl.glClearColor(.5f, .5f, .5f, 1);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_CLAMP_TO_EDGE);

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

    InputStream is = mContext.getResources()
            .openRawResource(R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();

    mGrid = generateWeightedGrid(gl);
}
 
Example 18
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 19
Source File: InvertedColorsVideoRenderer.java    From opentok-android-sdk-samples with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    gl.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    mFrameLock.lock();
    if (mCurrentFrame != null && !mVideoDisabled) {
        GLES20.glUseProgram(mProgram);

        if (mTextureWidth != mCurrentFrame.getWidth()
                || mTextureHeight != mCurrentFrame.getHeight()) {
            setupTextures(mCurrentFrame);
        }
        updateTextures(mCurrentFrame);

        Matrix.setIdentityM(mScaleMatrix, 0);
        float scaleX = 1.0f, scaleY = 1.0f;
        float ratio = (float) mCurrentFrame.getWidth()
                / mCurrentFrame.getHeight();
        float vratio = (float) mViewportWidth / mViewportHeight;

        if (mVideoFitEnabled) {
            if (ratio > vratio) {
                scaleY = vratio / ratio;
            } else {
                scaleX = ratio / vratio;
            }
        } else {
            if (ratio < vratio) {
                scaleY = vratio / ratio;
            } else {
                scaleX = ratio / vratio;
            }
        }

       Matrix.scaleM(mScaleMatrix, 0,
                scaleX * (mCurrentFrame.isMirroredX() ? -1.0f : 1.0f),
                scaleY, 1);

        if (metadataListener != null) {
            metadataListener.onMetadataReady(mCurrentFrame.getMetadata());
        }

        int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram,
                "uMVPMatrix");
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false,
                mScaleMatrix, 0);

        GLES20.glDrawElements(GLES20.GL_TRIANGLES, mVertexIndex.length,
                GLES20.GL_UNSIGNED_SHORT, mDrawListBuffer);
    } else {
        //black frame when video is disabled
        gl.glClearColor(0, 0, 0, 1);
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }
    mFrameLock.unlock();
}
 
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();
}