android 游戏OpenGL学习笔记1

package com.hyl.opengl.a;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity; 
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
import android.os.Bundle;
public class B extends Activity implements GLSurfaceView.Renderer{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		GLSurfaceView view =new GLSurfaceView(this);
		view.setRenderer(this);
		super.onCreate(savedInstanceState);
		super.setContentView(view);
	}

	@Override
	public void onDrawFrame(GL10 gl) {
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
		//设定背景颜色为绿色
		gl.glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
		//重设视图模型转换,用于观察创建的物体
		gl.glLoadIdentity();
		gl.glTranslatef(0.0f, 0.0f, 0.5f);
		
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		//设置坐标
		gl.glViewport(0, 0, width, height);
		//设置投影变换
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		GLU.gluPerspective(gl, 0f, (float)width/(float)height, 0.1f, 100.0f);
		//设定模型视图矩阵
		gl.glLoadIdentity();
		
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		
		
	}
	
}

猜你喜欢

转载自hylxinlang.iteye.com/blog/1884516