Android 我的场景渲染颠倒了

Android 我的场景渲染颠倒了,android,graphics,opengl-es,libgdx,Android,Graphics,Opengl Es,Libgdx,我为一个小项目开发的场景的渲染有问题。看起来我的场景实际上是颠倒的,我不知道为什么 可以看到,选项按钮实际上是以正确的方向渲染的,而场景的其余部分则不是。我试图简单地反转着色器返回的位置的y坐标,但这会弄乱棕色立方体的移动 这是我写的着色器: #ifndef GL_ES #version 330 #endif uniform mat4 u_projectionMatrix; uniform mat4 u_viewMatrix; uniform vec3 u_scale; uniform m

我为一个小项目开发的场景的渲染有问题。看起来我的场景实际上是颠倒的,我不知道为什么

可以看到,选项按钮实际上是以正确的方向渲染的,而场景的其余部分则不是。我试图简单地反转着色器返回的位置的y坐标,但这会弄乱棕色立方体的移动

这是我写的着色器:

#ifndef GL_ES
#version 330
#endif

uniform mat4 u_projectionMatrix;
uniform mat4 u_viewMatrix;

uniform vec3 u_scale;
uniform mat4 u_rotation;
uniform vec3 u_position;
uniform vec2 u_textureScale;
uniform vec2 u_textureOffset;

attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_texCoord0;

varying vec4 v_position;
varying vec4 v_normal;
varying vec2 v_texCoords;

void main()
{
// Not sure why some vec4's need 0 or 1, since it's the w-coordinate (shouldn't this      always be 1 prior to applying the projection matrix?).
v_position = vec4(u_position, 0) + (u_rotation * (a_position * vec4(u_scale, 1)));
v_normal = normalize(u_rotation * vec4(a_normal, 0));
v_texCoords = (a_texCoord0 * u_textureScale) + u_textureOffset;

gl_Position = u_projectionMatrix * u_viewMatrix * v_position;
//gl_Position.y = -gl_Position.y;
} 
这是摄像机的代码:

public void create() {
...

_camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());

_camera.translate(0, -10, 20);
_camera.lookAt(new Vector3(0,0,0));
_camera.near = 0.1f;

...
}
有人能帮忙吗

编辑:更改上方向向量的y坐标可以修复场景的方向问题,但会使按钮消失,就像没有渲染一样。下面是我用来绘制选项按钮的代码:

public void create() {
    //camera code and other initialization stuff...

    // Create new stage for the ui.
    toggleOptions = new Stage();


    // Add a menu button.
    Table toggleBtn = new Table(skin);
    toggleOptions.addActor(toggleBtn);

    initUI();

    ...
    }

    private void initUI(){

    final TextButton toggleMenuButton = new TextButton("Options", skin);

    menuWidgets.put("toggleMenu", toggleMenuButton);
    toggleMenuButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            // Toggle the menu.
            showMenu = !showMenu;
        }
    });

    // Set up button so that is appears in the bottom center of the screen (with some padding).
    toggleMenuButton.setPosition((Gdx.graphics.getWidth() / 2.0f) - toggleMenuButton.getWidth() / 2.0f, padY);


    toggleMenuButton.setWidth(toggleMenuButton.getWidth() + padX);

    // Add the toggle button.
    toggleOptions.addActor(toggleMenuButton);
}

    public void render() {
    ...
    toggleOptions.act();
    toggleOptions.draw();
    ...
    }

编辑2:好的,问题是按钮渲染在平面和立方体后面,因为绘制调用放错了位置(应该是最后一次调用,但我在平面绘制和立方体绘制之前调用了它)。谢谢大家的帮助。

\u camera.setOrientation(180.0f,0.0f,0.0f,1.0f)

此:\u camera.translate(0,-10,20);看起来可疑。如果将-10改为10会怎么样?在哪里以及如何设置视图矩阵?您的代码中应该有对Matrix.setLookAtM的调用。上方向向量正确吗?@Tobor-mmm。。它固定了场景的方向,但文本按钮消失。@NigelK它在渲染函数中使用以下行设置:
shader.setUniformMatrix(“u_viewMatrix”,“u camera.view”)好,我还尝试将上方向向量的y坐标更改为-y,然后我再次获得正确方向的场景,但是按钮消失了。我会继续研究它,但是如果有人有想法的话,我会很感激相机对象没有设置方向的方法。你能在图片上显示(+x、+y和+z轴)吗?你可以通过在场景中平移方框来找到它们的方向。在这种情况下,使用带有文本或数字的纹理会很有用,这样我们就可以了解对象的方向。这个纹理没有给出任何关于物体旋转的想法。对不起,我没有足够的声誉在你的问题下写评论,这就是为什么我会在这里写它,在我的答案下。正如你提到的,问题是按钮的位置;我认为托伯的第一句话是对你最初问题的正确回答,不是吗?