我看到一篇很有用的资源 :
关于 android opengl es--纹理映射,光照
import zhou.ne.he.four.FourRend;  
import zhou.ne.he.one.OneRend;  
import zhou.ne.he.thri.ThriRend;  
import zhou.ne.he.two.TwoRend;  
import android.app.Activity;  
import android.opengl.GLSurfaceView;  
import android.os.Bundle;  
import android.view.KeyEvent;  
import android.view.MotionEvent;  
  
public class Run extends Activity {  
  
 private GLSurfaceView gl_view = null;  
 private GLSurfaceView.Renderer gl_rend = null;  
 private float mPreviousX;  
 private float mPreviousY;  
  
 public void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);  
  gl_view = new GLSurfaceView(this);  
//  gl_rend = new FourRend(this.getApplicationContext());  
//  gl_rend = new OneRend();  
//  gl_rend = new TwoRend();  
  gl_rend = new ThriRend(this.getApplicationContext());  
  gl_view.setRenderer(gl_rend);  
  setContentView(gl_view);  
 }  
  
 public boolean onKeyUp(int keyCode, KeyEvent event) {  
  ((ThriRend) gl_rend).onKeyUp(keyCode, event);  
  return false;  
 }  
  
 public boolean onTouchEvent(MotionEvent event) {  
  float x = event.getX();  
  float y = event.getY();  
  if (event.getAction() == event.ACTION_MOVE) {  
   ((ThriRend) gl_rend).rato += (x - mPreviousX) * 0.5f;  
  }  
  mPreviousX = x;  
  mPreviousY = y;  
  return super.onTouchEvent(event);  
 }  
  
 protected void onResume() {  
  super.onResume();  
  gl_view.onResume();  
 }  
  
 protected void onPause() {  
  super.onPause();  
  gl_view.onPause();  
 }  
}  
  
import javax.microedition.khronos.egl.EGLConfig;  
import javax.microedition.khronos.opengles.GL10;  
  
import android.opengl.GLSurfaceView.Renderer;  
  
public class BaseRend implements Renderer {  
   
 public float rato = 0.0f;  
  
 public void onDrawFrame(GL10 gl) {  
           gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);  
           gl.glMatrixMode(GL10.GL_MODELVIEW);  
           gl.glLoadIdentity();  
 }  
  
 public void onSurfaceChanged(GL10 gl, int width, int height) {  
           if(height == 0){  
            height = 1;  
           }  
           float ratio = (float)width / (float)height;  
           gl.glViewport(0, 0, width, height);  
           gl.glMatrixMode(GL10.GL_PROJECTION);  
           gl.glLoadIdentity();  
           gl.glFrustumf(-ratio, ratio, -1, 1, 1.0f, 10.0f);  
           gl.glMatrixMode(GL10.GL_MODELVIEW);  
           gl.glLoadIdentity();  
 }  
  
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {  
                 gl.glDisable(GL10.GL_DITHER);  
//                 gl.glEnable(GL10.GL_CULL_FACE);  
                 gl.glShadeModel(GL10.GL_SMOOTH);  
                 gl.glClearColor(0, 0, 0, 0.5f);  
                 gl.glClearDepthf(1.0f);  
                 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);  
 }  
  
}  
  
import java.nio.IntBuffer;  
  
import javax.microedition.khronos.egl.EGLConfig;  
import javax.microedition.khronos.opengles.GL10;  
  
import zhou.ne.he.BaseRend;  
import zhou.ne.he.Cube;  
import zhou.ne.he.R;  
import android.content.Context;  
import android.graphics.Bitmap;  
import android.graphics.BitmapFactory;  
import android.opengl.GLUtils;  
import android.view.KeyEvent;  
  
public class ThriRend extends BaseRend {  
  
 public float rato = 0;  
 private int[] texture = null;// 纹理数组  
 private Bitmap[] bit = new Bitmap[6];  
 private boolean key = true;  
  
 public ThriRend(Context context) {  
  bit[0] = BitmapFactory.decodeResource(context.getResources(),  
    R.drawable.icon1);  
  bit[1] = BitmapFactory.decodeResource(context.getResources(),  
    R.drawable.icon2);  
  bit[2] = BitmapFactory.decodeResource(context.getResources(),  
    R.drawable.icon3);  
  bit[3] = BitmapFactory.decodeResource(context.getResources(),  
    R.drawable.icon4);  
  bit[4] = BitmapFactory.decodeResource(context.getResources(),  
    R.drawable.icon5);  
  bit[5] = BitmapFactory.decodeResource(context.getResources(),  
    R.drawable.icon6);  
 }  
  
 public boolean onKeyUp(int keyCode, KeyEvent event) {  
  key = !key;  
  return false;  
 }  
  
 public void onDrawFrame(GL10 gl) {  
  super.onDrawFrame(gl);  
  gl.glTranslatef(0.0f, 0.0f, -5.0f);  
  
  // 设置旋转  
  // gl.glRotatef(rato, 0.0f, 1.0f, 0.0f);  
  gl.glRotatef(rato, 1.0f, 0.0f, 0.0f);  
  gl.glRotatef(rato, 0.0f, 1.0f, 0.0f);  
  
  gl.glNormalPointer(GL10.GL_FIXED, 0, Cube.normals);  
  gl.glVertexPointer(3, GL10.GL_FIXED, 0, Cube.vertices);  
  gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, Cube.texCoords);  
  
  gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);  
  gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);  
  gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);  
  
  // 绘制四边形  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);  
  gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE,  
    Cube.indices1);  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]);  
  gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 8, GL10.GL_UNSIGNED_BYTE,  
    Cube.indices2);  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]);  
  gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 12, GL10.GL_UNSIGNED_BYTE,  
    Cube.indices3);  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]);  
  gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 16, GL10.GL_UNSIGNED_BYTE,  
    Cube.indices4);  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]);  
  gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 20, GL10.GL_UNSIGNED_BYTE,  
    Cube.indices5);  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]);  
  gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 24, GL10.GL_UNSIGNED_BYTE,  
    Cube.indices6);  
  
  gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);  
  gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);  
  gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);  
  // rato += 2.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); // 关闭深度测试  
  }  
 }  
  
 public void onSurfaceChanged(GL10 gl, int width, int height) {  
  super.onSurfaceChanged(gl, width, height);  
 }  
  
 public void onSurfaceCreated(GL10 gl, EGLConfig config) {  
  super.onSurfaceCreated(gl, config);  
    
   gl.glEnable(GL10.GL_DEPTH_TEST);  
         gl.glDepthFunc(GL10.GL_LEQUAL);  
    
  // 打开纹理  
  gl.glEnable(GL10.GL_TEXTURE_2D);  
  
  // 绑定纹理  
  IntBuffer t_b = IntBuffer.allocate(6);  
  gl.glGenTextures(6, t_b);// 设置纹理的个数  
  texture = t_b.array();  
  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);  
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit[0], 0);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,  
    GL10.GL_NEAREST);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,  
    GL10.GL_NEAREST);  
  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]);  
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit[1], 0);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,  
    GL10.GL_NEAREST);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,  
    GL10.GL_NEAREST);  
  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]);  
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit[2], 0);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,  
    GL10.GL_NEAREST);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,  
    GL10.GL_NEAREST);  
  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[3]);  
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit[3], 0);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,  
    GL10.GL_NEAREST);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,  
    GL10.GL_NEAREST);  
  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[4]);  
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit[4], 0);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,  
    GL10.GL_NEAREST);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,  
    GL10.GL_NEAREST);  
  
  gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[5]);  
  GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit[5], 0);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,  
    GL10.GL_NEAREST);  
  gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,  
    GL10.GL_NEAREST);  
  
  gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);  
  
  gl.glColor4f(1.0f, 1.0f, 1.0f, 0.4f);  
  
  gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);  
  
  // 设置环境光  
  gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_AMBIENT, Cube.lightAmbient);  
  
  // 设置漫射光  
  gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, Cube.lightDiffuse);  
  
  // 设置光源位置  
  gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, Cube.lightPosition);  
  
  // 开启光源  
  gl.glEnable(GL10.GL_LIGHT1);  
  
  // 开启混合  
  gl.glEnable(GL10.GL_BLEND);  
 }  
  
}  
这里学习的资料也不少:http://www.eoeandroid.com/thread-3561-1-1.html

解决方案 »

  1.   

    忘记貼出处: http://dev.10086.cn/cmdn/wiki/index.php?doc-view-5942.html
      

  2.   

    不是 想要的那位大虾  知道Android 里面继承于Activity 类 里面写了一个  OnClick...怎末拿到继承与PLView的方法小弟  自学求帮助!!!~~
    /*
     * This file is part of the PanoramaGL library for Android.
     *
     *  Authors: Javier Baez <[email protected]> and Miguel 刟u朼y <[email protected]>
     *
     *  $Id$
     *
     * This is free software; you can redistribute it and/or modify it
     * under the terms of the GNU Lesser General Public License as
     * published by the Free Software Foundation; version 3 of
     * the License
     *
     * This software is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     * Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public
     * License along with this software; if not, write to the Free
     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
     */package panoramagl.examples;import javax.microedition.khronos.opengles.GL10;import com.android.panoramagl.PLTexture;
    import com.android.panoramagl.PLView;
    import com.android.panoramagl.enumeration.PLViewType;
    import com.android.panoramagl.structs.PLRange;import android.util.Log;public class HelloPanorama extends PLView
    {
    @Override
    protected void onGLContextCreated(GL10 g1)
    {
            super.onGLContextCreated(g1);
            
            System.out.println(g1);
            
            try
            {
             /*
              * Important Note: You must edit AndroidManifest.xml and put android:configChanges="keyboardHidden|orientation" attribute in activity else you have memory problems
              */
            
            
             //If you want to use setDeviceOrientationEnabled(true), activity orientation only must be portrait. Eg. android:screenOrientation="portrait"
         //设置定位图像(false)
             this.setDeviceOrientationEnabled(false);
        
         //You can use accelerometer你可以用加速计
         this.setAccelerometerEnabled(false);
         this.setAccelerometerLeftRightEnabled(true);
         this.setAccelerometerUpDownEnabled(false);
        
         //Scrolling and Inertia滚动和惯性
         this.setScrollingEnabled(true);
         this.setInertiaEnabled(true);
        
         //setFovRange determines Zoom range. Range values from -1.0f to 1.0f设置缩放范围
         this.getCamera().setFovRange(PLRange.PLRangeMake(0.0f, 1.0f));
        
         //Example with Sphere type (you need one image)球面型为例,你需要一张图片
         this.setType(PLViewType.PLViewTypeSpherical);//设置风格球形景观类型
    //      this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.pano)));
         this.addTextureAndRelease(PLTexture.textureWithImage(this.getImageWithResouce(R.drawable.aa)));
            }
            catch(Throwable ex)
            {
             Log.e("HelloPanorama::onGLContextCreated", "Error:" + ex.getMessage());
            }
    }

    }package panoramagl.examples;import android.app.Activity;
    import android.content.Intent;
    import android.opengl.GLSurfaceView;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import javax.microedition.khronos.opengles.GL10;import com.android.panoramagl.PLView;public class asa extends Activity {
    private PLView plView = new PLView();
    // private GLSurfaceView gl_view = null;
    private Button button;
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    // gl_view = new GLSurfaceView(this);
    //
    // gl_view.setRenderer(new BaseRend());
    // this.setContentView(gl_view);
    setContentView(R.layout.main);
    button = (Button) this.findViewById(R.id.star1);
    button.setOnClickListener(new Button.OnClickListener() {
    public void onClick(View v) {
    HelloPanorama Hello=new HelloPanorama();
    System.out.println("11111111111");
    // Hello.onGLContextCreated();
    System.out.println("22222222222"); } });

    }}
      

  3.   

    楼主 有源码共享吗 这是个demo吗 能传上来吗~3q