openGL 在android上使用

public class GlsurfaceviewActivity extends Activity {
 
 private myGLSurfaceView mGLSurfaceView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mGLSurfaceView = new myGLSurfaceView(this);
        setContentView(mGLSurfaceView);
        //setContentView(R.layout.main);
    }
}
public class myGLSurfaceView extends GLSurfaceView {
 private myGLRenderer mrender;
 
 public myGLSurfaceView(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
  mrender = new myGLRenderer();
        setRenderer(mrender); //指定mrender对象,该mrender对象将会完成GLSurfaceView里3D图形的绘制。
 }
}
public class myGLRenderer implements Renderer {//实例化opengl.GLSurfaceView.Renderer需要实现3个方法,
public void onDrawFrame(GL10 gl) ;绘制GLSurfaceView的当前帧。
public void onSurfaceChanged(GL10 gl, int width, int height) :GL10就是画笔,当GLSurfaceView大小改变时回调。
public void onSurfaceCreated(GL10 gl, EGLConfig config) :当GLSurfaceView创建时回调。
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  // TODO Auto-generated method stub
  
  loadGif("data/app/girl.gif");
   gl.glEnable(GL11.GL_DITHER);//启用抗抖动
        gl.glDisable(GL11.GL_LIGHTING);
  //设置系统对某方面的修正,这里对透视修正。
        gl.glHint(GL10.GL_PERSPCTIVE_CORRECTION_HINT,gGL10.GL_FASTEST);
        // Enable textures.启用纹理贴图
        gl.glEnable(GL11.GL_TEXTURE_2D);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, GL11.GL_REPLACE);

        // Set up state for multitexture operations. Since multitexture is
        // currently used
        // only for layered crossfades the needed state can be factored out into
        // one-time
        // initialization. This section may need to be folded into drawMixed2D()
        // if multitexture
        // is used for other effects.

        // Enable Vertex Arrays
        gl.glEnableClientState(GL11.GL_VERTEX_ARRAY);
     

        // Enable depth test.
        gl.glEnable(GL11.GL_DEPTH_TEST);
        gl.glDepthFunc(GL11.GL_LEQUAL);

       
        // Set the blend function for premultiplied alpha.
        gl.glEnable(GL10.GL_BLEND);     
        gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
       
        // Set the background color.
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClear(GL11.GL_COLOR_BUFFER_BIT);
 }
  public void onSurfaceChanged(GL10 gl, int width, int height) {
  // TODO Auto-generated method stub
  final float zNear = 0.1f;
        final float zFar = 100.0f;
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL11.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU.gluPerspective(gl, 45.0f, (float) width / height, zNear, zFar);
        gl.glMatrixMode(GL11.GL_MODELVIEW);
 }
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值