- 浏览: 85135 次
- 性别:
- 来自: 张家港
文章分类
最新评论
-
likeMcdonald:
图片还不错
opengl es demo(有附件) -
wangzhigang2:
你用的什么型号的手机?
拦截短信,不让系统发通知 -
larry1030:
模拟器中可以, 真机貌似不行。
拦截短信,不让系统发通知 -
bawanglb:
这个必须顶 ,很好,谢谢
opengl es demo(有附件) -
cs3230524:
楼主怎么解决gles中中文字符的问题?lsl713@live. ...
opengl es demo(有附件)
创建android工程
以下代码有一个activity类 和一些 renderer的渲染类
在附件里有项目工程,这里共享给大家一起研究下
有什么好的提议,欢迎给我留言啊。
activity:
GLRender.java
GLTexRender.java
GLBlendRender.java
GLFogRender.java
GLLightRender.java
以下代码有一个activity类 和一些 renderer的渲染类
在附件里有项目工程,这里共享给大家一起研究下
有什么好的提议,欢迎给我留言啊。
activity:
package com.tracy; import android.app.Activity; import android.graphics.Color; import android.opengl.GLSurfaceView; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.widget.LinearLayout; public class Test extends Activity { /** Called when the activity is first created. */ GLSurfaceView glSurfaceView; GLTexRender glRender; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); glSurfaceView = new GLSurfaceView(this); glRender = new GLTexRender(this); glSurfaceView.setRenderer(glRender); // Log.i("tracy", "glSurfaceView"+glSurfaceView.getTop()+" "+glSurfaceView.getWidth()+" "+glSurfaceView.getHeight()); LinearLayout ll = new LinearLayout(this); ll.addView(glSurfaceView); ll.setBackgroundColor(Color.WHITE); setContentView(ll); Log.i("tracy", "glSurfaceView"+glSurfaceView.getTop()+" "+glSurfaceView.getWidth()+" "+glSurfaceView.getHeight()); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); glSurfaceView.onPause(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); glSurfaceView.onResume(); } // @Override // public boolean onKeyDown(int keyCode, KeyEvent event) { // Log.i("tracy", "onKeyDown"); // switch(keyCode){ // // case KeyEvent.KEYCODE_DPAD_LEFT: // glRender.yflag=-1; // glRender.key=true; // glRender.leftOrRight=true; // glRender.upOrDown=false; // break; // case KeyEvent.KEYCODE_DPAD_RIGHT: // glRender.yflag=1; // glRender.key=true; // glRender.leftOrRight=true; // glRender.upOrDown=false; // break; // case KeyEvent.KEYCODE_DPAD_UP: // glRender.xflag=-1; // glRender.key=true; // glRender.leftOrRight=false; // glRender.upOrDown=true; // break; // case KeyEvent.KEYCODE_DPAD_DOWN: // glRender.xflag=1; // glRender.key=true; // glRender.leftOrRight=false; // glRender.upOrDown=true; // break; // case KeyEvent.KEYCODE_DPAD_CENTER: // Log.i("tracy", "KEYCODE_DPAD_CENTER"); // if(glRender.onOrOffLight){ // glRender.onOrOffLight=false; // }else{ // glRender.onOrOffLight=true; // } // glRender.fogMode(); // break; // } // return super.onKeyDown(keyCode, event); // } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { Log.i("tracy", "onKeyUp"); // glRender.key=false; return super.onKeyUp(keyCode, event); } }
GLRender.java
package com.tracy; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.opengl.GLSurfaceView.Renderer; import android.util.Log; public class GLRender implements Renderer { public GLRender(Context context) { bm[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon); // TODO Auto-generated constructor stub } private static final String tag = "tracy"; private int one = 0x10000; // 三角形旋转角度 // private float rotateTri = 0.2f; private int[] a = { 0, 40000, 0, 0, 0, 0, 60000, 0, 0 }; // 三角形三个顶点 // private IntBuffer triggerBuffer = IntBuffer.wrap(a); // private IntBuffer texBuffer = IntBuffer.wrap(new int[] { 0, 40000, 0, 0, // 60000, 0 }); int[] tex={0, 0, 1, 0, 0, 1,1,1 }; private int[] b = { one, 0, 0, one, 0, one, 0, one, 0, 0, one, one }; private IntBuffer colorBuffer = IntBuffer.wrap(b); @Override public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glColor4f(1, 0, 0, 0); gl.glLoadIdentity(); gl.glTranslatef(-0.5f, 0.0f, -1.0f); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); // rotateTri+=0.5f; // gl.glRotatef(rotateTri, 0, 1, 0); gl.glColorPointer(4, GL10.GL_FIXED, 0, colorBuffer); gl.glVertexPointer(3, GL10.GL_FIXED, 0, getNativeIntBuffer(a)); gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, getNativeIntBuffer(tex)); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { // TODO Auto-generated method stub Log.i(tag, "onSurfaceChanged"); float ratio = (float) width / height; // 设置OpenGL场景的大小 gl.glViewport(0, 0, width, height); // 设置投影矩阵 gl.glMatrixMode(GL10.GL_PROJECTION); // 重置投影矩阵 gl.glLoadIdentity(); // 设置视口的大小 gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); // 选择模型观察矩阵 gl.glMatrixMode(GL10.GL_MODELVIEW); // 重置模型观察矩阵 gl.glLoadIdentity(); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { // TODO Auto-generated method stub Log.i(tag, "onSurfaceCreated"); // 启用阴影平滑 gl.glShadeModel(GL10.GL_SMOOTH); // // 黑色背景 gl.glClearColor(0, 0, 0, 0); // // 设置深度缓存 gl.glClearDepthf(1.0f); // 启用深度测试 gl.glEnable(GL10.GL_DEPTH_TEST); // 所作深度测试的类型 gl.glDepthFunc(GL10.GL_LEQUAL); // // 告诉系统对透视进行修正 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); // 允许2D贴图,纹理 gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnable(GL10.GL_CULL_FACE); IntBuffer intBuffer = IntBuffer.allocate(1); gl.glGenTextures(1, intBuffer); texture = intBuffer.array(); // 设置要使用的纹理 gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[0], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); } int[] texture; Bitmap[] bm = new Bitmap[5]; private IntBuffer getNativeIntBuffer(int[] buffer) { ByteBuffer ibb = ByteBuffer.allocateDirect(buffer.length * 4); ibb.order(ByteOrder.nativeOrder()); IntBuffer ibf = ibb.asIntBuffer(); ibf.put(buffer); ibf.position(0); return ibf; } }
GLTexRender.java
package com.tracy; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.opengl.GLSurfaceView.Renderer; public class GLTexRender implements Renderer { Bitmap[] bm = new Bitmap[6]; float rotx=0.2f; float roty=0.2f; float rotz=0.2f; public GLTexRender(Context context) { super(); bm[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.a); bm[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b); bm[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.c); bm[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.d); bm[4] = BitmapFactory.decodeResource(context.getResources(), R.drawable.e); bm[5] = BitmapFactory.decodeResource(context.getResources(), R.drawable.f); } int one = 0x10000; private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{ // FRONT -one, -one, one, one, -one, one, -one, one, one, one, one, one, // BACK -one, -one, -one, -one, one, -one, one, -one, -one, one, one, -one, // LEFT -one, -one, one, -one, one, one, -one, -one, -one, -one, one, -one, // RIGHT one, -one, -one, one, one, -one, one, -one, one, one, one, one, // TOP -one, one, one, one, one, one, -one, one, -one, one, one, -one, // BOTTOM -one, -one, one, -one, -one, -one, one, -one, one, one, -one, -one, }); IntBuffer texCoords=IntBuffer.wrap(new int[]{ 0,one,one,one,0,0,one,0, one,one,one,0,0,one,0,0, one,one,one,0,0,one,0,0, one,one,one,0,0,one,0,0, one,0,0,0,one,one,0,one, 0,0,0,one,one,0,one,one, }); @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); gl.glRotatef(rotx, 1, 0, 0); gl.glRotatef(roty, 0, 1, 0); gl.glRotatef(rotz, 0, 0, 1); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FIXED, 0, quaterBuffer); gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords); this.bindTexturePic(gl); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); rotx+=0.5f; roty+=0.5f; rotz+=0.5f; } //指定纹理图片 private void bindTexturePic(GL10 gl){ gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); // gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); // gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); // gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); // gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); // gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); // gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { float ratio = (float) width / height; //设置OpenGL场景的大小 gl.glViewport(0, 0, width, height); //设置投影矩阵 gl.glMatrixMode(GL10.GL_PROJECTION); //重置投影矩阵 gl.glLoadIdentity(); // 设置视口的大小 gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); // 选择模型观察矩阵 gl.glMatrixMode(GL10.GL_MODELVIEW); // 重置模型观察矩阵 gl.glLoadIdentity(); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { // 启用阴影平滑 gl.glShadeModel(GL10.GL_SMOOTH); // // 黑色背景 gl.glClearColor(0, 0, 0, 0); // 设置深度缓存 gl.glClearDepthf(1.0f); // 启用深度测试 gl.glEnable(GL10.GL_DEPTH_TEST); // 所作深度测试的类型 gl.glDepthFunc(GL10.GL_LEQUAL); // // 告诉系统对透视进行修正 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); //允许2D贴图,纹理 gl.glEnable(GL10.GL_TEXTURE_2D); // gl.glEnable(GL10.GL_CULL_FACE); toTex(gl); } int[] texture= new int[6]; //纹理映射 private void toTex(GL10 gl){ IntBuffer intBuffer = IntBuffer.allocate(6); gl.glGenTextures(6, intBuffer); texture=intBuffer.array(); // 设置要使用的纹理 gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[0], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[1], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[2], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[3], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[4], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[5], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); } }
GLBlendRender.java
package com.tracy; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.opengl.GLSurfaceView.Renderer; public class GLBlendRender implements Renderer { Bitmap[] bm = new Bitmap[6]; float rotx=0.2f; float roty=0.2f; float rotz=0.2f; public boolean key=true; public GLBlendRender(Context context) { super(); bm[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.a); bm[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b); bm[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.c); bm[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.d); bm[4] = BitmapFactory.decodeResource(context.getResources(), R.drawable.e); bm[5] = BitmapFactory.decodeResource(context.getResources(), R.drawable.f); } int one = 0x10000; private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{ // FRONT -one, -one, one, one, -one, one, -one, one, one, one, one, one, // BACK -one, -one, -one, -one, one, -one, one, -one, -one, one, one, -one, // LEFT -one, -one, one, -one, one, one, -one, -one, -one, -one, one, -one, // RIGHT one, -one, -one, one, one, -one, one, -one, one, one, one, one, // TOP -one, one, one, one, one, one, -one, one, -one, one, one, -one, // BOTTOM -one, -one, one, -one, -one, -one, one, -one, one, one, -one, -one, }); //纹理坐标 IntBuffer texCoords=IntBuffer.wrap(new int[]{ 0,one,one,one,0,0,one,0, one,one,one,0,0,one,0,0, one,one,one,0,0,one,0,0, one,one,one,0,0,one,0,0, one,0,0,0,one,one,0,one, 0,0,0,one,one,0,one,one, }); @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); gl.glRotatef(rotx, 1, 0, 0); gl.glRotatef(roty, 0, 1, 0); gl.glRotatef(rotz, 0, 0, 1); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FIXED, 0, quaterBuffer); gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords); this.bindTexturePic(gl); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); rotx+=0.5f; roty+=0.5f; rotz+=0.5f; //混合开关 if (key) { gl.glEnable(GL10.GL_BLEND); // 打开混合 gl.glDisable(GL10.GL_DEPTH_TEST); // 关闭深度测试 } else { gl.glDisable(GL10.GL_BLEND); // 关闭混合 gl.glEnable(GL10.GL_DEPTH_TEST); // 打开深度测试 } } //指定纹理图片 private void bindTexturePic(GL10 gl){ gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { float ratio = (float) width / height; //设置OpenGL场景的大小 gl.glViewport(0, 0, width, height); //设置投影矩阵 gl.glMatrixMode(GL10.GL_PROJECTION); //重置投影矩阵 gl.glLoadIdentity(); // 设置视口的大小 gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); // 选择模型观察矩阵 gl.glMatrixMode(GL10.GL_MODELVIEW); // 重置模型观察矩阵 gl.glLoadIdentity(); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { // 启用阴影平滑 gl.glShadeModel(GL10.GL_SMOOTH); // // 黑色背景 gl.glClearColor(0, 0, 0, 0); // 设置深度缓存 gl.glClearDepthf(1.0f); // 启用深度测试 gl.glEnable(GL10.GL_DEPTH_TEST); // 所作深度测试的类型 gl.glDepthFunc(GL10.GL_LEQUAL); // // 告诉系统对透视进行修正 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); //设置光线,,1.0f为全光线,a=50% gl.glColor4f(1.0f,1.0f,1.0f,0.5f); // 基于源象素alpha通道值的半透明混合函数 gl.glBlendFunc(GL10.GL_SRC_ALPHA,GL10.GL_ONE); //允许2D贴图,纹理 gl.glEnable(GL10.GL_TEXTURE_2D); // gl.glEnable(GL10.GL_CULL_FACE); toTex(gl); } int[] texture= new int[6]; //纹理映射 private void toTex(GL10 gl){ IntBuffer intBuffer = IntBuffer.allocate(6); gl.glGenTextures(6, intBuffer); texture=intBuffer.array(); // 设置要使用的纹理 gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[0], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[1], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[2], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[3], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[4], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[5], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); } public void OnKeyDown(){ if(key){ key=false; }else{ key=true; } } }
GLFogRender.java
package com.tracy; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.opengl.GLSurfaceView.Renderer; import android.util.Log; public class GLFogRender implements Renderer { Bitmap[] bm = new Bitmap[6]; float rotx = 0.2f; float roty = 0.2f; float rotz = 0.2f; public int xflag = 1; public int yflag = 1; public boolean leftOrRight = false; public boolean upOrDown = false; public boolean key = false; // public float pz; public GLFogRender(Context context) { super(); bm[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.a); bm[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b); bm[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.c); bm[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.d); bm[4] = BitmapFactory.decodeResource(context.getResources(), R.drawable.e); bm[5] = BitmapFactory.decodeResource(context.getResources(), R.drawable.f); } int one = 0x10000; private IntBuffer quaterBuffer = IntBuffer .wrap(new int[] { // FRONT -one, -one, one, one, -one, one, -one, one, one, one, one, one, // BACK -one, -one, -one, -one, one, -one, one, -one, -one, one, one, -one, // LEFT -one, -one, one, -one, one, one, -one, -one, -one, -one, one, -one, // RIGHT one, -one, -one, one, one, -one, one, -one, one, one, one, one, // TOP -one, one, one, one, one, one, -one, one, -one, one, one, -one, // BOTTOM -one, -one, one, -one, -one, -one, one, -one, one, one, -one, -one, }); IntBuffer texCoords = IntBuffer.wrap(new int[] { 0, one, one, one, 0, 0, one, 0, one, one, one, 0, 0, one, 0, 0, one, one, one, 0, 0, one, 0, 0, one, one, one, 0, 0, one, 0, 0, one, 0, 0, 0, one, one, 0, one, 0, 0, 0, one, one, 0, one, one, }); // 定义环境光源数组 float[] lightAmbient = { 0.5f, 0.5f, 0.5f, 1.0f }; // 定义漫射光源数组 float[] lightDiffuse = { 1.0f, 1.0f, 0.5f, 1.0f }; // 光源位置 float[] lightPosition = { 0.0f, 0.0f, 2.0f, 1.0f }; float fogColor[] = { 0.8f, 0.2f, 0.2f, 1.0f }; // 雾的颜色设为白色 int fogMode[] = { GL10.GL_EXP, GL10.GL_EXP2, GL10.GL_LINEAR }; // 雾气的模式 int fogfilter = 0; // 使用哪一种雾气 GL10 mGl10; public void fogMode() { Log.i("tracy", "fogfilter="+fogfilter); mGl10.glFogf(GL10.GL_FOG_MODE, fogMode[fogfilter++]); // 设置雾气的模式 fogfilter = fogfilter > 2 ? 0 : fogfilter; } @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); // 如果不启用GL_LIGHTING光就什么都看不见 gl.glEnable(GL10.GL_LIGHTING); // gl.glRotatef(rotz, 0, 0, 1); gl.glRotatef(roty, 0, 1, 0); gl.glRotatef(rotx, 1, 0, 0); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FIXED, 0, quaterBuffer); gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords); this.bindTexturePic(gl); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); if (key) { if (upOrDown) { rotx += 0.5f * xflag; } if (leftOrRight) { roty += 0.5f * yflag; } // rotz+=0.5f; } if (onOrOffLight) { gl.glEnable(GL10.GL_LIGHT1); } else { gl.glDisable(GL10.GL_LIGHT1); } } // 指定纹理图片 private void bindTexturePic(GL10 gl) { gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { float ratio = (float) width / height; // 设置OpenGL场景的大小 gl.glViewport(0, 0, width, height); // 设置投影矩阵 gl.glMatrixMode(GL10.GL_PROJECTION); // 重置投影矩阵 gl.glLoadIdentity(); // 设置视口的大小 gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); // 选择模型观察矩阵 gl.glMatrixMode(GL10.GL_MODELVIEW); // 重置模型观察矩阵 gl.glLoadIdentity(); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { mGl10 = gl; // 启用阴影平滑 gl.glShadeModel(GL10.GL_SMOOTH); // // 设置背景的颜色为雾气的颜色 gl.glClearColor(0.8f,0.2f,0.2f,1.0f); gl.glFogx(GL10.GL_FOG_MODE, fogMode[fogfilter]); // 设置雾气的模式 gl.glFogfv(GL10.GL_FOG_COLOR, fogColor,0); // 设置雾的颜色 gl.glFogf(GL10.GL_FOG_DENSITY, 0.35f); // 设置雾的密度 gl.glHint(GL10.GL_FOG_HINT, GL10.GL_DONT_CARE); // 设置系统如何计算雾气 gl.glFogf(GL10.GL_FOG_START, 1.0f); // 雾气的开始位置 gl.glFogf(GL10.GL_FOG_END, 5.0f); // 雾气的结束位置 gl.glEnable(GL10.GL_FOG); // 使用雾气 // 设置深度缓存 gl.glClearDepthf(1.0f); // 启用深度测试 gl.glEnable(GL10.GL_DEPTH_TEST); // 所作深度测试的类型 gl.glDepthFunc(GL10.GL_LEQUAL); // // 告诉系统对透视进行修正 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); // 允许2D贴图,纹理 gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnable(GL10.GL_CULL_FACE); toTex(gl); initLight(gl); } // 初始化光源 private void initLight(GL10 gl) { // 设置环境光 gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_AMBIENT, getNativeBuffer(lightAmbient)); // set diffuse light gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, getNativeBuffer(lightDiffuse)); // set light position gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, getNativeBuffer(lightPosition)); } public boolean onOrOffLight = true; int[] texture = new int[6]; // 纹理映射 private void toTex(GL10 gl) { IntBuffer intBuffer = IntBuffer.allocate(6); gl.glGenTextures(6, intBuffer); texture = intBuffer.array(); // 设置要使用的纹理 gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[0], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[1], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[2], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[3], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[4], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[5], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); } private FloatBuffer getNativeBuffer(float[] buffer) { ByteBuffer ibb = ByteBuffer.allocateDirect(buffer.length * 8); ibb.order(ByteOrder.nativeOrder()); FloatBuffer fb = ibb.asFloatBuffer(); fb.put(buffer); fb.position(0); return fb; } }
GLLightRender.java
package com.tracy; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.opengl.GLSurfaceView.Renderer; public class GLLightRender implements Renderer { Bitmap[] bm = new Bitmap[6]; float rotx=0.2f; float roty=0.2f; float rotz=0.2f; public int xflag=1; public int yflag=1; public boolean leftOrRight=false; public boolean upOrDown=false; public boolean key=false; // public float pz; public GLLightRender(Context context) { super(); bm[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.a); bm[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b); bm[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.c); bm[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.d); bm[4] = BitmapFactory.decodeResource(context.getResources(), R.drawable.e); bm[5] = BitmapFactory.decodeResource(context.getResources(), R.drawable.f); } int one = 0x10000; private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{ // FRONT -one, -one, one, one, -one, one, -one, one, one, one, one, one, // BACK -one, -one, -one, -one, one, -one, one, -one, -one, one, one, -one, // LEFT -one, -one, one, -one, one, one, -one, -one, -one, -one, one, -one, // RIGHT one, -one, -one, one, one, -one, one, -one, one, one, one, one, // TOP -one, one, one, one, one, one, -one, one, -one, one, one, -one, // BOTTOM -one, -one, one, -one, -one, -one, one, -one, one, one, -one, -one, }); IntBuffer texCoords=IntBuffer.wrap(new int[]{ 0,one,one,one,0,0,one,0, one,one,one,0,0,one,0,0, one,one,one,0,0,one,0,0, one,one,one,0,0,one,0,0, one,0,0,0,one,one,0,one, 0,0,0,one,one,0,one,one, }); //定义环境光源数组 float[] lightAmbient={0.5f,0.5f,0.5f,1.0f}; //定义漫射光源数组 float[] lightDiffuse={1.0f,1.0f,0.5f,1.0f}; //光源位置 float[] lightPosition={0.0f,0.0f,2.0f,1.0f}; @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); //如果不启用GL_LIGHTING光就什么都看不见 gl.glEnable(GL10.GL_LIGHTING); // gl.glRotatef(rotz, 0, 0, 1); gl.glRotatef(roty, 0, 1, 0); gl.glRotatef(rotx, 1, 0, 0); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FIXED, 0, quaterBuffer); gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords); this.bindTexturePic(gl); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); if(key){ if(upOrDown){ rotx+=0.5f*xflag; } if(leftOrRight){ roty+=0.5f*yflag; } // rotz+=0.5f; } if(onOrOffLight){ gl.glEnable(GL10.GL_LIGHT1); }else{ gl.glDisable(GL10.GL_LIGHT1); } } //指定纹理图片 private void bindTexturePic(GL10 gl){ gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { float ratio = (float) width / height; //设置OpenGL场景的大小 gl.glViewport(0, 0, width, height); //设置投影矩阵 gl.glMatrixMode(GL10.GL_PROJECTION); //重置投影矩阵 gl.glLoadIdentity(); // 设置视口的大小 gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); // 选择模型观察矩阵 gl.glMatrixMode(GL10.GL_MODELVIEW); // 重置模型观察矩阵 gl.glLoadIdentity(); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { // 启用阴影平滑 gl.glShadeModel(GL10.GL_SMOOTH); // // 黑色背景 gl.glClearColor(0, 0, 0, 0); // 设置深度缓存 gl.glClearDepthf(1.0f); // 启用深度测试 gl.glEnable(GL10.GL_DEPTH_TEST); // 所作深度测试的类型 gl.glDepthFunc(GL10.GL_LEQUAL); // // 告诉系统对透视进行修正 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); //允许2D贴图,纹理 gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnable(GL10.GL_CULL_FACE); toTex(gl); initLight(gl); } //初始化光源 private void initLight(GL10 gl){ //设置环境光 gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_AMBIENT, getNativeBuffer(lightAmbient)); //set diffuse light gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, getNativeBuffer(lightDiffuse)); //set light position gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, getNativeBuffer(lightPosition)); } public boolean onOrOffLight=true; int[] texture= new int[6]; //纹理映射 private void toTex(GL10 gl){ IntBuffer intBuffer = IntBuffer.allocate(6); gl.glGenTextures(6, intBuffer); texture=intBuffer.array(); // 设置要使用的纹理 gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[0], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[1], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[2], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[3], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[4], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bm[5], 0); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); } private FloatBuffer getNativeBuffer(float[] buffer){ ByteBuffer ibb = ByteBuffer.allocateDirect(buffer.length * 8); ibb.order(ByteOrder.nativeOrder()); FloatBuffer fb =ibb.asFloatBuffer(); fb.put(buffer); fb.position(0); return fb; } }
- GLTest.zip (5.1 MB)
- 下载次数: 595
评论
3 楼
likeMcdonald
2014-05-19
图片还不错
2 楼
bawanglb
2011-10-13
这个必须顶 ,很好,谢谢
1 楼
cs3230524
2011-08-30
楼主怎么解决gles中中文字符的问题?
lsl713@live.cn
lsl713@live.cn
相关推荐
使用OpenGL ES模拟器在Windows上开发OpenGL ES程序。。
最后,学习OpenGL ES是很有价值的,它能让你掌握底层图形编程,为创建高性能的游戏和图形应用提供基础。不过,对于初学者来说,可能需要花费一些时间去理解和实践,尤其是着色器编程和状态管理。 总结来说,这个...
很好用的特好用超好用OpenGL ES 1.0 Demo
在Android平台上,OpenGL ES(Open Graphics Library for Embedded Systems)是一种广泛使用的图形库,用于在移动设备上绘制2D和3D图像。...通过这个OpenGLES demo,你将有机会亲手实践并理解这一重要特性。
通过这个demo,初学者可以学习到如何在Android上设置openGLES环境,理解基本的3D图形绘制流程,以及如何使用着色器来实现不同的视觉效果。通过逐步分析和修改代码,可以提升对openGLES的理解和应用能力。
【基于QT的OPENGL ES代码纹理DEMO】是一个示例项目,它展示了如何在QT框架下使用OpenGL ES来处理纹理。OpenGL ES(Embedded Systems)是OpenGL的一个子集,专为嵌入式设备如智能手机、平板电脑等设计,提供2D和3D...
【OpenGLES demo - 3. 建立Android工程】是关于在Android平台上构建一个使用OpenGL ES(OpenGL for Embedded Systems)的示例项目。OpenGL ES是针对嵌入式设备,如智能手机和平板电脑,设计的一个2D和3D图形处理库。...
通过这个OpenGL ES 2.0入门demo,你可以学习如何设置和使用着色器,以及理解图形渲染的基本流程。实践这些概念可以帮助你逐步掌握OpenGL,并能创建更复杂的3D场景。同时,对移动平台的图形性能优化和资源管理也是...
这个"OpenGLES demo - 16. 蒙板 Stencil"的示例可能包含了如何设置和使用模板缓冲的具体代码和步骤,是初学者学习OpenGLES蒙板功能的好资源。通过分析和运行这个示例,你可以更好地理解模板缓冲在实际场景中的应用,...
在提供的"OpenGLES demo - 9. 矩阵变换"压缩包中,你将找到一个实际的OpenGLES项目,其中包含展示了如何在代码中应用上述矩阵变换的示例。这个示例可能包括创建顶点数组、设置模型视图投影矩阵、应用矩阵变换以及...
- 在提供的"OpenGLES demo - 13. Framebuffer FBO"中,你将看到如何创建和使用FBO的示例代码。通过分析这个例子,你可以更深入地理解FBO的工作原理和使用方法。 总之,理解并掌握FBO对于提升OpenGLES应用的图形...
在OpenGLES编程中,材质贴图(Texture Mapping)是一项重要的技术,用于为3D模型增添真实感和细节。在本教程中,我们将深入探讨如何在iOS设备上使用OpenGLES实现这一功能。OpenGLES是OpenGL的一个轻量级版本,专为...
本Demo是在Android Studio上使用OpenGLES画一个立方体,有较详细的注释说明.
在"opengles3-book-master"这个压缩包中,很可能包含了以上提到的各个特性的示例代码,通过这些示例,你可以实际操作并理解每个特性的工作原理。学习这些Demo,不仅能提升你的OpenGL ES 3.0编程能力,还能为开发高...
在这个"小行星展示全景图demo"中,我们将探讨如何使用OpenGL ES 2.0来创建一个能够显示全景图像的场景,模拟一个小行星的表面,并提供互动体验。 全景图是一种360度全方位的图像,可以用来构建沉浸式的视觉体验。在...
本"ios下opengl小demo"旨在帮助开发者熟悉如何在iOS环境中集成和使用OpenGL进行图形渲染。 在iOS开发中,OpenGL ES通常通过`GLKit`或`Metal`框架进行封装,简化了与硬件交互的过程。然而,直接使用OpenGL ES可以...
OpenGL es2.0 小行星展示全景图demo.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
它通常与OpenGL ES不直接交互,但在构建例如3D地理信息系统或可视化应用时,可能会利用Elasticsearch来检索和组织数据,然后通过OpenGL ES进行呈现。 总的来说,OpenGL ES 3.0编程指南涵盖了移动和嵌入式设备图形...
个人opengles demo中第二篇的shader部分的代码