Mesh rendering issue libgdx

▼魔方 西西 提交于 2019-12-12 11:05:39

问题


I have a very simple program, that loads an wavefront obj file, rotate and displays it. The problem is that the program renders it with some issues (like missing triangles). I had a similar problem when I tried to render a Pyramid with a vertex buffer taken from NeHe's tutorial. So I don't know what cause this rendering issues. Can you help me?

package com.jam.libgdx3DTest;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g3d.loaders.obj.ObjLoader;

import java.io.InputStream;

public class Libgdx3DTest extends Game {

    private Mesh shuttleMesh;
    private Camera camera;
    private float rotateAngle;

    public void create() {
        if (shuttleMesh == null) {
            InputStream in = Gdx.files.internal("shuttle.obj").read();
            shuttleMesh = ObjLoader.loadObj(in, false);
        }
    }

    public void render() {
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

        Gdx.gl10.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);

        Gdx.gl10.glLoadIdentity();

        camera.update();
        camera.apply(Gdx.gl10);

        rotateAngle += 0.5f;
        Gdx.gl10.glRotatef(rotateAngle, 0f, 1f, 0f);
        Gdx.gl10.glRotatef(-90f, 1f, 0f, 0f);

        shuttleMesh.render(GL11.GL_TRIANGLES);
    }

    public void resize(int width, int height) {
        float aspectRatio = (float) width / (float) height;
        camera = new PerspectiveCamera(67, 2f * aspectRatio, 2f);
        camera.translate(0f, 0f, 12f);
    }

    public void pause(){
    }

    public void resume(){
    }

    public void dispose() {
    }
}

回答1:


I think you might be having winding issues i.e. the model has different winding than OpenGL.

OpenGL Winding is counterclockwise by default though this can be changed with glFrontFace(GL_CW);




回答2:


i think this is your problem

shuttleMesh.render(GL11.GL_TRIANGLES) 

should be

shuttleMesh.render(GL11.GL_TRIANGL_FAN);

to ma



来源:https://stackoverflow.com/questions/11927277/mesh-rendering-issue-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!