Hi,
wie der Titel schon andeutet möchte ich eine Orthogonale Projektionsmatrix
errechnen, damit ich 2D Sprites mit Koordinaten auf den Screen klatschen kann.
Ich habe mich bei dem Algorithmus ganz dreist bei 'glOrtho's Man Page orientiert.
Dabei kam folgendes heraus:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
|
void orthogonalProjection(float* pMatrix, float left, float right, float bottom, float top, float far, float near){
identity(pMatrix);
pMatrix[0] = 2.0f / (right - left);
pMatrix[3] = - (right + left) / (right - left);
pMatrix[5] = 2.0f / (top - bottom);
pMatrix[7] = - (top + bottom) / (top - bottom);
pMatrix[10] = -2.0f / (far - near);
pMatrix[11] = - (far + near) / (far - near);
pMatrix[15] = 1.0f;
}
|
Leider bekomme ich einen leeren Viewport dadurch. Ist die Projektionsmatrix eine Identitätsmatrix,
dann sehe ich zum Glück meine Sprites wieder, jedoch sind diese im Clipspace.
Errechne ich irgendetwas falsch?
LG Julien
P.S.: Mein Shader sieht so aus:
|
HLSL-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#version 330 core
layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 _uv;
uniform mat4 projection;
uniform mat4 model;
out vec2 uv;
void main(){
gl_Position = projection * model * vec4(pos.xy, 0.0, 1.0);
uv = _uv;
};
|