@Override public void onDrawFrame(GL10 unused) { GLES20.glClearColor(0f, 0f, 0f, 0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); if (mShaderCompilerSupport[0] == false) { return; } GLES20.glDisable(GLES20.GL_DEPTH_TEST); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); float angle = (SystemClock.uptimeMillis() % 5000) / 5000f * 360; Matrix.setRotateM(mMatrixModel, 0, angle, 1, 2, 0); Matrix.multiplyMM(mMatrixModelViewProjection, 0, mMatrixView, 0, mMatrixModel, 0); Matrix.multiplyMM( mMatrixModelViewProjection, 0, mMatrixProjection, 0, mMatrixModelViewProjection, 0); mShaderSpline.useProgram(); GLES20.glUniformMatrix4fv( mShaderSpline.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0); GLES20.glVertexAttribPointer( mShaderSpline.getHandle("aPosition"), 2, GLES20.GL_FLOAT, false, 0, mBufferSpline); GLES20.glEnableVertexAttribArray(mShaderSpline.getHandle("aPosition")); for (float[] ctrl : mSplines) { GLES20.glUniform3fv(mShaderSpline.getHandle("uCtrl"), 4, ctrl, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, COUNT_VERTICES); } }
public void onSurfaceCreated(GL10 unused, EGLConfig config) { // Set the background frame color GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLES20.glDisable(GLES20.GL_DITHER); GLES20.glDisable(GL10.GL_LIGHTING); GLES20.glDisable(GLES20.GL_DEPTH_TEST); GLES20.glEnable(GLES20.GL_TEXTURE_2D); GLES20.glEnable(GL10.GL_BLEND); GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); inirBuffers(); int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program GLES20.glLinkProgram(mProgram); // creates OpenGL program executables // get handle to the vertex shader's vPosition member maPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); maTexCoordsHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoords"); mSampleHandle = GLES20.glGetUniformLocation(mProgram, "u_Texture"); // mSampleHandle2 = GLES20.glGetUniformLocation(mProgram, "u_Texture2"); mOpacityHandle = GLES20.glGetUniformLocation(mProgram, "u_Opacity"); }
@Override public void onDrawFrame(GL10 unused) { GLES20.glClearColor(0f, 0f, 0f, 1f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); if (mShaderCompilerSupport[0] == false) { return; } GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); long time = SystemClock.uptimeMillis(); if (mLastRenderTime == -1) { for (Star star : mStarArray) { star.randomize(); star.mPosition[2] = (float) (Math.random() * 4 - 2); } mLastRenderTime = time; } float t = (time - mLastRenderTime) / 1000f; mLastRenderTime = time; mShaderStar.useProgram(); GLES20.glUniformMatrix4fv( mShaderStar.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0); GLES20.glUniform1f(mShaderStar.getHandle("uSize"), .01f); GLES20.glVertexAttribPointer( mShaderStar.getHandle("aPosition"), 2, GLES20.GL_BYTE, false, 0, mBufferVertices); GLES20.glEnableVertexAttribArray(mShaderStar.getHandle("aPosition")); for (Star star : mStarArray) { star.mPosition[2] += star.mSpeed * t; if (star.mPosition[2] > 2) { star.randomize(); } } Arrays.sort( mStarArray, new Comparator<Star>() { @Override public int compare(Star arg0, Star arg1) { return arg0.mPosition[2] < arg1.mPosition[2] ? -1 : 1; } }); for (Star star : mStarArray) { GLES20.glUniform3fv(mShaderStar.getHandle("uPosition"), 1, star.mPosition, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); } GLES20.glDisable(GLES20.GL_BLEND); }
@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { // Set rendering options GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glDisable(GLES20.GL_DITHER); // Face culling GLES20.glEnable(GLES20.GL_CULL_FACE); GLES20.glFrontFace(GL10.GL_CCW); GLES20.glCullFace(GLES20.GL_BACK); // Depth GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glDepthFunc(GLES20.GL_LEQUAL); GLES20.glDepthMask(true); }
private void renderLines() { if (phenixLineProgram != null) { if (!phenixLineProgram.use()) { return; } float angle = 360.0f * getTimeDeltaByScale((long) (1 * 50000L / speedFactor / rotationSpeedFactor)); Matrix.setRotateM(M_matrix, 0, angle, 0, 0, 1.0f); Matrix.multiplyMM(MVP_matrix, 0, V_matrix, 0, M_matrix, 0); Matrix.multiplyMM(MVP_matrix, 0, P_matrix, 0, MVP_matrix, 0); float delta = getTimeDeltaByScale((long) (1 * 25000L / speedFactor)); lineVertices.bind(phenixLineProgram, "aPosition", null); GLES20.glUniformMatrix4fv( phenixLineProgram.getUniformLocation("uMVPMatrix"), 1, false, MVP_matrix, 0); GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), delta); GLES20.glUniform1f( phenixLineProgram.getUniformLocation("uBrightness"), brightness * brightnessFactor); GLES20.glUniform3f( phenixLineProgram.getUniformLocation("uColor"), linesColorRed, linesColorGreen, linesColorBlue); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE); GLES20.glLineWidth(lineWidth * lineWidthFactor); lineVertices.draw(GLES20.GL_LINES, 0, MOVING_LINE_COUNT); GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), 0.0f); lineVertices.draw(GLES20.GL_LINES, MOVING_LINE_COUNT, STALE_LINE_COUNT); GLES20.glDisable(GLES20.GL_BLEND); lineVertices.unbind(phenixLineProgram, "aPosition", null); } }
@Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { // this.scale = GameConstants.scale; // set the background frame color GLES20.glClearColor(0.29f, 0.95f, 0.88f, 1.0f); // Use culling to remove back faces. GLES20.glEnable(GLES20.GL_CULL_FACE); // Enable depth testing // GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); gsmanager.Push(new MainScreenState()); gsmanager.Push(new InitStageScreenState(1500)); gsmanager.Push(new MenuScreenState()); gsmanager.Push(new SplitScreenState(2000)); }
private void renderBlurTexture(int textureIndex) { if (postProgram.use()) { renderTextures[textureIndex].bind(GLES20.GL_TEXTURE0, postProgram, "sTexture"); quadVertices.bind(postProgram, "aPosition", "aTextureCoord"); GLES20.glUniform1f(postProgram.getUniformLocation("uBlur"), blur * blurFactor); GLES20.glUniformMatrix4fv( postProgram.getUniformLocation("uMVPMatrix"), 1, false, Q_matrix, 0); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE); quadVertices.draw(GLES20.GL_TRIANGLE_STRIP); GLES20.glDisable(GLES20.GL_BLEND); quadVertices.unbind(postProgram, "aPosition", "aTextureCoord"); renderTextures[textureIndex].unbind(GLES20.GL_TEXTURE0); } }
private void drawParticles() { float currentTime = (System.nanoTime() - globalStartTime) / 1000000000f; redParticleShooter.addParticles(particleSystem, currentTime, 1); greenParticleShooter.addParticles(particleSystem, currentTime, 1); blueParticleShooter.addParticles(particleSystem, currentTime, 1); setIdentityM(modelMatrix, 0); updateMvpMatrix(); glDepthMask(false); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); particleProgram.useProgram(); particleProgram.setUniforms(modelViewProjectionMatrix, currentTime, particleTexture); particleSystem.bindData(particleProgram); particleSystem.draw(); glDisable(GL_BLEND); glDepthMask(true); }
/** Draw the desktop. Make sure {@link hasVideoFrame} returns true. */ public void draw(float[] combinedMatrix, boolean isTransparent) { GLES20.glUseProgram(mProgramHandle); // Pass in model view project matrix. GLES20.glUniformMatrix4fv(mCombinedMatrixHandle, 1, false, combinedMatrix, 0); // Pass in texture coordinate. GLES20.glVertexAttribPointer( mTextureCoordinateHandle, TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false, 0, TEXTURE_COORDINATES); GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle); GLES20.glVertexAttribPointer( mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mPosition); GLES20.glEnableVertexAttribArray(mPositionHandle); // Enable transparency. GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); // Pass in transparency. GLES20.glVertexAttrib1f(mTransparentHandle, isTransparent ? 0.5f : 1.0f); // Link texture data with texture unit. GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle); GLES20.glUniform1i(mTextureUniformHandle, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, VERTICES_NUMBER); GLES20.glDisable(GLES20.GL_BLEND); GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mTextureCoordinateHandle); }
@Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { GLES20.glClearColor(0.82f, 0.84f, 0.85f, 1.0f); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); if (birdiePercent == 0 && parPercent == 0 && bogiePercent == 0) { birdiePercent = .3333333f; parPercent = .3333333f; bogiePercent = .3333333f; } System.out.println("pars %" + Float.toString(parPercent)); System.out.println("birdies %" + Float.toString(birdiePercent)); System.out.println("bogies %" + Float.toString(bogiePercent)); float colorYellow[] = {.83f, 0.65f, 0.16f, 1.0f}; float colorGreen[] = {.33f, 0.47f, 0.25f, 1.0f}; float colorBlue[] = {.14f, .35f, .48f, 1.0f}; float colorBG[] = {0.82f, 0.84f, 0.85f, 1.0f}; float colorWheelBG[] = {.66f, .66f, .66f, 1.0f}; float colorShadow[] = {0f, 0f, 0f, 0.7f}; float wheelHoleCoords[] = {0f, 0f, 0f}; float innerHoleRadius = .2f; wheelHole = new CircleShape(innerHoleRadius, colorBG, wheelHoleCoords); float wheelBGCoords[] = {0f, 0f, 0f}; float radius = .5f; wheelBG = new CircleShape(radius, colorWheelBG, wheelBGCoords); float buffer = .005f; birdiePieWheel = new PieWheelShape(radius, colorBlue, (birdiePercent + buffer), false); parPieWheel = new PieWheelShape(radius, colorGreen, (parPercent + buffer), false); bogiePieWheel = new PieWheelShape(radius, colorYellow, (bogiePercent + buffer), false); shadowPieWheel = new PieWheelShape(radius, colorShadow, 1f, true); }
@Override public void onDrawFrame(GL10 gl) { // 清除深度缓冲与颜色缓冲 GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); MatrixState.pushMatrix(); MatrixState.translate(0, -2, 0); desert.drawSelf(desertId); MatrixState.popMatrix(); // 开启混合 GLES20.glEnable(GLES20.GL_BLEND); // 设置混合因子 GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); MatrixState.pushMatrix(); MatrixState.translate(0, -2, 0); group.drawSelf(); MatrixState.popMatrix(); // 关闭混合 GLES20.glDisable(GLES20.GL_BLEND); }
/////////////////////////////////////////////////////////////////////////////////////// // render /////////////////////////////////////////////////////////////////////////////////////// // Draw every sprite's primitives /////////////////////////////////////////////////////////////////////////////////////// // IN: true=render BACKground // false=render FOREground /////////////////////////////////////////////////////////////////////////////////////// @Override public void render(int floor, boolean backGround) { // Display every sprites GLES20.glEnable(GLES20.GL_BLEND); float[] color = new float[4]; // =textureEngine.graphicStuff.getFloat(GL11.GL_CURRENT_COLOR, 4); color[0] = 1f; color[1] = 1f; color[2] = 1f; color[3] = 1f; Vector3f ambient = ClientEngineZildo.ortho.getAmbientColor(); if (ambient != null) { color[0] = ambient.x; color[1] = ambient.y; color[2] = ambient.z; } // Respect order from bankOrder boolean endSequence = false; int posBankOrder = 0; // Retrieve the sprite's order int[][][] bankOrder = ClientEngineZildo.spriteDisplay.getBankOrder(); int phase = (backGround) ? 0 : 1; while (!endSequence) { int numBank = bankOrder[floor][phase][posBankOrder * 4]; if (numBank == -1) { endSequence = true; } else { // Render the n sprites from this bank int nbQuads = bankOrder[floor][phase][posBankOrder * 4 + 1]; int iCurrentFX = bankOrder[floor][phase][posBankOrder * 4 + 2]; int alpha = bankOrder[floor][phase][posBankOrder * 4 + 3]; EngineFX currentFX = EngineFX.values()[iCurrentFX]; int texId = textureEngine.getNthTexture(numBank); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId); // Select the right pixel shader (if needed) if (pixelShaderSupported) { switch (currentFX) { case NO_EFFECT: shaders.setCurrentShader(GLShaders.textured); break; case PERSO_HURT: // A sprite has been hurt shaders.setCurrentShader(GLShaders.wounded); shaders.setWoundedColor( new Vector4f( (float) Math.random(), (float) Math.random(), (float) Math.random(), 1)); /* ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(1)); ClientEngineZildo.pixelShaders.setParameter(1, "randomColor", ); */ break; case YELLOW_HALO: shaders.setCurrentShader(GLShaders.goldFilter); shaders.setGoldFactor((float) (0.6 + 0.4 * Math.cos(3 * gamma))); break; case STAR: shaders.setCurrentShader(GLShaders.star); shaders.setStarNoise(gamma, (float) Math.random()); break; default: if (currentFX.needPixelShader()) { // This is a color replacement, so get the right ones Vector4f[] tabColors = ClientEngineZildo.pixelShaders.getConstantsForSpecialEffect(currentFX); // And enable the 'color replacement' pixel shader shaders.setCurrentShader(GLShaders.switchColor); shaders.setSwitchColors(tabColors); /* ClientEngineZildo.pixelShaders.setParameter(0, "Color1", tabColors[2]); ClientEngineZildo.pixelShaders.setParameter(0, "Color2", tabColors[3]); ClientEngineZildo.pixelShaders.setParameter(0, "Color3", tabColors[0].scale(color[0])); ClientEngineZildo.pixelShaders.setParameter(0, "Color4", tabColors[1].scale(color[0])); */ } else { shaders.setCurrentShader(GLShaders.textured); } } } switch (currentFX) { case SHINY: GLES20.glBlendFunc(GLES20.GL_SRC_COLOR, GLES20.GL_ONE); // _MINUS_SRC_ALPHA); shaders.setColor(1, (float) Math.random(), 0, (float) Math.random()); break; case QUAD: GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); shaders.setColor( 0.5f + 0.5f * (float) Math.random(), 0.5f * (float) Math.random(), 0, 1); break; case FOCUSED: GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); // FIXME: previously color3f shaders.setColor(1.0f, 1.0f, 1.0f, alpha / 255.0f); break; case FONT_PEOPLENAME: GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); shaders.setColor(0.9f, 0.5f, 0.2f, alpha / 255.0f); break; default: color[3] = alpha / 255.0f; shaders.setColor(color[0], color[1], color[2], color[3]); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); } meshSprites[numBank].render(nbQuads); posBankOrder++; } } // Deactivate pixel shader if (pixelShaderSupported) { shaders.setCurrentShader(GLShaders.textured); } GLES20.glDisable(GLES20.GL_BLEND); gamma = (float) ((gamma + 0.01f) % (Math.PI * 2)); }
@Override public void glBlendFunc(int sfactor, int dfactor) { GLES20.glBlendFunc(sfactor, dfactor); }
/** * drawing function also calculates color value * * @param mvpMatrix */ public void draw(float[] mvpMatrix) { float dif = Math.abs(midx - midTx) + Math.abs(midy - midTy) + Math.abs(sizx - sizTx) + Math.abs(sizy - sizTy); // Log.d("ASCII","dif"+dif); if (dif > 0.01) { midx += (midTx - midx) / 10.0f; midy += (midTy - midy) / 10.0f; sizx += (sizTx - sizx) / 10.0f; sizy += (sizTy - sizy) / 10.0f; } // color[0]= recBlink; // color[1]=1.0f-recBlink/5; // color[2]=1.0f-recBlink/5; GLES20.glUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // get handle to fragment shader's vColor member mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); // get handle to texture coordinate variable mTextureHandle = GLES20.glGetAttribLocation(mProgram, "TexCoordIn"); // if (mTextureHandle == -1) Log.e("ASCII", "TexCoordIn not found"); // get handle to shape's texture reference fsTexture = GLES20.glGetUniformLocation(mProgram, "Texture"); // if (fsTexture == -1) Log.e("ASCII", "Texture not found"); // GLES20.glUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); // XQGLRenderer.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); // MyGLRenderer.checkGlError("glUniformMatrix4fv"); // GLES20.glEnableVertexAttribArray(mPositionHandle); // GLES20.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); GLES20.glVertexAttribPointer( mTextureHandle, COORDS_PER_TEXTURE, GLES20.GL_FLOAT, false, textureStride, textureBuffer); GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureRef); GLES20.glUniform1i(fsTexture, 3); // GLES20.glEnableVertexAttribArray(mPositionHandle); GLES20.glEnableVertexAttribArray(mTextureHandle); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); // Draw the shape GLES20.glDrawElements( GLES20.GL_TRIANGLE_STRIP, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer); GLES20.glDisable(GLES20.GL_BLEND); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mTextureHandle); }
public void draw( float[] mvpMatrix, float[] normalMat) { // pass in the calculated transformation matrix, and the normal transform // mat; // Add program to OpenGL ES environment GLES20.glUseProgram(mProgram); // GLES20.glPolygonMode(GLES20.GL_FRONT,GLES20.GL_LINE); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member // mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle // GLES20.glUniform4fv(mColorHandle, 1, color, 0); mColorHandle = GLES20.glGetAttribLocation(mProgram, "vColor"); GLES20.glEnableVertexAttribArray(mColorHandle); // Prepare the color data GLES20.glVertexAttribPointer( mColorHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, colorBuffer); // now deal with normals mNormalHandle = GLES20.glGetAttribLocation(mProgram, "vNormal"); GLES20.glEnableVertexAttribArray(mNormalHandle); // Prepare the normal data GLES20.glVertexAttribPointer( mNormalHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, normalBuffer); // now deal with tex coords mTexCHandle = GLES20.glGetAttribLocation(mProgram, "vTexCoord"); GLES20.glEnableVertexAttribArray(mTexCHandle); GLES20.glVertexAttribPointer( mTexCHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, texCBuffer); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); GLES20.glActiveTexture(GLES20.GL_TEXTURE1); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[1]); GLES20.glUniform1i(GLES20.glGetUniformLocation(mProgram, "s_texture00"), 0); GLES20.glUniform1i(GLES20.glGetUniformLocation(mProgram, "s_texture01"), 1); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); mNormalMatHandle = GLES20.glGetUniformLocation(mProgram, "uNormalMat"); float[] scale = new float[16]; Matrix.setIdentityM(scale, 0); Matrix.scaleM(scale, 0, 1.0f, 1.0f, 1.0f); ; // mvp = Proj*view*model*scale float[] temp = new float[16]; Matrix.multiplyMM(temp, 0, mvpMatrix, 0, scale, 0); // Apply the projection and view transformation // GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, temp, 0); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, temp, 0); GLES20.glUniformMatrix4fv(mNormalMatHandle, 1, false, normalMat, 0); // Draw the triangle // GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); // this line will draw the whole // set GLES20.glEnable(GLES20.GL_BLEND); // source_frag, dest_pixel // dest_pixel = source_frag*source_alpha + (1- source_alpha)*dest_pixel; GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glActiveTexture(GLES20.GL_TEXTURE1); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[1]); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[2]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); // this will just draw one face; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[3]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 6, 6); // this will just draw one face; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[4]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 12, 6); // this will just draw one face; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[5]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 18, 6); // this will just draw one face; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[6]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 24, 6); // this will just draw one face; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[7]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 30, 6); // this will just draw one face; GLES20.glDisable(GLES20.GL_BLEND); /* GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); GLES20.glActiveTexture(GLES20.GL_TEXTURE1); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[2]); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 6, 6); // this will just draw one face; */ // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); GLES20.glDisableVertexAttribArray(mColorHandle); GLES20.glDisableVertexAttribArray(mNormalHandle); GLES20.glDisableVertexAttribArray(mTexCHandle); }
@Override public void blendFunc(final int sfactor, final int dfactor) { checkOpenGLThread(); GLES20.glBlendFunc(sfactor, dfactor); }
@Override public void draw() { GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); super.draw(); GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); }
public void DrawModel() { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, m.textureHandle[0]); Mat4 rot; if (!haslanded) { Vec3 cross = VecMath.CrossProduct(MainActivity.phone_n, MainActivity.init_phone_n); phone_n = MainActivity.phone_n; init_phone_n = MainActivity.init_phone_n; Vec3 ny = new Vec3(0, 0, -1); Vec3 cross2 = VecMath.CrossProduct(init_phone_n, ny); float ang2 = (float) Math.asin(VecMath.Norm(cross2) / (VecMath.Norm(init_phone_n))); ; Mat4 rotmat2 = VecMath.ArbRotate(cross2, ang2); // Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang); Mat4 rotmat = VecMath.ArbRotate(VecMath.Normalize(cross), MainActivity.phone_ang); if (Math.abs(init_phone_n.z) > Math.abs(init_phone_n.y)) rotmat = VecMath.ArbRotate( VecMath.MultVec3(VecMath.Rx(-(float) Math.PI / 2), VecMath.Normalize(cross)), MainActivity.phone_ang); Mat4 rotmatf = VecMath.Mult(rotmat, rotmat2); Ro = rotmat; // Ro = VecMath.ArbRotate( VecMath.MultVec3(VecMath.Rx(-(float) Math.PI/2), // VecMath.Normalize(cross)), MainActivity.phone_ang); rot = VecMath.Mult(T, Ro); GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(rot.m)); } else { rot = T; GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(rot.m)); // Ro = rot; } // GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(Ro.m)); m.DrawModel(); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); // draw debug spheres for (int i = 0; i < 3; i++) { float r = .3f; float coss = (float) (r * Math.cos(Math.PI / 6 + i * 2 * Math.PI / 3)); float sinn = (float) (r * Math.sin(Math.PI / 6 + i * 2 * Math.PI / 3)); Vec3 poss = new Vec3(coss, -.5f, sinn); Mat4 TT = VecMath.T(poss); Mat4 SS = VecMath.S(.2f, .2f, .2f); Mat4 tott = VecMath.Mult(T, VecMath.Mult(Ro, VecMath.Mult(TT, SS))); fin_pos[i] = VecMath.MultVec3(tott, poss); // fin position in absolute coords GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(tott.m)); sphere[i].DrawModel(); } if (isthrusting && fuel > .0f) { GLES20.glUniform1i(GLES20.glGetUniformLocation(Shader.program, "draw_exhaustf"), 1); Mat4 Tf = VecMath.Mult(rot, VecMath.T(0, -.8f, 0)); GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(Tf.m)); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glDepthMask(false); fire.DrawModel(); GLES20.glDepthMask(true); GLES20.glDisable(GLES20.GL_BLEND); GLES20.glUniform1i(GLES20.glGetUniformLocation(Shader.program, "draw_exhaustf"), 0); } }
@Override public boolean initObject() { if (imageResId != 0) { vertexCount = coordinates.length / COORDS_PER_VERTEX; ByteBuffer buff = ByteBuffer.allocateDirect(coordinates.length * 4); buff.order(ByteOrder.nativeOrder()); vBuffer = buff.asFloatBuffer(); vBuffer.put(coordinates); vBuffer.position(0); ByteBuffer drawBuff = ByteBuffer.allocateDirect(drawOrder.length * 2); drawBuff.order(ByteOrder.nativeOrder()); drawBuffer = drawBuff.asShortBuffer(); drawBuffer.put(drawOrder); drawBuffer.position(0); ByteBuffer textBuff = ByteBuffer.allocateDirect(textureCoordinates.length * 4); textBuff.order(ByteOrder.nativeOrder()); textureBuffer = textBuff.asFloatBuffer(); textureBuffer.put(textureCoordinates); textureBuffer.position(0); // Prepare shaders and OpenGL program vertexShaderHandle = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); fragShaderHandle = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); programHandle = GLES20.glCreateProgram(); // create empty OpenGL Program GLES20.glAttachShader(programHandle, vertexShaderHandle); // add the vertex shader to program GLES20.glAttachShader(programHandle, fragShaderHandle); // add the fragment shader to program GLES20.glBindAttribLocation(programHandle, 0, "aPosition"); GLES20.glBindAttribLocation(programHandle, 1, "aTexCoordinate"); GLES20.glLinkProgram(programHandle); // create OpenGL program executables final int[] status = new int[1]; GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, status, 0); if (status[0] == 0) { Log.e( "GLSprite", "Error compiling OpenGL program: " + GLES20.glGetProgramInfoLog(programHandle)); GLES20.glDeleteProgram(programHandle); programHandle = 0; throw new RuntimeException("Error creating OpenGL program."); } textureDataHandle = GLUtil.loadTexture(mCanvas.getView().getContext(), imageResId); // get handle to vertex shader's aPosition member positionHandle = GLES20.glGetAttribLocation(programHandle, "aPosition"); textureCoordinateHandle = GLES20.glGetAttribLocation(programHandle, "aTexCoordinate"); mModelMatrixHandle = GLES20.glGetUniformLocation(programHandle, "uMVMatrix"); GLES20Renderer.checkGLError("glUniformLocation uMVMatrix"); mMVPMatrixHandle = GLES20.glGetUniformLocation(programHandle, "uMVPMatrix"); GLES20Renderer.checkGLError("glUniformLocation uMVPMatrix"); textureUniformHandle = GLES20.glGetUniformLocation(programHandle, "u_Texture"); GLES20Renderer.checkGLError("glUniformLocation u_Texture"); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); initialized = true; return true; } else { return false; } }
public void draw(StandardProgram prog, Viewport vp) { // get handle to vertex shader's vPosition member mPositionHandle = prog.getAttributeLocation("vPosition"); // set the vertext pointer to the front of the buffer GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, buffers[1]); // draw order GLES20.glEnableVertexAttribArray(mPositionHandle); // get handle to fragment shader's vColor member mColorHandle = prog.getUniformLocation("vColor"); // texture stuff mTextureUniformHandle = prog.getUniformLocation("u_Texture"); mTextureCoordinateHandle = prog.getAttributeLocation("a_TexCoordinate"); tm.setTextureToRepeat(R.drawable.blank); GLES20.glUniform1i(mTextureUniformHandle, 0); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); GLES20.glEnable(GLES20.GL_BLEND); GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle); // get handle to shape's transformation matrix mMVPMatrixHandle = prog.getUniformLocation("uMVPMatrix"); // start the position at -1, -1 Matrix.setIdentityM(mMMatrix, 0); Matrix.translateM(mMMatrix, 0, 0, 0, 1.0f); // z index is at the very front // ---- draw a puddle setBufferPosition(PUDDLE); setColor(normalColor); setDrawPosition(300f, -300f); setScale(9.0f, 7.0f); // set up the view matrix and projection matrix Matrix.multiplyMM(eyeMatrix, 0, vp.getViewMatrix(), 0, mMMatrix, 0); Matrix.multiplyMM(mvpMatrix, 0, vp.getProjMatrix(), 0, eyeMatrix, 0); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); // Draw GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, 0); // ---- end draw puddle // IMPORTANT: Unbind from the buffer when we're done with it. GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); }