android opengl 背景,Android OpenGL ES透明背景_android_开发99编程知识库

最後的代碼示例用於啟用 GLSurfaceView 透明度。 但是在 GLSurfaceView 使用透明度之前,考慮下面的否定點。啟用透明度要求你在 GLSurfaceView 上使用 setZOrderOnTop 。 這將阻止你將任何其他視圖( 比如 TextView ) 放在透明 GLSurfaceView 之上。 甚至導航抽屜不能滑動到透明 GLSurfaceView ( 忽略技巧 ) 上面。 無論是否透明,GLSurfaceView 只能存在於其他android視圖之上,也不能在它們之間。

透明度要求你使用 setEGLConfigChooser 和 setFormat,如下面的示例所示。 這意味著,你無法獲得由系統選擇的默認格式,這將是該特定設備最好的設備。 更重要的是,你需要確保設備具有支持的格式,如果預期格式沒有出現在 GSoC 示例中。

為透明 其他選項。在Android中運行 Tracer 為 opengl,將顯示 activity的背景圖像繪製為opengl紋理。 如果可以能的話,不要使 GLSurfaceView 透明,可以將背景作為一個opengl紋理呈現在GLSurfaceView中。

在opengl中,對於alpha混合,表面的alpha通道或者透明度不是預先要求的。 兩者都是獨立的。

如果你的opengl組件在其他視圖之間嵌入,則 TextureView ( 技巧 ) 是不錯的選擇。 這是一個很好的例子,它是一個很好的例子,為 GLSurfaceView 2d 繪圖在Android中。

以下示例帶有布局xml和具有背景的透明 GLSurfaceView 代碼。

使用 green 顏色背景的布局xml文件

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity"

android:background="#00FFFF">

android:id="@+id/mySurfaceView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

MainActivity.java 文件從 0.0到 1.0更改 ALPHA 變數以查看表面顏色 red 混合背景 Activity 顏色 greenpackage com.example.transparentsurfaceview;

import android.app.Activity;

import android.graphics.PixelFormat;

import android.opengl.GLES20;

import android.opengl.GLSurfaceView;

import android.os.Bundle;

import javax.microedition.khronos.egl.EGLConfig;

import javax.microedition.khronos.opengles.GL10;

public class MainActivity extends Activity {

private GLSurfaceView mSurfaceView;

private static float ALPHA = 0.5f;

private static float RED = 1.0f;

private static float GREEN = 0.0f;

private static float BLUE = 0.0f;

protected void onCreate( Bundle savedInstanceState ) {

super.onCreate( savedInstanceState );

setContentView( R.layout.activity_main );

mSurfaceView = (GLSurfaceView)findViewById( R.id.mySurfaceView );

mSurfaceView.setEGLContextClientVersion( 2 );

mSurfaceView.setZOrderOnTop( true );

mSurfaceView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0 );

mSurfaceView.getHolder().setFormat( PixelFormat.RGBA_8888 );

mSurfaceView.setRenderer( new GLSurfaceView.Renderer() {

public void onSurfaceCreated( GL10 gl10, EGLConfig eglConfig ) {

GLES20.glClearColor( RED, GREEN, BLUE, ALPHA );

}

public void onSurfaceChanged( GL10 gl10, int i, int i2 ) {}

public void onDrawFrame( GL10 gl10 ) {

GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值