Ich habe keine Ideen, warum mein Modell im Perspektivmodus gut dargestellt wird, aber im Orthomodus fehlerhaft ist. Das Modell besteht aus 2 Würfeln, von denen einer groß und der andere klein ist. In Ortho-Modus die kleinen Würfel hinter dem Großen machen, altough sollte es nicht:Probleme beim Rendern eines 3D-Modells auf einer 2D-GUI
Obvisouly bin ich etwas richtig, weil der große Würfel tut ganz richtig macht, selbst wenn sie in jede Richtung gedreht werden. Vielleicht etwas damit zu tun, dass im Orthomodus der Tiefenpuffer linear ist? Meine Werte für znear und zfar in Orthomode sind 0,4 und 1000. Die Tiefe ist aktiviert. Das Modell (= beiden Würfel) wird in einer VAO mit 3 VBOs gespeichert (für Vertices, UVS und rgbas)
Das Modell dieses Shader gerendert wird unter Verwendung von:
Vertex:
#version 330
#extension GL_ARB_explicit_attrib_location: enable
layout(location = 0) in vec3 vertexPositionIn;
layout(location = 1) in vec2 uvIn;
layout(location = 2) in vec4 colorIn;
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
out vec2 uv;
out vec4 color;
void main(void)
{
uv = uvIn;
color = colorIn;
gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPositionIn, 1.0);
}
Fragmente:
#version 330
in vec2 uv;
in vec4 color;
uniform sampler2D itemTex;
void main() {
gl_FragColor = texture(itemTex, uv) * color;
}
Ortho-Modus-Setup
public void OrthoMode(int width, int height)
{
GlMatrixModeProjection();
GlPushMatrix();
GlLoadIdentity();
GlOrtho(0, width, height, 0, 0.4f, 1001);
LoadCurrentProjectionMatrix();
GlMatrixModeModelView();
GlPushMatrix();
GlLoadIdentity();
GlTranslate(0, 0, -500); // Translate far in the back so we can also render 3d stuff
LoadCurrentModelViewMatrix();
}
Draw-Aufruf:
[....]
game.GlPushMatrix();
game.GlTranslate((float)posX, (float)posY, (float)posZ);
DrawItemStack(modelref, size, rotate);
game.GlPopMatrix();
[....]
public void DrawItemStack(ModelRef modelref, float size, bool rotate = false)
{
game.GlPushMatrix();
game.GlTranslate(0.5f * size, 0.5f * size, 0.5f * size);
game.GlRotate(180f + 22.6f, 1, 0, 0); // In ortho mode our y-axis is flipped
game.GlRotate(-45.3f + (rotate ? game.CurrentTimeMilliseconds/50f : 0), 0, 1, 0);
game.GlScale(size * 0.5f, size * 0.5f, size * 0.5f);
game.GlTranslate(-0.5f, -0.5f, -0.5f);
game.LoadCurrentProjectionMatrixUniform(0);
game.LoadCurrentModelviewMatrixUniform(1);
game.Platform.DrawModelNew(modelref); // Calls GL.DrawElements()
game.GlPopMatrix();
}
Und schließlich ist er ein animiertes gif, wie es bei einer Drehung verhält:
Bitte fügen Sie den Code hinzu, der Ihr Setup für den Orthomodus und die Tiefeneinstellung zeigt. – Andreas
hinzugefügt Ortho Modus Setup (ich mache die Matrix-Berechnungen selbst, also nicht native OpenGL-Matrix-Methoden aufrufen). Die Tiefeneinstellung ist nur ein einfacher Tiefen-Test. – Tyron
Hm. Sieht für mich lustig aus. Lass uns etwas anderes versuchen. Rufen Sie gDEBugger/CodeXL auf und analysieren Sie die Tiefe der beiden Würfel. Wenn Sie gleich sind, haben Sie ein Problem. – Andreas