Hi,
ich hab den FragmentShader jetzt mal wieder "richtig" gemacht
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#version 330
precision highp float;
uniform sampler2D texture0;
uniform vec4 textcolor;
in vec2 texCoords;
out vec4 outputColor;
void main(){
outputColor = texture(texture0, texCoords);
outputColor = outputColor * textcolor;
}
|
Funktioniert trotzdem nicht.
Wenn ich beim Rendern nichts grundlegendes falsch gemacht habe, kann der Fehler ja eigentlich nurnoch an den Berechnungen von
pm liegen.
Da ich bei GLM keine Berechnungsfunktionen für eine 3x3 Matrix gefunden habe, habe ich mir selber eine Helper Klasse gebastelt.
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#include "../../stdafx.h"
#include "Mat3x3.h"
glm::mat3 Math::Mat3x3::Translate(const glm::mat3 matrix, const float x, const float y)
{
glm::mat3x3 m = Math::Mat3x3::Identity();
m[2][0] = x;
m[2][1] = y;
glm::mat3 ret = matrix;
ret *= m;
return ret;
}
glm::mat3 Math::Mat3x3::Rotate(const glm::mat3 matrix, float angle)
{
glm::mat3 m = glm::mat3(0.0f);
float co, si;
angle = angle * ((float)M_PI/180.0f);
si = sinf(angle);
co = cosf(angle);
m[0][0] = co;
m[0][1] = si;
m[0][2] = 0;
m[1][0] = -si;
m[1][1] = co;
m[1][2] = 0;
m[2][0] = 0;
m[2][1] = 0;
m[2][2] = 1;
glm::mat3 ret = matrix;
ret *= m;
return ret;
}
glm::mat3 Math::Mat3x3::Scale(const glm::mat3 matrix, const float x, const float y)
{
glm::mat3 m = STEngine::Math::Mat3x3::Identity();
m[0][0] = x;
m[1][1] = y;
glm::mat3 ret = matrix;
ret *= m;
return ret;
}
glm::mat3 Math::Mat3x3::Ortho(const int left, const int right, const int bottom, const int top)
{
glm::mat3 ret = Math::Mat3x3::Identity();
if (left != right && bottom != top)
{
ret[0][0] = 2 / (float(right - left));
ret[1][1] = 2 / (float(top - bottom));
ret[2][0] = -(float(right + left)) / (float(right - left));
ret[2][1] = -(float(top + bottom)) / (float(top - bottom));
ret[2][2] = 1;
}
return ret;
}
float* Math::Mat3x3::GetArray(const glm::mat3 matrix)
{
std::vector<float> values;
values.push_back(matrix[0][0]);
values.push_back(matrix[0][1]);
values.push_back(matrix[0][2]);
values.push_back(matrix[1][0]);
values.push_back(matrix[1][1]);
values.push_back(matrix[1][2]);
values.push_back(matrix[2][0]);
values.push_back(matrix[2][1]);
values.push_back(matrix[2][2]);
return &values[0];
}
glm::mat3 Math::Mat3x3::Identity()
{
glm::mat3 ident = glm::mat3(0.0f);
ident[0][0] = 1.0f;
ident[1][1] = 1.0f;
ident[2][2] = 1.0f;
return ident;
}
|
Beim Rendern:
Zuerst berechne ich die Orthologie-Matrix für das Fenster:
|
C-/C++-Quelltext
|
1
|
this->OrthoMatrix = Math::Mat3x3::Ortho(0, (int)width, 0, (int)height);
|
Die ModelMatrix für das TextObjekt berechne ich
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//Identity Matrix
this->ModelMatrix = Math::Mat3x3::Identity();
//zur Rotation an den Rotationspunkt verschieben
this->ModelMatrix = Math::Mat3x3::Translate(this->ModelMatrix, this->Position + this->Rotationpoint);
//Rotieren
this->ModelMatrix = Math::Mat3x3::Rotate(this->ModelMatrix, this->Rotation);
//zurück Verschieben
this->ModelMatrix = Math::Mat3x3::Translate(this->ModelMatrix, -this->Rotationpoint.x, -this->Rotationpoint.y);
//Skalieren
this->ModelMatrix = Math::Mat3x3::Scale(this->ModelMatrix, this->Size);
this->ModelMatrix = Math::Mat3x3::Scale(this->ModelMatrix, this->Scale);
|
Und zum Ende berechne ich dann
pm für den Shader
|
C-/C++-Quelltext
|
1
|
this->TextShader->sendUniform3x3("pm", Math::Mat3x3::GetArray(this->OrthoMatrix * text->GetModelMatrix()));
|
Hab ich da vielleicht schon irgendwo nen Fehler drin?
Mein Problem im Moment ist, dass ich nicht wirklich richtig debuggen kann, weil ich halt nicht weis, wie am Ende die Werte der
pm-Matrix richtig aussehen müssen, bevor sie an den Shader gehen.
Gruß
EDIT: Ich habe mir mal GLSLDevil runtergeladen. Ich glaube das Problem entdeckt zu haben. Irgendwie wird das glGetAttribLocation() aufgerufen, bevor das ShaderProgram überhaupt gelinkt wird. Das sollte ja sicher nicht so sein. Deshalb gibt mir die Funktion immer -1 zurück.
Jetzt ist also erstmal debuggen angesagt, aber vielleicht kann doch jemand kurz über meine Mat3x3 Helper Klasse drübergucken, ob das alles soweit korrekt ist.