Hallo an alle,
ich wollte in mein Framework eine 2D-Schnittstelle einbauen, um z.B. Text zeichnen zu können. Da hab ich mir überlegt das mit einer Orthogonalen Porjectionsmatrix zu realisieren. Die hab ich dann auch erstmal in mein Framework eingebaut, aber wenn ich die nun anwende, seh ich nichts.
Als Beispiel hab ich ein Dreieck genommen, der leider nicht angezeigt wird, der Bildschirm bleibt schwarz. Die World und View Matrix sind jeweils auf die Einheitsmatrix gesetzt, der Vertexbuffer wird auch erstellt.
Hier mein Beispielcode:
|
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
|
Vertexbuffer vBuffer;
void Init()
{
SVertex Vertices[3];
// Positionen in Pixel
Vertices[0].Pos = Vector3(320.0f, 50.0f, 1.0f);
Vertices[1].Pos = Vector3(520.0f, 400.0f, 1.0f);
Vertices[2].Pos = Vector3(120.0f, 400.0f, 1.0f);
// Farbe der Vertices
Vertices[0].Color = Color::RED;
Vertices[1].Color = Color::BLUE;
Vertices[2].Color = Color::GREEN;
// Vertexbuffer erstellen
Math::Matrix4x4 Projection;
// Orthogonale Projections Matrix erstellen Width: 800, Height: 600, NearPlane: -1, FarPlane: 1
Projection = Math::OrthogonalProjection(800.0f, 600.0f, -1.0f, 1.0f);
// Matrix setzen
}
void Draw()
{
Device->Clear(Color::BLACK);
// Shader, InputLayout und der Vertexbuffer werden in der Draw Methode gesetzt
Device->Draw(3, 0, &vBuffer);
Device->Present();
}
|
Hier mein Shader:
|
HLSL-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
|
cbuffer Matrixbuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
matrix WVP;
matrix TexturMatrix;
};
struct VShaderInput
{
float4 Pos : POSITION;
float4 Color : COLOR;
};
struct PShaderInput
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
PShaderInput VShader(VShaderInput Input)
{
PShaderInput Output;
// WVP = World * View * Projection ... Wurde im Hauptprogramm schon zusammen multiplieziert
Output.Pos = mul(float4(Input.Pos, 1.0f), WVP);
Output.Color = Input.Color;
return Output;
}
float4 PShader(PShaderInput Input) : SV_TARGET
{
return Input.Color;
}
|
Meine Matrix wird so gebildet:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
|
Matrix4x4 OrthogonalProjection(float Width, float Height, float NearPlane, float FarPlane)
{
return Matrix4x4(2 / Width, 0.0f, 0.0f, 0.0f,
0.0f, 2 / Height, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f / (FarPlane - NearPlane), 0.0f,
0.0f, 0.0f, 0.0f, -NearPlane/ (FarPlane - NearPlane));
}
|
Ich glaube das der Fehler nicht beim erstellen der Matrix liegen kann, mit den Debuger hab ich auch schon geschaut, ob der Vertexbuffer erstellt wird, und der wird auch erstellt.
Gegoogelt hab ich auch schon, aber nichts gefunden, was bei mein Problem helfen könnte. Vllt sieht einer von euch, was ich hier falsch mache.
Aufjedenfall vielen Dank im voraus.
Mfg Male