Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Anonymous

unregistriert

1

01.08.2003, 16:18

Bildschirm bleibt schwarz

Es ist zum verzweifeln!!!!!!!!!!!!!
Warum funktioniert dieser Code nicht:

Quellcode

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//*****************************************************************************
//Includes

#include <Tribase.h>

//*****************************************************************************
//globale Funktionen: Deklaration

tbResult InitApp ();
tbResult Move (float fTime);
tbResult Render (float fTime);

//*****************************************************************************

tbConfig                    g_Config;

tbVertexBuffer              *g_pVertexBuffer;
tbIndexBuffer               *g_pIndexBuffer;

tbMatrix                    g_Projection;
tbMatrix                    g_View;
tbMatrix                    g_World;

tbMatrix                    g_Translation;
tbMatrix                    g_Rotation;
tbMatrix                    g_Skalation;

//*****************************************************************************
//Klassen
///////////////////////////////////////////////////////////////////////////////
struct SVertex
{
tbVector3                   Position;
tbVector3                   Normal;
tbVector2                   TexCoord;
};
///////////////////////////////////////////////////////////////////////////////
//*****************************************************************************
//Funktionen
///////////////////////////////////////////////////////////////////////////////
//Move-Funkion
tbResult Move (float fTime)
{
return TB_OK;
}
///////////////////////////////////////////////////////////////////////////////
//Render-Funktion
tbResult Render (float fTime)
{
tbDirect3D::Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, tbColor (0.0f), 1.0f, 0);

tbDirect3D::BeginScene ();

tbDirect3D::GetDevice()->DrawIndexedPrimitive (D3DPT_TRIANGLELIST,
                                               0,
                                               0,
                                               1536,
                                               0,
                                               512);

tbDirect3D::Present ();

tbDirect3D::EndScene ();

return TB_OK;
}
///////////////////////////////////////////////////////////////////////////////
//WINMAIN-Funktion
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow )
{
ZeroMemory (&g_Config, sizeof (tbConfig));

if (tbInit () == TB_OK && 
    tbDoConfigDialog (&g_Config) == TB_OK && 
    tbDirect3D::Init (&g_Config, 
                      "Simulation") == TB_OK &&
    tbDirectInput::Init () == TB_OK && 
    tbDirectSound::Init (&g_Config) == TB_OK)
    {
    InitApp ();

    tbDoMessageLoop (Move, Render);
    }

tbDirectSound::Exit ();
tbDirectInput::Exit ();
tbDirect3D::Exit ();
tbExit ();

return 0;
}
///////////////////////////////////////////////////////////////////////////////
//*****************************************************************************
//Initiiert die Application
tbResult InitApp ()
{
tbDirect3D::SetFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
tbDirect3D::SetRS (D3DRS_CULLMODE, D3DCULL_NONE);

SVertex Vertex[256];

g_pVertexBuffer = new tbVertexBuffer ();
g_pIndexBuffer  = new tbIndexBuffer ();
g_pVertexBuffer->Init (256*sizeof(SVertex), 
                       sizeof(SVertex), 
                       D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
g_pIndexBuffer->Init  (256*2*3,
                       2,
                       D3DFMT_INDEX16);

for (int j = 0; j < 256; j++)
    {
    Vertex[j].Position = tbVector3 (10.0f*(j%16), 
                                    10.0f*((j-j%16)/16), 
                                    tbFloatRandom (0.0f, 10.0f));
    Vertex[j].TexCoord = tbVector2  ((float) (j%16),
                                    (float) (j-j%16)/16);
    }

for (int i = 0; i < 256; i++)
    {
    Vertex[i].Normal = tbVector3InterpolateNormal (
                            tbVector3InterpolateCoords (
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i-15].Position-Vertex[i].Position,
                                        Vertex[i+1 ].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i+1 ].Position-Vertex[i].Position,
                                        Vertex[i+17].Position-Vertex[i].Position),
                                    0.5f),
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i+17].Position-Vertex[i].Position,
                                        Vertex[i+16].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i+16].Position-Vertex[i].Position,
                                        Vertex[i+15].Position-Vertex[i].Position),
                                    0.5f),
                                0.5f),
                            tbVector3InterpolateCoords (
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i+15].Position-Vertex[i].Position,
                                        Vertex[i-1 ].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i-1 ].Position-Vertex[i].Position,
                                        Vertex[i-17].Position-Vertex[i].Position),
                                    0.5f),
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i-17].Position-Vertex[i].Position,
                                        Vertex[i-16].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i-16].Position-Vertex[i].Position,
                                        Vertex[i-15].Position-Vertex[i].Position),
                                    0.5f),
                                0.5f),
                            0.5f);
    }
g_pVertexBuffer->SetVertices (0, 256, Vertex);
g_pVertexBuffer->Update ();
int x = 0;
for (int a = 0; a < 256; a++)
    {
    x = a;
    g_pIndexBuffer->SetIndex (6*a  , &x);
    x = a+16;
    g_pIndexBuffer->SetIndex (6*a+1, &x);
    x = a+17;
    g_pIndexBuffer->SetIndex (6*a+2, &x);
    x = a;
    g_pIndexBuffer->SetIndex (6*a+3, &x);
    x = a+17;
    g_pIndexBuffer->SetIndex (6*a+4, &x);
    x = a+1;
    g_pIndexBuffer->SetIndex (6*a+5, &x);
    }
g_pIndexBuffer->Update ();

g_Translation = tbMatrixTranslation (tbVector3 (0, 0, 0));
g_Rotation    = tbMatrixRotation (0, 0, 0);
g_Skalation   = tbMatrixScaling (tbVector3 (1, 1, 1));

g_World       = g_Skalation * g_Rotation * g_Translation;
g_Projection  = tbMatrixProjection (TB_DEG_TO_RAD (65.0f), 
                                    tbDirect3D::GetAspect (),
                                    0.1f, 
                                    250.0f);
g_View        = tbMatrixCamera (tbVector3 (80.0f, 80.0f, 100.0f),
                                tbVector3 (80.0f, 80.0f, 99.0f),
                                tbVector3 (0.0f,  1.0f,  0.0f));

tbDirect3D::SetTransform (D3DTS_WORLD, g_World);
tbDirect3D::SetTransform (D3DTS_PROJECTION, g_Projection);
tbDirect3D::SetTransform (D3DTS_VIEW, g_View);

D3DMATERIAL9 Material;

Material.Diffuse = tbColor (0.0f, 1.0f, 0.0f);
Material.Ambient = tbColor (0.0f, 0.0f, 0.1f);
Material.Specular = tbColor (0.0f, 0.0f, 0.0f);
Material.Emissive = tbColor (0.1f, 0.0f, 0.0f);
Material.Power = 1.0f;

tbDirect3D::SetMaterial (&Material);

return TB_OK;
};
//*****************************************************************************

2

01.08.2003, 16:22

Du hast

Quellcode

1
2
tbDirect3D::Present (); 
tbDirect3D::EndScene ();
vertauscht. Die Scene wird erst Beendet und dann dargestellt.

Hast Du Licht eingeschaltet? Wenn nicht wird das Material Ignoriert.
Wichtig! Ich übernehme keinerlei Verantwortung für eventl. Datenverlust oder Schäden am Rechner ;D

Anonymous

unregistriert

3

01.08.2003, 16:48

Das ist der gesamte Code. Ich habe ihn jetzt verändert, aber der Schirm bleibt trotzdem schwarz. Hab ne GeForce 3 MX mit maximal 8 Lichtern

Quellcode

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//*****************************************************************************
//Includes

#include <Tribase.h>

//*****************************************************************************
//globale Funktionen: Deklaration

tbResult InitApp ();
tbResult Move (float fTime);
tbResult Render (float fTime);

//*****************************************************************************

tbConfig                    g_Config;

tbVertexBuffer              *g_pVertexBuffer;
tbIndexBuffer               *g_pIndexBuffer;

tbMatrix                    g_Projection;
tbMatrix                    g_View;
tbMatrix                    g_World;

tbMatrix                    g_Translation;
tbMatrix                    g_Rotation;
tbMatrix                    g_Skalation;

//*****************************************************************************
//Klassen
///////////////////////////////////////////////////////////////////////////////
struct SVertex
{
tbVector3                   Position;
tbVector3                   Normal;
tbVector2                   TexCoord;
};
///////////////////////////////////////////////////////////////////////////////
//*****************************************************************************
//Funktionen
///////////////////////////////////////////////////////////////////////////////
//Move-Funkion
tbResult Move (float fTime)
{
return TB_OK;
}
///////////////////////////////////////////////////////////////////////////////
//Render-Funktion
tbResult Render (float fTime)
{
tbDirect3D::Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, tbColor (0.0f), 1.0f, 0);

tbDirect3D::BeginScene ();

tbDirect3D::GetDevice()->DrawIndexedPrimitive (D3DPT_TRIANGLELIST,
                                               0,
                                               0,
                                               1536,
                                               0,
                                               512);

tbDirect3D::EndScene ();

tbDirect3D::Present ();

return TB_OK;
}
///////////////////////////////////////////////////////////////////////////////
//WINMAIN-Funktion
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow )
{
ZeroMemory (&g_Config, sizeof (tbConfig));

if (tbInit () == TB_OK && 
    tbDoConfigDialog (&g_Config) == TB_OK && 
    tbDirect3D::Init (&g_Config, 
                      "Simulation") == TB_OK &&
    tbDirectInput::Init () == TB_OK && 
    tbDirectSound::Init (&g_Config) == TB_OK)
    {
    InitApp ();

    tbDoMessageLoop (Move, Render);
    }

tbDirectSound::Exit ();
tbDirectInput::Exit ();
tbDirect3D::Exit ();
tbExit ();

return 0;
}
///////////////////////////////////////////////////////////////////////////////
//*****************************************************************************
//Initiiert die Application
tbResult InitApp ()
{
tbDirect3D::SetFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
tbDirect3D::SetRS (D3DRS_CULLMODE, D3DCULL_NONE);

SVertex Vertex[256];

g_pVertexBuffer = new tbVertexBuffer ();
g_pIndexBuffer  = new tbIndexBuffer ();
g_pVertexBuffer->Init (256*sizeof(SVertex), 
                       sizeof(SVertex), 
                       D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
g_pIndexBuffer->Init  (256*2*3,
                       2,
                       D3DFMT_INDEX16);

for (int j = 0; j < 256; j++)
    {
    Vertex[j].Position = tbVector3 (10.0f*(j%16), 
                                    10.0f*((j-j%16)/16), 
                                    tbFloatRandom (0.0f, 10.0f));
    Vertex[j].TexCoord = tbVector2  ((float) (j%16),
                                    (float) (j-j%16)/16);
    }

for (int i = 0; i < 256; i++)
    {
    Vertex[i].Normal = tbVector3InterpolateNormal (
                            tbVector3InterpolateCoords (
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i-15].Position-Vertex[i].Position,
                                        Vertex[i+1 ].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i+1 ].Position-Vertex[i].Position,
                                        Vertex[i+17].Position-Vertex[i].Position),
                                    0.5f),
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i+17].Position-Vertex[i].Position,
                                        Vertex[i+16].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i+16].Position-Vertex[i].Position,
                                        Vertex[i+15].Position-Vertex[i].Position),
                                    0.5f),
                                0.5f),
                            tbVector3InterpolateCoords (
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i+15].Position-Vertex[i].Position,
                                        Vertex[i-1 ].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i-1 ].Position-Vertex[i].Position,
                                        Vertex[i-17].Position-Vertex[i].Position),
                                    0.5f),
                                tbVector3InterpolateCoords (
                                    tbVector3Cross (
                                        Vertex[i-17].Position-Vertex[i].Position,
                                        Vertex[i-16].Position-Vertex[i].Position),
                                    tbVector3Cross (
                                        Vertex[i-16].Position-Vertex[i].Position,
                                        Vertex[i-15].Position-Vertex[i].Position),
                                    0.5f),
                                0.5f),
                            0.5f);
    }
g_pVertexBuffer->SetVertices (0, 256, Vertex);
g_pVertexBuffer->Update ();
int x = 0;
for (int a = 0; a < 256; a++)
    {
    x = a;
    g_pIndexBuffer->SetIndex (6*a  , &x);
    x = a+16;
    g_pIndexBuffer->SetIndex (6*a+1, &x);
    x = a+17;
    g_pIndexBuffer->SetIndex (6*a+2, &x);
    x = a;
    g_pIndexBuffer->SetIndex (6*a+3, &x);
    x = a+17;
    g_pIndexBuffer->SetIndex (6*a+4, &x);
    x = a+1;
    g_pIndexBuffer->SetIndex (6*a+5, &x);
    }
g_pIndexBuffer->Update ();

g_Translation = tbMatrixTranslation (tbVector3 (0, 0, 0));
g_Rotation    = tbMatrixRotation (0, 0, 0);
g_Skalation   = tbMatrixScaling (tbVector3 (1, 1, 1));

g_World       = g_Skalation * g_Rotation * g_Translation;
g_Projection  = tbMatrixProjection (TB_DEG_TO_RAD (65.0f), 
                                    tbDirect3D::GetAspect (),
                                    0.1f, 
                                    250.0f);
g_View        = tbMatrixCamera (tbVector3 (80.0f, 80.0f, 100.0f),
                                tbVector3 (80.0f, 80.0f, 99.0f),
                                tbVector3 (0.0f,  1.0f,  0.0f));

tbDirect3D::SetTransform (D3DTS_WORLD, g_World);
tbDirect3D::SetTransform (D3DTS_PROJECTION, g_Projection);
tbDirect3D::SetTransform (D3DTS_VIEW, g_View);

D3DMATERIAL9 Material;

Material.Diffuse = tbColor (0.0f, 1.0f, 0.0f);
Material.Ambient = tbColor (0.0f, 0.0f, 0.1f);
Material.Specular = tbColor (0.0f, 0.0f, 0.0f);
Material.Emissive = tbColor (0.1f, 0.0f, 0.0f);
Material.Power = 1.0f;

tbDirect3D::SetMaterial (&Material);

D3DLIGHT9 Light;
ZeroMemory (&Light, sizeof(D3DLIGHT9));
Light.Type = D3DLIGHT_DIRECTIONAL;
Light.Diffuse = tbColor (1.0f, 1.0f, 1.0f);
Light.Specular = tbColor (1.0f, 0.0f, 0.0f);
Light.Direction = tbVector3 (-1.0f, -1.0f, 1.0f);

tbDirect3D::GetDevice()->SetLight (0, &Light);
tbDirect3D::GetDevice()->LightEnable (0, TRUE);

return TB_OK;
};
//*****************************************************************************

Anonymous

unregistriert

4

01.08.2003, 17:16

Hab jetzt noch

Quellcode

1
2
3
tbDirect3D::GetDevice()->SetStreamSource (0,                                                   g_pVertexBuffer->GetVB (),
                                                            0,                                 sizeof (SVertex));
tbDirect3D::GetDevice()->SetIndices (g_pIndexBuffer->GetIB ());

Jetzt wird ein Fehler ausgegeben, dass g_pVertexbuffer->GetVB nicht den passen´den Wert zurück gibt. Warum?

Werbeanzeige