簡體   English   中英

OpenGL ES Android中的深度緩沖區問題

[英]Depth Buffer Woes in OpenGL ES Android

好吧,所以深度緩沖無法正常工作,因為當我在演示中移動時,它會更改顯示的頂點,並使模型變形和“閃爍”。 我的問題是,我正在做或不做任何可能導致這種影響的事情?

@Override
       public void onSurfaceCreated(GL10 gl, EGLConfig config) {
          gl.glClearColor(0.0f, 0.4f, 0.4f, 1.0f);  // Set color's clear-value to black
          /*Enable back face culling*/
          gl.glEnable(GL10.GL_CULL_FACE);
          gl.glCullFace(GL10.GL_BACK);
          gl.glFrontFace(GL10.GL_CCW);
          gl.glClearDepthf(1.0f);            // Set depth's clear-value to farthest
          gl.glEnable(GL10.GL_DEPTH_TEST);   // Enables depth-buffer for hidden surface removal
          gl.glDepthFunc(GL10.GL_LEQUAL);    // The type of depth testing to do
          gl.glDepthMask(true);
          gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);  // nice perspective view
          gl.glShadeModel(GL10.GL_SMOOTH);   // Enable smooth shading of color

          neroburst.model.loadTexture(gl, context);    // Load image into Texture (NEW)
          gl.glEnable(GL10.GL_TEXTURE_2D);  // Enable texture (NEW)
       }

       // Call back after onSurfaceCreated() or whenever the window's size changes
       @Override
       public void onSurfaceChanged(GL10 gl, int width, int height) {
          if (height == 0) height = 1;   // To prevent divide by zero
          float aspect = (float)width / height;

          // Set the viewport (display area) to cover the entire window
          gl.glViewport(0, 0, width, height);

          // Setup perspective projection, with aspect ratio matches viewport
          gl.glMatrixMode(GL10.GL_PROJECTION); // Select projection matrix
          gl.glLoadIdentity();                 // Reset projection matrix
          // Use perspective projection
          GLU.gluPerspective(gl, 45, aspect, 0.1f, 300.f);

          gl.glMatrixMode(GL10.GL_MODELVIEW);  // Select model-view matrix
          gl.glLoadIdentity();                 // Reset
       }

       // Call back to draw the current frame.
       @Override
       public void onDrawFrame(GL10 gl) {
          // Clear color and depth buffers using clear-value set earlier
          gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

          gl.glLoadIdentity();                 // Reset model-view matrix ( NEW )
           gl.glRotatef(neroburst.player.yaw, 0, 1, 0);
           gl.glTranslatef(-neroburst.player.pos.x, neroburst.player.pos.y, -neroburst.player.pos.z); 

          neroburst.model.draw(gl);
       }

修復。 我起飛了

  gl.glEnable(GL10.GL_CULL_FACE);
  gl.glCullFace(GL10.GL_BACK);
  gl.glFrontFace(GL10.GL_CCW);

將gl.glHint從最快更改為最好,我的觀點的值從0.1f更改為1。

還添加了禁用抖動

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM