转载:http://blog.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/
I'm going to write a couple of tutorials on using OpenGL ES on Android phones. The theory of OpenGL ES is the same on different devices so it should be quite easy to convert them to another platform.
I can't always remember where I found particular info so I might not always be able to give you the right reference. If you feel that I have borrowed stuff from you but have forgotten to add you as a reference, please e-mail me.
In the code examples I will have two different links for each function. The actual function will be linked to the android documentation and after that I will also link the OpenGL documentations. Like this:
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // OpenGL docs.
So, let's start.
In this tutorial I will show you how to set up your OpenGL ES view that’s always a good place to start.
Setting up an OpenGL ES View
Setting up a OpenGL view has never been hard and on Android it is still easy. There really are only two things you need to get started.
GLSurfaceView
GLSurfaceView is a API class in Android 1.5 that helps you write OpenGL ES applications.
-
Providing the glue code to connect OpenGL ES to the View system.
-
Providing the glue code to make OpenGL ES work with the Activity life-cycle.
-
Making it easy to choose an appropriate frame buffer pixel format.
-
Creating and managing a separate rendering thread to enable smooth animation.
-
Providing easy-to-use debugging tools for tracing OpenGL ES API calls and checking for errors.
If you want to get going fast with your OpenGL ES application this is where you should start.
The only function you need to call on is:
public void setRenderer(GLSurfaceView.Renderer renderer)
Read more at:GLSurfaceView
GLSurfaceView.Renderer
GLSurfaceView.Renderer is a generic render interface. In your implementation of this renderer you should put all your calls to render a frame.
There are three functions to implement:
onSurfaceCreated
Here it's a good thing to setup things that you don't change so often in the rendering cycle. Stuff like what color to clear the screen with, enabling z-buffer and so on.
onDrawFrame
Here is where the actual drawing take place.
onSurfaceChanged
If your device supports flipping between landscape and portrait you will get a call to this function when it happens. What you do here is setting upp the new ratio.
Read more at:GLSurfaceView.Renderer
Putting it together
First we create our activity, we keep it clean and simple.
Our renderer takes little bit more work to setup, look at it and I will explain the code a bit more.
Fullscreen
Just add this lines in the OpenGLDemo class and you will get fullscreen.
This is pretty much all you need to get your view up and running. If you compile and run it you will see a nice black screen.
References
The info used in this tutorial is collected from:
Android
Developers
OpenGL
ES 1.1 Reference Pages
You can download the source for this tutorial here:Tutorial_Part_I.zip
You can also checkout the code from:code.google.com
Next tutorial:OpenGL
ES Tutorial for Android – Part II – Building a polygon
分享到:
相关推荐
OpenGL ES Tutorial for Android – Part I – Setting up the view OpenGL ES Tutorial for Android – Part II – Building a polygon OpenGL ES Tutorial for Android – Part III – Transformations OpenGL ES ...
Android开发之OpenGL ES教程 OpenGL ES Tutorial for Android 教程(英文)和源代码。
This is a presentation file from AMD's Game developer's forum. It describes briefly the extension feature set in OpenGL ES 1.0 and new features introduced in OpenGL 2.0.
OpenGL was back when 3Dfx released their Hardware accelerated OpenGL driver for the Voodoo 1 card. Immediately I knew OpenGL was something I had to learn. Unfortunately, it was very hard to find any ...
OpenGL Superbible Comprehensive Tutorial and Reference(7th) 英文无水印pdf 第7版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本...
OpenGL SuperBible Comprehensive Tutorial and Reference, 7th Edition - 2015
OpenGL官方tutorial测试源代码,适合新手入门OpenGL
My goal in this tutorial is to set up, step-by-step, how to initialize an OpenGL rendering context inside of an MFC control such as a picture control, as well as basic functionality to draw based on a...
1. OpenGL 2. Graphics Theory 3. OpenGL ES Tutorial 4. iPhone OpenGL ES 5. Resources 6. Questions
Part of the OpenGL Technical Library–The official knowledge resource for OpenGL developers The OpenGL Technical Library provides tutorial and reference books for OpenGL. The Library enables ...
set up openGL window based on MFC
Nehe OpenGL Tutorial 中文版(附源码).rar
I strongly recommend that you pick up the following books for your 3D knowledge: Real-Time Rendering (Moller/Haines), The OpenGL Programming Guide, 3D Games: Real-Time Rendering and Software ...
iPhone-OpenGL-ES-Tutorial-Series-master iphone opengl es 源码
The OpenGL Geometry Shader Tutorial from Oregon State University,it's cool...
01 2D Animation Tutorial - Setting Up Flash.srt
openGL-RPi-tutorial, 在 树莓派 中使用openGL的介绍 openGLES 2.0 树莓派 教程安装必要的工具:sudo apt-get install git cmake libglm-dev克隆存储库:git clone https://github.com/
Tutorial on OpenCV for Android Setup
Nehe 的入门级别 OpenGL 教程,深入浅出,实践性强,具有很高的学习价值
NeHe OpenGL Tutorial(包含英文版,中文翻译,代码code)