public override void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config) { base.OnSurfaceCreated(gl, config); //SETUP OpenGL ES GLES20.GlClearColor(0.9f, 0.9f, 0.9f, 1.0f); GLES20.GlEnable(GLES20.GlDepthTest); //uncoment if needs enabled dpeth test //GLES20.GlEnable(2884); // GlCullFace == 2884 see OpenGL documentation to this constant value GLES20.GlDisable(2884); //GLES20.GlFrontFace(GLES20.GlCcw); //GLES20.GlCullFace(GLES20.GlFront); GLES20.GlEnable(GL10.GlBlend); GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); // GLES20.GlDisable(GL10.GlLighting); // GLES20.GlEnable(2884); // GLES20.GlDisable(GL10.GlDepthBufferBit); // GLES20.GlEnable(GL10.GlDither); // GLES20.GlEnable(GL10.GlBlend); // GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOne); //ENDSETUP OpenGL ES //Loading objects glObjects.Add(new GLObject(this, "vertex_shader", "fragment_shader", "oldhouse_objvertex", "oldhouse_objnormal", "oldhouse_objtexture", "body")); //Ask android to run RAM garbage cleaner System.GC.Collect(); }
public override void DrawFrame() { //Glass code with enable blend GLES20.GlEnable(GL10.GlBlend); GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); if (brocken) { lx = 0.9f; ly = 0.0f; lz = 0.0f; lw += 0.01f; if (lw > 0.5) { lw = 0; } } else { lw = 0; } base.DrawFrame(); GLES20.GlDisable(GL10.GlBlend); }
/** * \brief Draw the video keyframe (in OpenGL). * @param mvpMatrix the model-view-projection matrix. */ private void DrawKeyFrame(float[] mvpMatrix) { GLES20.GlEnable(GLES20.GlBlend); GLES20.GlBlendFunc(GLES20.GlSrcAlpha, GLES20.GlOneMinusSrcAlpha); GLES20.GlUseProgram(mKeyframe_Program_GL_ID); int vertexHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexPosition"); int textureCoordHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexTexCoord"); int mvpMatrixHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "modelViewProjectionMatrix"); int texSampler2DHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "texSampler2D"); GLES20.GlVertexAttribPointer(vertexHandle, 3, GLES20.GlFloat, false, 0, mVertices_Buffer); GLES20.GlVertexAttribPointer(textureCoordHandle, 2, GLES20.GlFloat, false, 0, mTexCoords_Buffer); GLES20.GlEnableVertexAttribArray(vertexHandle); GLES20.GlEnableVertexAttribArray(textureCoordHandle); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mKeyframeTexture_GL_ID); GLES20.GlUniform1i(texSampler2DHandle, 0); GLES20.GlUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); GLES20.GlDrawElements(GLES20.GlTriangles, mIndices_Number, GLES20.GlUnsignedShort, mIndex_Buffer); GLES20.GlDisableVertexAttribArray(vertexHandle); GLES20.GlDisableVertexAttribArray(textureCoordHandle); GLES20.GlUseProgram(0); GLES20.GlDisable(GLES20.GlBlend); }
public void OnSurfaceCreated(IGL10 gl, EGLConfig config) { GLES20.GlEnable(GL10.GlBlend); // For premultiplied alpha: // GLES20.GlBlendFunc( GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA ); GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); GLES20.GlEnable(GL10.GlScissorTest); TextureCache.Reload(); }
public override void Draw() { if (_light) { GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOne); base.Draw(); GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); } else { base.Draw(); } }
public override void Draw() { base.Draw(); if (_lightMode) { GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOne); DrawRays(); GLES20.GlBlendFunc(GL10.GlSrcAlpha, GL10.GlOneMinusSrcAlpha); } else { DrawRays(); } }
public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config) { // Create the triangle SetupTriangle(); // Create the image information SetupImage(); // Set the clear color to yellow GLES20.GlClearColor(1.0f, 1.0f, 0f, 1); GLES20.GlEnable(GLES20.GlBlend); GLES20.GlBlendFunc(GLES20.GlOne, GLES20.GlOneMinusSrcAlpha); #region Solid colors mode /* * // Create the shaders, solid color * int vertexShader = ShaderHelper.LoadShader(GLES20.GlVertexShader, ShaderHelper.VsSolidColor); * int fragmentShader = ShaderHelper.LoadShader(GLES20.GlFragmentShader, ShaderHelper.FsSolidColor); * * ShaderHelper.SpSolidColor = GLES20.GlCreateProgram(); // create empty OpenGL ES Program * GLES20.GlAttachShader(ShaderHelper.SpSolidColor, vertexShader); // add the vertex shader to program * GLES20.GlAttachShader(ShaderHelper.SpSolidColor, fragmentShader); // add the fragment shader to program * GLES20.GlLinkProgram(ShaderHelper.SpSolidColor); // creates OpenGL ES program executables * * // Set our shader programm * GLES20.GlUseProgram(ShaderHelper.SpSolidColor); */ #endregion #region Texture mode // Create the shaders, images int vertexShader = ShaderHelper.LoadShader(GLES20.GlVertexShader, ShaderHelper.VsImage); int fragmentShader = ShaderHelper.LoadShader(GLES20.GlFragmentShader, ShaderHelper.FsImage); ShaderHelper.SpImage = GLES20.GlCreateProgram(); GLES20.GlAttachShader(ShaderHelper.SpImage, vertexShader); GLES20.GlAttachShader(ShaderHelper.SpImage, fragmentShader); GLES20.GlLinkProgram(ShaderHelper.SpImage); // Set our shader programm GLES20.GlUseProgram(ShaderHelper.SpImage); #endregion }
public void OnSurfaceCreated(IGL10 gl, EGLConfig config) { // GL configurations int bonenum = 48; GLES20.GlGetIntegerv(GLES20.GlMaxTextureSize, mTexSize, 0); ShellViewModel.MaxBone = bonenum; mNpot = hasExt("GL_OES_texture_npot"); // initialize GLES20.GlClearColor(0, 0, 0, 1); GLES20.GlEnable(GLES20.GlDepthTest); GLES20.GlEnable(GLES20.GlBlend); checkGlError("GlEnable"); // GLUtils.texImage2D generates premultiplied-alpha texture. so we use GL_ONE instead of GL_ALPHA GLES20.GlBlendFunc(GL10.GlOne, GL10.GlOneMinusSrcAlpha); GLES20.GlDepthFunc(GLES20.GlLequal); GLES20.GlFrontFace(GLES20.GlCw); checkGlError("GlMiscSettings"); // shader programs mGLSL = new Dictionary <String, GLSL>(); mGLSL.Add("builtin:default", new GLSL(String.Format(Util.ReadAssetString("shader/vs.vsh"), ShellViewModel.MaxBone), Util.ReadAssetString("shader/fs.fsh"))); mGLSL.Add("builtin:default_alpha", new GLSL(String.Format(Util.ReadAssetString("shader/vs.vsh"), ShellViewModel.MaxBone), Util.ReadAssetString("shader/fs_alpha.fsh"))); mGLSL.Add("builtin:nomotion", new GLSL(Util.ReadAssetString("shader/vs_nm.vsh"), Util.ReadAssetString("shader/fs.fsh"))); mGLSL.Add("builtin:nomotion_alpha", new GLSL(Util.ReadAssetString("shader/vs_nm.vsh"), Util.ReadAssetString("shader/fs_alpha.fsh"))); // render targets mRT = new Dictionary <String, RenderTarget>(); mRT.Add("screen", new RenderTarget()); GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, 0); }
/** * Draws the model. * * @param cameraView A 4x4 view matrix, in column-major order. * @param cameraPerspective A 4x4 projection matrix, in column-major order. * @param lightIntensity Illumination intensity. Combined with diffuse and specular material * properties. * @see #setBlendMode(BlendMode) * @see #updateModelMatrix(float[], float) * @see #setMaterialProperties(float, float, float, float) * @see android.opengl.Matrix */ public void Draw(float[] cameraView, float[] cameraPerspective, float lightIntensity) { ShaderUtil.CheckGLError(TAG, "Before draw"); // Build the ModelView and ModelViewProjection matrices // for calculating object position and light. Android.Opengl.Matrix.MultiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Android.Opengl.Matrix.MultiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); GLES20.GlUseProgram(mProgram); // Set the lighting environment properties. Android.Opengl.Matrix.MultiplyMV(mViewLightDirection, 0, mModelViewMatrix, 0, LIGHT_DIRECTION, 0); normalizeVec3(mViewLightDirection); GLES20.GlUniform4f(mLightingParametersUniform, mViewLightDirection[0], mViewLightDirection[1], mViewLightDirection[2], lightIntensity); // Set the object material properties. GLES20.GlUniform4f(mMaterialParametersUniform, mAmbient, mDiffuse, mSpecular, mSpecularPower); // Attach the object texture. GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]); GLES20.GlUniform1i(mTextureUniform, 0); // Set the vertex attributes. GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVertexBufferId); GLES20.GlVertexAttribPointer( mPositionAttribute, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, mVerticesBaseAddress); GLES20.GlVertexAttribPointer( mNormalAttribute, 3, GLES20.GlFloat, false, 0, mNormalsBaseAddress); GLES20.GlVertexAttribPointer( mTexCoordAttribute, 2, GLES20.GlFloat, false, 0, mTexCoordsBaseAddress); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0); // Set the ModelViewProjection matrix in the shader. GLES20.GlUniformMatrix4fv( mModelViewUniform, 1, false, mModelViewMatrix, 0); GLES20.GlUniformMatrix4fv( mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0); // Enable vertex arrays GLES20.GlEnableVertexAttribArray(mPositionAttribute); GLES20.GlEnableVertexAttribArray(mNormalAttribute); GLES20.GlEnableVertexAttribArray(mTexCoordAttribute); if (mBlendMode != BlendMode.Null) { GLES20.GlDepthMask(false); GLES20.GlEnable(GLES20.GlBlend); switch (mBlendMode) { case BlendMode.Shadow: // Multiplicative blending function for Shadow. GLES20.GlBlendFunc(GLES20.GlZero, GLES20.GlOneMinusSrcAlpha); break; case BlendMode.Grid: // Grid, additive blending function. GLES20.GlBlendFunc(GLES20.GlSrcAlpha, GLES20.GlOneMinusSrcAlpha); break; } } GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mIndexBufferId); GLES20.GlDrawElements(GLES20.GlTriangles, mIndexCount, GLES20.GlUnsignedShort, 0); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0); if (mBlendMode != BlendMode.Null) { GLES20.GlDisable(GLES20.GlBlend); GLES20.GlDepthMask(true); } // Disable vertex arrays GLES20.GlDisableVertexAttribArray(mPositionAttribute); GLES20.GlDisableVertexAttribArray(mNormalAttribute); GLES20.GlDisableVertexAttribArray(mTexCoordAttribute); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); ShaderUtil.CheckGLError(TAG, "After draw"); }
/** * \brief Draw the video icon (in OpenGL). * @param mvpMatrix the model-view-projection matrix. * @param status the video state. */ private void DrawIcon(float[] mvpMatrix, PikkartVideoPlayer.VideoSate.VIDEO_STATE status) { GLES20.GlEnable(GLES20.GlBlend); GLES20.GlBlendFunc(GLES20.GlSrcAlpha, GLES20.GlOneMinusSrcAlpha); GLES20.GlUseProgram(mKeyframe_Program_GL_ID); int vertexHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexPosition"); int textureCoordHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexTexCoord"); int mvpMatrixHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "modelViewProjectionMatrix"); int texSampler2DHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "texSampler2D"); GLES20.GlVertexAttribPointer(vertexHandle, 3, GLES20.GlFloat, false, 0, mVertices_Buffer); GLES20.GlVertexAttribPointer(textureCoordHandle, 2, GLES20.GlFloat, false, 0, mTexCoords_Buffer); GLES20.GlEnableVertexAttribArray(vertexHandle); GLES20.GlEnableVertexAttribArray(textureCoordHandle); GLES20.GlActiveTexture(GLES20.GlTexture0); switch ((int)status) { case 0: //end GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 1: //pasued GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 2: //stopped GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 3: //playing GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 4: //ready GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 5: //not ready GLES20.GlBindTexture(GLES20.GlTexture2d, mIconBusyTexture_GL_ID); break; case 6: //buffering GLES20.GlBindTexture(GLES20.GlTexture2d, mIconBusyTexture_GL_ID); break; case 7: //error GLES20.GlBindTexture(GLES20.GlTexture2d, mIconErrorTexture_GL_ID); break; default: GLES20.GlBindTexture(GLES20.GlTexture2d, mIconBusyTexture_GL_ID); break; } GLES20.GlUniform1i(texSampler2DHandle, 0); GLES20.GlUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); GLES20.GlDrawElements(GLES20.GlTriangles, mIndices_Number, GLES20.GlUnsignedShort, mIndex_Buffer); GLES20.GlDisableVertexAttribArray(vertexHandle); GLES20.GlDisableVertexAttribArray(textureCoordHandle); GLES20.GlUseProgram(0); GLES20.GlDisable(GLES20.GlBlend); }