gpt4 book ai didi

java - OpenGL ES Android 中的深度缓冲区问题

转载 作者:行者123 更新时间:2023-12-01 04:54:29 24 4
gpt4 key购买 nike

好吧,所以我的深度缓冲区不起作用,因为当我在演示中移动时,它会改变显示的顶点,并使模型扭曲和“闪烁”。我的问题是,我做了或没有做任何可能导致这种影响的事情?

@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。

还添加了禁用抖动

关于java - OpenGL ES Android 中的深度缓冲区问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com