List of usage examples for android.opengl GLES20 glClearColor
public static native void glClearColor(float red, float green, float blue, float alpha);
From source file:helloopengles.example.com.MyGLRenderer.java
@Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { // Set the background frame color GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //mTriangle = new Triangle(); mSquare = new Square(); }
From source file:com.dmitrybrant.android.cardboardmpo.MainActivity.java
@Override public void onSurfaceCreated(EGLConfig config) { Log.i(TAG, "onSurfaceCreated"); GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); rectLeftEye = new TexturedRect(); rectRightEye = new TexturedRect(); checkGLError("Error after creating textures"); }
From source file:com.google.fpl.liquidfunpaint.ParticleRenderer.java
/** * This should only execute on the GLSurfaceView thread. *//*from ww w . j a v a2s . 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 onDrawFrame(GL10 gl) { if (mSimulation) { setChanged();// w ww.jav a 2 s . c o m notifyObservers(); GLES20.glClearColor(1, 1, 1, 1); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // Draw particles showFrameRate(); mWorldLock.lock(); try { drawBackgroundTexture(); mWorldLock.stepWorld(); mParticleRenderer.onDrawFrame(gl); mSolidWorld.onDrawFrame(gl); if (DEBUG_DRAW) { mDebugRenderer.onDrawFrame(gl); } } finally { mWorldLock.unlock(); } } }
From source file:com.wlanjie.streaming.camera.CameraView.java
@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { GLES20.glDisable(GL10.GL_DITHER);//www .j a v a2 s . c om GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); HandlerThread thread = new HandlerThread("glDraw"); thread.start(); mHandler = new Handler(thread.getLooper()) { @Override public void handleMessage(Message msg) { super.handleMessage(msg); IntBuffer buffer = mEglCore.getRgbaBuffer(); mFrameBuffer.asIntBuffer().put(buffer.array()); if (mCallback != null) { mCallback.onPreviewFrame(CameraView.this, mFrameBuffer.array()); } } }; mEglCore = new EglCore(getResources()); mEglCore.init(); mSurfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture) { mGLSurfaceView.requestRender(); } }); }
From source file:com.wlanjie.streaming.camera.CameraView.java
@Override public void onDrawFrame(GL10 gl) { GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); mSurfaceTexture.updateTexImage();//from w w w .j a v a 2s. c om mSurfaceTexture.getTransformMatrix(mSurfaceMatrix); Matrix.multiplyMM(mTransformMatrix, 0, mSurfaceMatrix, 0, mProjectionMatrix, 0); mEglCore.setTextureTransformMatrix(mTransformMatrix); mEglCore.onDrawFrame(mTextureId); mHandler.sendEmptyMessage(0); }
From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java
/** * Creates the buffers we use to store information about the 3D world. * * <p>OpenGL doesn't use Java arrays, but rather needs data in a format it can understand. * Hence we use ByteBuffers.//from ww w . java 2 s.c o m * * @param config The EGL configuration used when creating the surface. */ @Override public void onSurfaceCreated(EGLConfig config) { Log.i(TAG, "onSurfaceCreated"); GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); // Dark background so text shows up well. ByteBuffer bbVertices = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_COORDS.length * 4); bbVertices.order(ByteOrder.nativeOrder()); cubeVertices = bbVertices.asFloatBuffer(); cubeVertices.put(WorldLayoutData.CUBE_COORDS); cubeVertices.position(0); ByteBuffer bbColors = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_COLORS.length * 4); bbColors.order(ByteOrder.nativeOrder()); cubeColors = bbColors.asFloatBuffer(); cubeColors.put(WorldLayoutData.CUBE_COLORS); cubeColors.position(0); ByteBuffer bbFoundColors = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_FOUND_COLORS.length * 4); bbFoundColors.order(ByteOrder.nativeOrder()); cubeFoundColors = bbFoundColors.asFloatBuffer(); cubeFoundColors.put(WorldLayoutData.CUBE_FOUND_COLORS); cubeFoundColors.position(0); ByteBuffer bbNormals = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_NORMALS.length * 4); bbNormals.order(ByteOrder.nativeOrder()); cubeNormals = bbNormals.asFloatBuffer(); cubeNormals.put(WorldLayoutData.CUBE_NORMALS); cubeNormals.position(0); ByteBuffer mcbbVertices = ByteBuffer.allocateDirect(WorldLayoutData.MINI_CUBE_COORDS.length * 4); mcbbVertices.order(ByteOrder.nativeOrder()); miniCubeVertices = mcbbVertices.asFloatBuffer(); miniCubeVertices.put(WorldLayoutData.MINI_CUBE_COORDS); miniCubeVertices.position(0); ByteBuffer mcbbColors = ByteBuffer.allocateDirect(WorldLayoutData.MINI_CUBE_COLORS.length * 4); mcbbColors.order(ByteOrder.nativeOrder()); miniCubeColors = mcbbColors.asFloatBuffer(); miniCubeColors.put(WorldLayoutData.MINI_CUBE_COLORS); miniCubeColors.position(0); ByteBuffer mcbbNormals = ByteBuffer.allocateDirect(WorldLayoutData.CUBE_NORMALS.length * 4); mcbbNormals.order(ByteOrder.nativeOrder()); miniCubeNormals = mcbbNormals.asFloatBuffer(); miniCubeNormals.put(WorldLayoutData.CUBE_NORMALS); miniCubeNormals.position(0); // make a floor ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COORDS.length * 4); bbFloorVertices.order(ByteOrder.nativeOrder()); floorVertices = bbFloorVertices.asFloatBuffer(); floorVertices.put(WorldLayoutData.FLOOR_COORDS); floorVertices.position(0); ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_NORMALS.length * 4); bbFloorNormals.order(ByteOrder.nativeOrder()); floorNormals = bbFloorNormals.asFloatBuffer(); floorNormals.put(WorldLayoutData.FLOOR_NORMALS); floorNormals.position(0); ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COLORS.length * 4); bbFloorColors.order(ByteOrder.nativeOrder()); floorColors = bbFloorColors.asFloatBuffer(); floorColors.put(WorldLayoutData.FLOOR_COLORS); floorColors.position(0); int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, R.raw.light_vertex); int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.grid_fragment); int passthroughShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.passthrough_fragment); cubeProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(cubeProgram, vertexShader); GLES20.glAttachShader(cubeProgram, passthroughShader); GLES20.glLinkProgram(cubeProgram); GLES20.glUseProgram(cubeProgram); checkGLError("Cube program"); cubePositionParam = GLES20.glGetAttribLocation(cubeProgram, "a_Position"); cubeNormalParam = GLES20.glGetAttribLocation(cubeProgram, "a_Normal"); cubeColorParam = GLES20.glGetAttribLocation(cubeProgram, "a_Color"); cubeModelParam = GLES20.glGetUniformLocation(cubeProgram, "u_Model"); cubeModelViewParam = GLES20.glGetUniformLocation(cubeProgram, "u_MVMatrix"); cubeModelViewProjectionParam = GLES20.glGetUniformLocation(cubeProgram, "u_MVP"); cubeLightPosParam = GLES20.glGetUniformLocation(cubeProgram, "u_LightPos"); GLES20.glEnableVertexAttribArray(cubePositionParam); GLES20.glEnableVertexAttribArray(cubeNormalParam); GLES20.glEnableVertexAttribArray(cubeColorParam); checkGLError("Cube program params"); //Minicube miniCubeProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(miniCubeProgram, vertexShader); GLES20.glAttachShader(miniCubeProgram, passthroughShader); GLES20.glLinkProgram(miniCubeProgram); GLES20.glUseProgram(miniCubeProgram); checkGLError("Cube program"); miniCubePositionParam = GLES20.glGetAttribLocation(miniCubeProgram, "a_Position"); miniCubeNormalParam = GLES20.glGetAttribLocation(miniCubeProgram, "a_Normal"); miniCubeColorParam = GLES20.glGetAttribLocation(miniCubeProgram, "a_Color"); miniCubeModelParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_Model"); miniCubeModelViewParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_MVMatrix"); miniCubeModelViewProjectionParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_MVP"); miniCubeLightPosParam = GLES20.glGetUniformLocation(miniCubeProgram, "u_LightPos"); GLES20.glEnableVertexAttribArray(miniCubePositionParam); GLES20.glEnableVertexAttribArray(miniCubeNormalParam); GLES20.glEnableVertexAttribArray(miniCubeColorParam); checkGLError("Cube program params"); floorProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(floorProgram, vertexShader); GLES20.glAttachShader(floorProgram, gridShader); GLES20.glLinkProgram(floorProgram); GLES20.glUseProgram(floorProgram); checkGLError("Floor program"); floorModelParam = GLES20.glGetUniformLocation(floorProgram, "u_Model"); floorModelViewParam = GLES20.glGetUniformLocation(floorProgram, "u_MVMatrix"); floorModelViewProjectionParam = GLES20.glGetUniformLocation(floorProgram, "u_MVP"); floorLightPosParam = GLES20.glGetUniformLocation(floorProgram, "u_LightPos"); floorPositionParam = GLES20.glGetAttribLocation(floorProgram, "a_Position"); floorNormalParam = GLES20.glGetAttribLocation(floorProgram, "a_Normal"); floorColorParam = GLES20.glGetAttribLocation(floorProgram, "a_Color"); GLES20.glEnableVertexAttribArray(floorPositionParam); GLES20.glEnableVertexAttribArray(floorNormalParam); GLES20.glEnableVertexAttribArray(floorColorParam); checkGLError("Floor program params"); Matrix.setIdentityM(modelFloor, 0); Matrix.translateM(modelFloor, 0, 0, -floorDepth, 0); // Floor appears below user. // Avoid any delays during start-up due to decoding of sound files. new Thread(new Runnable() { public void run() { // Start spatial audio playback of SOUND_FILE at the model postion. The returned //soundId handle is stored and allows for repositioning the sound object whenever // the cube position changes. cardboardAudioEngine.preloadSoundFile(SOUND_FILE); soundId = cardboardAudioEngine.createSoundObject(SOUND_FILE); cardboardAudioEngine.setSoundObjectPosition(soundId, modelPosition[0], modelPosition[1], modelPosition[2]); cardboardAudioEngine.playSound(soundId, true /* looped playback */); } }).start(); updateModelPosition(); checkGLError("onSurfaceCreated"); }
From source file:com.kentdisplays.synccardboarddemo.MainActivity.java
/** * Prepares OpenGL ES before we draw a frame. * @param headTransform The head transformation in the new frame. *//*from w w w .j a v a 2 s . c o m*/ @Override public void onNewFrame(HeadTransform headTransform) { GLES20.glUseProgram(mGlProgram); GLES20.glClearColor(0f, 0f, 0f, 1.0f); // Dark background so text shows up well mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP"); mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos"); mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix"); mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model"); mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor"); // Build the camera matrix and apply it to the ModelView. Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); headTransform.getHeadView(mHeadView, 0); checkGLError("onReadyToDraw"); }
From source file:com.kentdisplays.synccardboarddemo.MainActivity.java
/** * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as * a parameter./*from w w w .j a v a 2s . c o m*/ * @param transform The transformations to apply to render this eye. */ @Override public void onDrawEye(EyeTransform transform) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glClearColor(0f, 0f, 0f, 1.00f); // Dark background so text shows up well mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position"); mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal"); mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color"); GLES20.glEnableVertexAttribArray(mPositionParam); GLES20.glEnableVertexAttribArray(mNormalParam); GLES20.glEnableVertexAttribArray(mColorParam); checkGLError("mColorParam"); // Apply the eye transformation to the camera. Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0); // Set the position of the light Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0); GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]); // Draw the pages. for (Page page : mPages) { page.draw(transform.getPerspective(), mView); checkGLError("Drawing page"); } // Set mModelView for the floor, so we draw floor in the correct location Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0); Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0); drawFloor(transform.getPerspective()); }
From source file:com.tumblr.cardboard.Tumblr3DActivity.java
/** * Creates the buffers we use to store information about the 3D world. OpenGL doesn't use Java * arrays, but rather needs data in a format it can understand. Hence we use ByteBuffers. * * @param config The EGL configuration used when creating the surface. *//*from www .jav a2 s.c o m*/ @Override public void onSurfaceCreated(EGLConfig config) { Log.i(TAG, "onSurfaceCreated"); GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); // Dark background so text shows up well ByteBuffer bbVertices = ByteBuffer.allocateDirect(WorldLayoutData.RECT_COORDS.length * 4); bbVertices.order(ByteOrder.nativeOrder()); mRectVertices = bbVertices.asFloatBuffer(); mRectVertices.put(WorldLayoutData.RECT_COORDS); mRectVertices.position(0); ByteBuffer bbColors = ByteBuffer.allocateDirect(WorldLayoutData.RECT_COLORS.length * 4); bbColors.order(ByteOrder.nativeOrder()); mRectColors = bbColors.asFloatBuffer(); mRectColors.put(WorldLayoutData.RECT_COLORS); mRectColors.position(0); ByteBuffer bbFoundColors = ByteBuffer.allocateDirect(WorldLayoutData.RECT_FOUND_COLORS.length * 4); bbFoundColors.order(ByteOrder.nativeOrder()); mRectFoundColors = bbFoundColors.asFloatBuffer(); mRectFoundColors.put(WorldLayoutData.RECT_FOUND_COLORS); mRectFoundColors.position(0); ByteBuffer bbNormals = ByteBuffer.allocateDirect(WorldLayoutData.RECT_NORMALS.length * 4); bbNormals.order(ByteOrder.nativeOrder()); mRectNormals = bbNormals.asFloatBuffer(); mRectNormals.put(WorldLayoutData.RECT_NORMALS); mRectNormals.position(0); ByteBuffer bbTextureCoordinates = ByteBuffer.allocateDirect(WorldLayoutData.RECT_TEX_COORDS.length * 4); bbTextureCoordinates.order(ByteOrder.nativeOrder()); mRectTexCoords = bbTextureCoordinates.asFloatBuffer(); mRectTexCoords.put(WorldLayoutData.RECT_TEX_COORDS); mRectTexCoords.position(0); // make a floor ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COORDS.length * 4); bbFloorVertices.order(ByteOrder.nativeOrder()); mFloorVertices = bbFloorVertices.asFloatBuffer(); mFloorVertices.put(WorldLayoutData.FLOOR_COORDS); mFloorVertices.position(0); ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_NORMALS.length * 4); bbFloorNormals.order(ByteOrder.nativeOrder()); mFloorNormals = bbFloorNormals.asFloatBuffer(); mFloorNormals.put(WorldLayoutData.FLOOR_NORMALS); mFloorNormals.position(0); ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(WorldLayoutData.FLOOR_COLORS.length * 4); bbFloorColors.order(ByteOrder.nativeOrder()); mFloorColors = bbFloorColors.asFloatBuffer(); mFloorColors.put(WorldLayoutData.FLOOR_COLORS); mFloorColors.position(0); int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, R.raw.light_vertex); int gridShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, R.raw.flat_fragment); mGlProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(mGlProgram, vertexShader); GLES20.glAttachShader(mGlProgram, gridShader); GLES20.glLinkProgram(mGlProgram); GLES20.glEnable(GLES20.GL_DEPTH_TEST); Matrix.setIdentityM(mModelFloor, 0); Matrix.translateM(mModelFloor, 0, 0, -FLOOR_DEPTH, 0); // Floor appears below user checkGLError("onSurfaceCreated"); }