<<Android.游戏开发入门](美)Mario.Zechner>>读书笔记-----OpenGL ES概览
2012-06-05 22:01
711 查看
<<Android.游戏开发入门>>
CHAPTER 7: OpenGL ES: A Gentle Introduction
This means that the memory is
not allocated in the virtual machine’s heap memory, but in native heap memory.
NIO直接从本地堆内存分配 ,而不是VM 堆内存
float[] vertices = { ... definitions of vertex positions etc ...;//定义顶点
floatBuffer.clear();//重置buffer sets the position to zero and the limit to the capacity.
floatBuffer.put(vertices);//把顶点数据存入buffer
floatBuffer.flip();//切换模式 从写入模式进入读出模式 just swaps the position and limit.
we can only access OpenGL ES on the rendering
thread.
http://insanitydesign.com/wp/projects/nehe-android-ports/
2012-6-5
NOTE: While this method looks like it sets up a 2D coordinate system for us to render to, it
actually does not. It only defines the portion of the framebuffer OpenGL ES uses to output the
final image. Our coordinate system is defined via the projection and model-view matrices.
GL10.glViewport(int x, int y, int width, int height) 看起来像设置显示,其实不是
opengl es 追踪三个矩阵:projection matrix ,model-view matrix,texture matrix
在操作他们的数据前,先要告诉openglES 要操作哪个,使用:
GL10.glMatrixMode(int mode)
mode: 可选值 GL10.GL_PROJECTION, GL10.GL_MODELVIEW, or
GL10.GL_TEXTURE.
This matrix mode is one of OpenGL ES’s states (which will get lost when we
lose the context if our application is paused and resumed)
矩阵模式是opengl es的状态之一(会随应用程序状态变化发生丢失)
gl.glClearColor(0,0,0,1);//用RGBA颜色清除屏幕
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);//执行清除
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
gl.glMatrixMode(GL10.GL_PROJECTION);//设置matrix mode
gl.glLoadIdentity();//恢复单位矩阵
gl.glOrthof(0, 320, 0, 480, 1, -1);//projection matrix produced by glOrthof()
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);//要绘制顶点位置了
gl.glVertexPointer( 2, GL10.GL_FLOAT, 0, vertices);//一旦执行,顶点信息被存储供后续使用
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
CHAPTER 7: OpenGL ES: A Gentle Introduction
This means that the memory is
not allocated in the virtual machine’s heap memory, but in native heap memory.
NIO直接从本地堆内存分配 ,而不是VM 堆内存
float[] vertices = { ... definitions of vertex positions etc ...;//定义顶点
floatBuffer.clear();//重置buffer sets the position to zero and the limit to the capacity.
floatBuffer.put(vertices);//把顶点数据存入buffer
floatBuffer.flip();//切换模式 从写入模式进入读出模式 just swaps the position and limit.
we can only access OpenGL ES on the rendering
thread.
http://insanitydesign.com/wp/projects/nehe-android-ports/
2012-6-5
NOTE: While this method looks like it sets up a 2D coordinate system for us to render to, it
actually does not. It only defines the portion of the framebuffer OpenGL ES uses to output the
final image. Our coordinate system is defined via the projection and model-view matrices.
GL10.glViewport(int x, int y, int width, int height) 看起来像设置显示,其实不是
opengl es 追踪三个矩阵:projection matrix ,model-view matrix,texture matrix
在操作他们的数据前,先要告诉openglES 要操作哪个,使用:
GL10.glMatrixMode(int mode)
mode: 可选值 GL10.GL_PROJECTION, GL10.GL_MODELVIEW, or
GL10.GL_TEXTURE.
This matrix mode is one of OpenGL ES’s states (which will get lost when we
lose the context if our application is paused and resumed)
矩阵模式是opengl es的状态之一(会随应用程序状态变化发生丢失)
gl.glClearColor(0,0,0,1);//用RGBA颜色清除屏幕
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);//执行清除
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
gl.glMatrixMode(GL10.GL_PROJECTION);//设置matrix mode
gl.glLoadIdentity();//恢复单位矩阵
gl.glOrthof(0, 320, 0, 480, 1, -1);//projection matrix produced by glOrthof()
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);//要绘制顶点位置了
gl.glVertexPointer( 2, GL10.GL_FLOAT, 0, vertices);//一旦执行,顶点信息被存储供后续使用
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
package com.test.opengles; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.Random; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.app.Activity; import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView.Renderer; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.view.WindowManager; /** * OpenGL ES 绘制三角形测试 * 按照作者所说,不要直接复制粘贴代码了事,要明白每一步在做什么,也不辜负作者用六页详细通俗苦心的解释了:) * " * Now compare that to the six pages it took me to explain this to you. I * could have of course left out the details and used coarser language. The problem is that * OpenGL ES is a pretty complex beast at times, and to avoid getting an empty screen, it’s * best to learn what it is all about rather than just copying and pasting code. * " * @author Administrator * */ public class MainActivity extends Activity { GLSurfaceView glView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); glView = new GLSurfaceView(this); glView.setRenderer(new SimpleRenderer()); setContentView(glView); } @Override public void onResume() { super.onPause(); glView.onResume(); } @Override public void onPause() { super.onPause(); glView.onPause(); } /** * render * @author Administrator * */ private class SimpleRenderer implements Renderer { Random rand = new Random(); @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { Log.d("GLSurfaceViewTest", "surface created"); gl.glViewport(0, 0, glView.getWidth(), glView.getHeight()); gl.glMatrixMode(GL10.GL_PROJECTION);//设置要操作的matrix mode gl.glLoadIdentity();//单位矩阵 gl.glOrthof(0, 320, 0, 480, 1, -1);//设置projection /** * 依赖NIO ByteBuffer来从本地堆分配内存 */ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(3 * 2 * 4);//或最好写成float[].length*4 byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer vertices = byteBuffer.asFloatBuffer(); vertices.put(new float[] { 0.0f, 0.0f, 319.0f, 0.0f, 160.0f, 479.0f }); vertices.flip();//buffer模式切换,由写变成读 gl.glColor4f(1, 0, 0, 1);//设置RGBA颜色 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glVertexPointer( 2, GL10.GL_FLOAT, 0, vertices); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { Log.d("GLSurfaceViewTest", "surface changed: " + width + "x" + height); } private long start; @Override public void onDrawFrame(GL10 gl) { /** * The 10 in GL10 * indicates that it offers us all the functions defined in * the OpenGL ES 1.0 standard. * OpenGL ES 1.0标准 */ gl.glClearColor(0,0,0,1); gl.glClear(GL10.GL_COLOR_BUFFER_BIT);//和setViewPort间无先后关系 gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3); } } }
相关文章推荐
- <Android入门笔记>第一章 搭建Android开发环境
- <转载>IT痴汉的工作现状21-Android开发前景论
- <Android>入门的一点知识
- <杂谈1001> 一种Android手机开发架构
- <<3D数学基础:图形与游戏开发>>读后感
- <为知更新>Android内核驱动开发中的Kconfig文件结构分析(图文)
- Android开发工具——ADB(Android Debug Bridge) <一>概览
- Android游戏开发指南<一>背景地图
- 用人类的思维方式去写更容易维护的代码——用<抽象-基础-逻辑>模式开发Java(Android)程序
- <Android>在android开发中实现一行文字流动
- <Android开发代码库>achartengine实现柱状图、圆饼图、线图等
- Android开发工具——ADB(Android Debug Bridge) <一>概览
- <Android>游戏中简单的WebView公告适配
- android_应用开发之(使用<include>标签重用布局)
- <转>Android开发:用Drawable XML绘制带阴影效果的圆形按钮
- <Android开发代码库>achartengine实现柱状图、圆饼图、线图等
- Android UI 优化 使用<include/>和 <merge />标签
- <转载>Android ListView 美化 去阴影 底色 选中色 间隙线
- AndroidManifest.xml中的<uses-feature/>以及和<uses-permission/>之间的联系
- <Android诀窍> Layouts与Views