my scene is rendered upside down

I have a problem with the rendering of a scene that I'm developing for a small project. It appears that my scene is actually rendered upside down and I can't figure out why.

在这里输入图像描述

You can see that the option button is actually rendered with the right orientation, while the rest of the scene is not. I tried to simply invert the y coordinate of the position returned by the shader but it messes up with the movement of the brown cube.

This is the shader that I wrote:

#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;
} 

This is the code for the camera:

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;

...
}

Can anybody help?

EDIT: Changing the y coordinate of the up vector fixes the orientation problem with the scene but makes the button disappear, like it's not rendered. Here's the code that I use to draw the options button:

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();
    ...
    }

EDIT 2: Ok, the issue was that the button was rendered behind the plane and the cube because the draw call was misplaced (it was supposed to be the last call, but instead I called it before the plane draw and cube draw). Thanks for the help, everyone.


_camera.setOrientation(180.0f,0.0f,0.0f,1.0f)

链接地址: http://www.djcxy.com/p/63876.html

上一篇: 在Qml场景下使用OpenGL进行渲染时出现奇怪的错误

下一篇: 我的场景颠倒了