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. */ glDisable(GL_DITHER); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, 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(). */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* * Now we're ready to draw some 3D objects */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, mTextureID); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); long time = SystemClock.uptimeMillis() % 4000L; float angle = 0.090f * ((int) time); glRotatef(angle, 0, 0, 1.0f); mTriangle.draw(gl); }
/** * Draws a frame where the content of the electron beam is collapsing inwards upon itself * vertically with red / green / blue channels dispersing and eventually merging down to a single * horizontal line. * * @param stretch The stretch factor. 0.0 is no collapse, 1.0 is full collapse. */ private void drawVStretch(float stretch) { // compute interpolation scale factors for each color channel final float ar = scurve(stretch, 7.5f); final float ag = scurve(stretch, 8.0f); final float ab = scurve(stretch, 8.5f); if (DEBUG) { Slog.d(TAG, "drawVStretch: stretch=" + stretch + ", ar=" + ar + ", ag=" + ag + ", ab=" + ab); } // set blending GLES10.glBlendFunc(GLES10.GL_ONE, GLES10.GL_ONE); GLES10.glEnable(GLES10.GL_BLEND); // bind vertex buffer GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer); GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY); // set-up texturing GLES10.glDisable(GLES10.GL_TEXTURE_2D); GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES); // bind texture and set blending for drawing planes GLES10.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexNames[0]); GLES10.glTexEnvx( GLES10.GL_TEXTURE_ENV, GLES10.GL_TEXTURE_ENV_MODE, mMode == MODE_WARM_UP ? GLES10.GL_MODULATE : GLES10.GL_REPLACE); GLES10.glTexParameterx( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR); GLES10.glTexParameterx( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR); GLES10.glTexParameterx( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_CLAMP_TO_EDGE); GLES10.glTexParameterx( GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_CLAMP_TO_EDGE); GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES); GLES10.glTexCoordPointer(2, GLES10.GL_FLOAT, 0, mTexCoordBuffer); GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY); // draw the red plane setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ar, mSwapNeeded); GLES10.glColorMask(true, false, false, true); GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4); // draw the green plane setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag, mSwapNeeded); GLES10.glColorMask(false, true, false, true); GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4); // draw the blue plane setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ab, mSwapNeeded); GLES10.glColorMask(false, false, true, true); GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4); // clean up after drawing planes GLES10.glDisable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES); GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY); GLES10.glColorMask(true, true, true, true); // draw the white highlight (we use the last vertices) if (mMode == MODE_COOL_DOWN) { GLES10.glColor4f(ag, ag, ag, 1.0f); GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4); } // clean up GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY); GLES10.glDisable(GLES10.GL_BLEND); }