亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > Java > 正文

java實現OpenGL ES紋理映射的方法

2019-11-26 15:08:21
字體:
來源:轉載
供稿:網友

本文實例講述了java實現OpenGL ES紋理映射的方法。分享給大家供大家參考。具體如下:

1. GlRenderer.java文件:

package net.obviam.opengl;import javax.microedition.khronos.egl.EGLConfig;import javax.microedition.khronos.opengles.GL10;import android.content.Context;import android.opengl.GLU;import android.opengl.GLSurfaceView.Renderer;public class GlRenderer implements Renderer {  private Square   square;   // the square  private Context   context;  /** Constructor to set the handed over context */  public GlRenderer(Context context) {    this.context = context;    // initialise the square    this.square = new Square();  }  @Override  public void onDrawFrame(GL10 gl) {    // clear Screen and Depth Buffer    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);    // Reset the Modelview Matrix    gl.glLoadIdentity();    // Drawing    gl.glTranslatef(0.0f, 0.0f, -5.0f);    // move 5 units INTO the screen    // is the same as moving the camera 5 units away//   gl.glScalef(0.5f, 0.5f, 0.5f);// scale the square to 50% // otherwise it will be too large    square.draw(gl); // Draw the triangle  }  @Override  public void onSurfaceChanged(GL10 gl, int width, int height) {    if(height == 0) { //Prevent A Divide By Zero By      height = 1; //Making Height Equal One    }    gl.glViewport(0, 0, width, height); //Reset The Current Viewport    gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix    gl.glLoadIdentity(); //Reset The Projection Matrix    //Calculate The Aspect Ratio Of The Window    GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);    gl.glMatrixMode(GL10.GL_MODELVIEW);    //Select The Modelview Matrix    gl.glLoadIdentity(); //Reset The Modelview Matrix  }  @Override  public void onSurfaceCreated(GL10 gl, EGLConfig config) {    // Load the texture for the square    square.loadGLTexture(gl, this.context);    gl.glEnable(GL10.GL_TEXTURE_2D); //Enable Texture Mapping ( NEW )    gl.glShadeModel(GL10.GL_SMOOTH); //Enable Smooth Shading    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //Black Background    gl.glClearDepthf(1.0f); //Depth Buffer Setup    gl.glEnable(GL10.GL_DEPTH_TEST); //Enables Depth Testing    gl.glDepthFunc(GL10.GL_LEQUAL); //The Type Of Depth Testing To Do    //Really Nice Perspective Calculations    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);   }}

2. Square.java文件:

package net.obviam.opengl;import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.nio.FloatBuffer;import javax.microedition.khronos.opengles.GL10;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.opengl.GLUtils;public class Square {  private FloatBuffer vertexBuffer;  // buffer holding the vertices  private float vertices[] = {      -1.0f, -1.0f, 0.0f,    // V1 - bottom left      -1.0f, 1.0f, 0.0f,    // V2 - top left       1.0f, -1.0f, 0.0f,    // V3 - bottom right       1.0f, 1.0f, 0.0f     // V4 - top right  };  private FloatBuffer textureBuffer; // buffer holding the texture coordinates  private float texture[] = {           // Mapping coordinates for the vertices      0.0f, 1.0f,   // top left   (V2)      0.0f, 0.0f,   // bottom left (V1)      1.0f, 1.0f,   // top right  (V4)      1.0f, 0.0f   // bottom right (V3)  };  /** The texture pointer */  private int[] textures = new int[1];  public Square() {    // a float has 4 bytes so we allocate for each coordinate 4 bytes    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);    byteBuffer.order(ByteOrder.nativeOrder());    // allocates the memory from the byte buffer    vertexBuffer = byteBuffer.asFloatBuffer();    // fill the vertexBuffer with the vertices    vertexBuffer.put(vertices);    // set the cursor position to the beginning of the buffer    vertexBuffer.position(0);    byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);    byteBuffer.order(ByteOrder.nativeOrder());    textureBuffer = byteBuffer.asFloatBuffer();    textureBuffer.put(texture);    textureBuffer.position(0);  }  /**   * Load the texture for the square   * @param gl   * @param context   */  public void loadGLTexture(GL10 gl, Context context) {    // loading texture    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.android);    // generate one texture pointer    gl.glGenTextures(1, textures, 0);    // ...and bind it to our array    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);    // create nearest filtered texture    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);    //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE//   gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);//   gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);    // Use Android GLUtils to specify a two-dimensional texture image from our bitmap     GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);    // Clean up    bitmap.recycle();  }  /** The draw method for the square with the GL context */  public void draw(GL10 gl) {    // bind the previously generated texture    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);    // Point to our buffers    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);    // Set the face rotation    gl.glFrontFace(GL10.GL_CW);    // Point to our vertex buffer    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);    // Draw the vertices as triangle strip    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);    //Disable the client state before leaving    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);  }}

3. Triangle.java文件:

package net.obviam.opengl;import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.nio.FloatBuffer;import javax.microedition.khronos.opengles.GL10;public class Triangle {  private FloatBuffer vertexBuffer;  // buffer holding the vertices  private float vertices[] = {      -0.5f, -0.5f, 0.0f,    // V1 - first vertex (x,y,z)       0.5f, -0.5f, 0.0f,    // V2 - second vertex       0.0f, 0.5f, 0.0f     // V3 - third vertex//      1.0f, 0.5f, 0.0f     // V3 - third vertex  };  public Triangle() {    // a float has 4 bytes so we allocate for each coordinate 4 bytes    ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);    vertexByteBuffer.order(ByteOrder.nativeOrder());    // allocates the memory from the byte buffer    vertexBuffer = vertexByteBuffer.asFloatBuffer();    // fill the vertexBuffer with the vertices    vertexBuffer.put(vertices);    // set the cursor position to the beginning of the buffer    vertexBuffer.position(0);  }  /** The draw method for the triangle with the GL context */  public void draw(GL10 gl) {    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);    // set the colour for the background//   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // to show the color (paint the screen) we need to clear the color buffer//   gl.glClear(GL10.GL_COLOR_BUFFER_BIT);    // set the colour for the triangle    gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);    // Point to our vertex buffer    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);    // Draw the vertices as triangle strip    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);    //Disable the client state before leaving    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);  }}

4. Run.java文件:

package net.obviam.opengl;import android.app.Activity;import android.opengl.GLSurfaceView;import android.os.Bundle;import android.view.Window;import android.view.WindowManager;public class Run extends Activity {  /** The OpenGL view */  private GLSurfaceView glSurfaceView;  /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    // requesting to turn the title OFF    requestWindowFeature(Window.FEATURE_NO_TITLE);    // making it full screen    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Initiate the Open GL view and    // create an instance with this activity    glSurfaceView = new GLSurfaceView(this);    // set our renderer to be the main renderer with    // the current activity context    glSurfaceView.setRenderer(new GlRenderer(this));    setContentView(glSurfaceView);  }  /**   * Remember to resume the glSurface   */  @Override  protected void onResume() {    super.onResume();    glSurfaceView.onResume();  }  /**   * Also pause the glSurface   */  @Override  protected void onPause() {    super.onPause();    glSurfaceView.onPause();  }}

希望本文所述對大家的java程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产盗摄xxxx视频xxx69| 欧洲成人午夜免费大片| 热久久视久久精品18亚洲精品| 欧美日本啪啪无遮挡网站| 热门国产精品亚洲第一区在线| 1769国内精品视频在线播放| 中文字幕亚洲情99在线| 久久99亚洲热视| 亚洲福利视频久久| 精品国产福利视频| 国产精品成人品| 久久久久日韩精品久久久男男| 欧美日韩福利在线观看| 日韩亚洲在线观看| 精品网站999www| 91av在线看| 国产精品夜色7777狼人| 亚洲午夜激情免费视频| 日韩欧美亚洲成人| 国产一区二区三区精品久久久| 久久伊人91精品综合网站| 国产一区二区三区三区在线观看| 久久久国产成人精品| 国产精品视频一区二区三区四| 日韩成人在线视频观看| 欧美国产高跟鞋裸体秀xxxhd| 国产精品美女免费| 中文字幕免费精品一区| 成人激情在线播放| 欧美午夜精品久久久久久久| 亚洲欧美视频在线| 欧美疯狂做受xxxx高潮| 国产aⅴ夜夜欢一区二区三区| 欧美高清自拍一区| 亚洲免费人成在线视频观看| 亚洲成人免费在线视频| 日韩精品在线视频| 久久精品中文字幕一区| 国产免费亚洲高清| 国产精品久久久久久久久久免费| 性色av一区二区三区红粉影视| 日韩欧美国产免费播放| 中文字幕欧美日韩va免费视频| 欧美日韩精品二区| 精品久久久久久久中文字幕| 国产精品揄拍一区二区| 日韩美女福利视频| 欧美中文在线观看国产| 亚洲自拍偷拍在线| 欧美激情视频三区| 国产日韩在线看片| 亚洲a区在线视频| 97国产一区二区精品久久呦| 国产精品观看在线亚洲人成网| 美日韩精品免费视频| 热99在线视频| 亚洲成年人在线| 久久精品视频一| 亚洲在线第一页| 欧美电影《睫毛膏》| 精品一区二区电影| 亚洲最大激情中文字幕| 日韩亚洲国产中文字幕| 亚洲最大福利视频网| 久久久av亚洲男天堂| 国产一区二中文字幕在线看| 欧美黄色片在线观看| wwwwwwww亚洲| 久久亚洲欧美日韩精品专区| 国产亚洲人成a一在线v站| 午夜精品久久久99热福利| 亚洲国产欧美一区二区丝袜黑人| 日韩女在线观看| 亚洲国产成人精品女人久久久| 一区二区三区亚洲| 97碰碰碰免费色视频| 久热精品视频在线| 亚洲天堂网站在线观看视频| 国产亚洲精品一区二区| 日韩视频在线免费观看| 最近中文字幕mv在线一区二区三区四区| 亚洲国产高清高潮精品美女| 日本精品va在线观看| 亚洲爱爱爱爱爱| 日韩av在线一区| 亚洲精品自在久久| 欧美大成色www永久网站婷| 中文精品99久久国产香蕉| 亚洲欧美国产高清va在线播| 第一福利永久视频精品| 国产亚洲xxx| 欧美香蕉大胸在线视频观看| 亚洲人成77777在线观看网| 久久免费精品日本久久中文字幕| 亚洲风情亚aⅴ在线发布| 亚洲福利视频网站| 国产精品自拍网| 久久精品国产96久久久香蕉| 在线播放国产精品| 欧美日韩亚洲高清| 午夜精品久久久久久久99热浪潮| 亚洲欧美日韩精品久久奇米色影视| 久久99亚洲热视| 欧美色videos| 日本成人精品在线| 国产精品久久久久久久久久ktv| 日韩av在线电影网| 国产精品爽爽ⅴa在线观看| 国产综合香蕉五月婷在线| 美女视频久久黄| 国产欧美一区二区三区在线看| 久久精品成人一区二区三区| 日韩电影中文字幕在线| 欧美日韩国产精品一区二区三区四区| 亚洲a在线播放| 欧美色视频日本高清在线观看| 九九久久精品一区| 亚洲美女精品久久| 亚洲r级在线观看| 国产999精品| 国产婷婷色综合av蜜臀av| 2019中文字幕在线免费观看| 福利视频一区二区| 日韩天堂在线视频| 成人国产精品久久久久久亚洲| 国产精品美女在线| 亚洲图片欧美日产| 日韩在线播放一区| 欧美大片免费观看| 中文字幕亚洲无线码a| 日韩电影免费在线观看中文字幕| 日韩精品中文字幕久久臀| 中文.日本.精品| 亚洲精品中文字幕女同| 久久久电影免费观看完整版| 国产福利精品视频| 亚洲人精品午夜在线观看| 亚洲精品国产精品国自产观看浪潮| 日韩电视剧免费观看网站| 中文字幕无线精品亚洲乱码一区| 国产精品第2页| 久久影院资源网| 国产成人综合精品在线| 2018中文字幕一区二区三区| 久久久久久久久久久免费| 国产精品中文在线| 亚洲免费视频网站| 久久综合久中文字幕青草| 国产精品香蕉av| 国产精品igao视频| 91久久中文字幕| 亚洲欧洲午夜一线一品| 亚洲精品视频网上网址在线观看| 精品久久在线播放| 九九热精品视频国产| 51久久精品夜色国产麻豆| 国产成人avxxxxx在线看| 日本一区二三区好的精华液| 欧美精品第一页在线播放| 亚洲成人a级网| 久久久成人精品视频| 中文字幕精品在线视频| 亚洲午夜小视频| 日韩av大片免费看|