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

23.11.2003, 17:40

Problem mit Multi texturing

Hi! Ich habe jetzt alle States für Multi Texturing eingestellt und auch die beiden texturen geladen.Aber irgendwie kommt dabei nur Mist heraus.Könnt ihr mir villeicht helfen?

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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#include <Windows.h>
#include <TriBase.h>
#include <D3DX9.h>
#include <D3D9.h>
#include "D:\TriBase\Beispiele\Allgemeines\InitWindow.h"
#include "D:\TriBase\Beispiele\Allgemeines\Direct3DEnum.h"
#include "D:\TriBase\Beispiele\Allgemeines\InitDirect3D.h"
#include "Resource.h"

// ******************************************************************
// Struktur für einen Vertex: Position, Farbe und Texturkoordinaten
struct SVertex
{
    tbVector3   vPosition;  // Position des Vertex
    tbVector3   vNormal;    // Farbe des Vertex
    tbVector2   vTexture;   // Texturkoordinaten
};

float fTime = 1.0f;
SDirect3DParameters g_Direct3DParameters;
SVertex g_aTriAngleVertex[8];
PDIRECT3DINDEXBUFFER9  g_pIndexBuffer = NULL;
PDIRECT3DTEXTURE9  g_pTexture[2];
PDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;
D3DMATERIAL9 Material;
D3DLIGHT9 Light;


tbResult InitScene()
{

    int* pusIndices;
    SVertex* pVertices;
    tbMatrix mProjection;
    float fAspect;


    //RenderStates
    g_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
    g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
    g_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);
    g_pD3DDevice->SetRenderState(D3DRS_AMBIENT, tbColor(0.5f, 0.0f, 0.0f));


    //Samplerstates
    g_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    g_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
    g_pD3DDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    g_pD3DDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    g_pD3DDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);


    //Multi Texturing Einstellungen für Textur1
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

    //Multi Texturingeinstellungen für die zweite Texturschicht
    g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
    g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED);

    g_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);



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

    fAspect = (float) (g_Direct3DParameters.VideoMode.Width)
            / (float) (g_Direct3DParameters.VideoMode.Height);
    mProjection = tbMatrixProjection(TB_DEG_TO_RAD(140.0f), fAspect, 100.0f, 0.1f);
    g_pD3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*) (&mProjection));

    //Textur setzen
    D3DXCreateTextureFromFileEx(g_pD3DDevice,
                               "Texture1.jpg",
                                D3DX_DEFAULT,
                                D3DX_DEFAULT,
                                D3DX_DEFAULT,
                                0,
                                D3DFMT_UNKNOWN,
                                D3DPOOL_MANAGED,
                                D3DX_FILTER_NONE,
                                D3DX_DEFAULT,
                                0,
                                NULL,
                                NULL,
                                &g_pTexture[0]);

    D3DXCreateTextureFromFileEx(g_pD3DDevice,
                               "Texture2.jpg", 
                                D3DX_DEFAULT,
                                D3DX_DEFAULT,
                                D3DX_DEFAULT,
                                0, 
                                D3DFMT_UNKNOWN,
                                D3DPOOL_MANAGED,
                                D3DX_FILTER_NONE,
                                D3DX_DEFAULT,
                                0,
                                NULL,
                                NULL,
                                &g_pTexture[1]);

    
    g_pD3DDevice->SetTexture(0, g_pTexture[0]);
    g_pD3DDevice->SetTexture(1, g_pTexture[1]);

    //Material erstellen und setzen
    Material.Diffuse = tbColor(1.0f, 0.0f, 0.0f);
    Material.Specular = tbColor(0.5f, 0.5f, 0.5f);
    Material.Ambient = tbColor(0.1f, 0.0f, 0.0f);
    Material.Emissive = tbColor(0.0f, 0.0f, 0.0f);
    Material.Power = 10.0f;

    g_pD3DDevice->SetMaterial(&Material);


    //Licht erstellen und setzen
    Light.Type = D3DLIGHT_POINT;
    Light.Diffuse = tbColor(1.0f, 1.0f, 1.0f);
    Light.Ambient = tbColor(1.0f, 1.0f, 1.0f);
    Light.Specular = tbColor(1.0f, 1.0f, 1.0f);
    Light.Position = tbVector3(0.0f, 0.05f, 0.0f);
    Light.Range = 1000.0f;
    Light.Attenuation0 = 0.0f;
    Light.Attenuation1 = 0.25f;
    Light.Attenuation2 = 0.0f;

    g_pD3DDevice->SetLight(0, &Light);
    g_pD3DDevice->LightEnable(0,TRUE);



    //Positionsangaben für die Vertices des Würfels generieren
    g_aTriAngleVertex[0].vPosition = tbVector3(-1.0f, 1.0f, -1.0f);
    g_aTriAngleVertex[1].vPosition = tbVector3(-1.0f, 1.0f, 1.0f);
    g_aTriAngleVertex[2].vPosition = tbVector3(1.0f, 1.0f, 1.0f);
    g_aTriAngleVertex[3].vPosition = tbVector3(1.0f, 1.0f, -1.0f);
    g_aTriAngleVertex[4].vPosition = tbVector3(-1.0f, -1.0f, -1.0f);
    g_aTriAngleVertex[5].vPosition = tbVector3(-1.0f, -1.0f, 1.0f);
    g_aTriAngleVertex[6].vPosition = tbVector3(1.0f, -1.0f, 1.0f);
    g_aTriAngleVertex[7].vPosition = tbVector3(1.0f, -1.0f, -1.0f);

    //Testurkoordinaten setzen
    for(int i = 0; i < 8; ++i)
    {
        g_aTriAngleVertex[i].vTexture = tbVector2Random();
    };


    //Die Indizes
   unsigned short aiIndex[36] = { 0, 3, 7,  0, 7, 4,
                                  2, 1, 5,  2, 5, 6,
                                  1, 0, 4,  1, 4, 5,
                                  3, 2, 6,  3, 6, 7,
                                  0, 1, 2,  0, 2, 3,
                                  6, 5, 4,  6, 4, 7 };




    //Index und Vertex Buffer erstellen
    g_pD3DDevice->CreateVertexBuffer(8*sizeof(SVertex), 0, D3DFVF_XYZ | D3DFVF_DIFFUSE |D3DFVF_TEX1, D3DPOOL_MANAGED, &g_pVertexBuffer, NULL);
    g_pD3DDevice->CreateIndexBuffer(36*2, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &g_pIndexBuffer, NULL);



    //Index und Vertex Buffer sperren
    g_pVertexBuffer->Lock(0, 0, (void**) (&pVertices), D3DLOCK_NOSYSLOCK);
    g_pIndexBuffer->Lock(0, 0, (void**) (&pusIndices), D3DLOCK_NOSYSLOCK);

    //Daten in den Vertex Buffer hineinkopieren
    memcpy(pVertices, g_aTriAngleVertex, sizeof(g_aTriAngleVertex));
    //Daten in den Index Buffer hineinkopieren
    memcpy(pusIndices, aiIndex, sizeof(aiIndex));

    g_pVertexBuffer->Unlock();
    g_pIndexBuffer->Unlock();



    return TB_OK;
}

tbResult Move(float fNumSecsPassed)
{
    fTime += 0.015f;
    return TB_OK;
}

tbResult ExitScene()
{
    g_pD3DDevice->SetTexture(0, NULL);
    TB_SAFE_RELEASE(g_pTexture[0]);
    TB_SAFE_RELEASE(g_pTexture[1]);
    TB_SAFE_RELEASE(g_pIndexBuffer);
    TB_SAFE_RELEASE(g_pVertexBuffer);
    g_pD3DDevice->SetStreamSource(0, NULL, 0, 0);
    g_pD3DDevice->SetIndices(NULL);
    return TB_OK;
}

tbResult ExitApplication()
{
    ExitScene();
    ExitDirect3D();
    ExitWindow();
    tbExit();
    return TB_OK;
}

tbResult Render(float fNumSecsPassed)
{
    tbMatrix mTranslation;
    tbMatrix mRotation1;
    tbMatrix mRotation;
    tbMatrix mWorld;
    tbMatrix mTexture;


    mRotation = tbMatrixRotationY(TB_DEG_TO_RAD(45.0f * fTime));
    mRotation1 = tbMatrixRotationZ(TB_DEG_TO_RAD(45.0f * fTime));
    mTranslation = tbMatrixTranslation(tbVector3(0, 0, 2));
    mWorld = mRotation1 * mRotation * mTranslation;
    g_pD3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*) (&mWorld));



    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 63), 1.0f, 0);


    g_pD3DDevice->BeginScene();

    //Den Vertex Buffer einsetzen
    g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(SVertex));

    //Den Index Buffer einsetzen
    g_pD3DDevice->SetIndices(g_pIndexBuffer);
    

    g_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

    g_pD3DDevice->EndScene();


    //Den Bildpuffer sichtbar machen
    g_pD3DDevice->Present(NULL, NULL, NULL, NULL);

    return TB_OK;
}



// ******************************************************************
// Initialisierungsfunktion
tbResult InitApplication()
{
    tbResult Result;

    // TriBase-Engine initialisieren
    tbInit();

    // Direct3D-Optionen abfragen (vom Benutzer gewählt)
    Result = GetDirect3DParameters(&g_Direct3DParameters);
    if(Result == TB_ERROR)
    {
        // Es trat ein Fehler auf!
        MessageBox(NULL, "Fehler beim Abzählen!", "Fehler",
                   MB_OK | MB_ICONEXCLAMATION);
        return TB_ERROR;
    }
    else if(Result == TB_CANCELED)
    {
        // Der Dialog wurde abgebrochen!
        return TB_CANCELED;
    }

    // Fenster initialisieren. Die Größe hängt vom gewählten
    // Videomodus ab, der in der Parameterstruktur gespeichert ist.
    if(InitWindow(g_Direct3DParameters.VideoMode.Width,
                  g_Direct3DParameters.VideoMode.Height,
                  "Beispielprogramm Nr. 4: Texturen",
                  LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1))))
    {
        // Fehler beim Erstellen des Fensters!
        MessageBox(NULL, "Fehler beim Erstellen des Fensters!",
                   "Fehler", MB_OK | MB_ICONEXCLAMATION);
        return TB_ERROR;
    }

    // Direct3D mit den abgefragten Einstellungen initialisieren
    if(InitDirect3D(&g_Direct3DParameters,
                    g_hWindow))
    {
        // Fehler!
        MessageBox(g_hWindow, "Fehler beim Initialisieren von Direct3D!",
                   "Fehler", MB_OK | MB_ICONEXCLAMATION);
        ExitApplication();
        return TB_ERROR;
    }

    // Szene initialisieren
    if(InitScene())
    {
        // Fehler!
        MessageBox(g_hWindow, "Fehler beim Initialisieren der Szene!",
                   "Fehler", MB_OK | MB_ICONINFORMATION);
        ExitApplication();
        return TB_ERROR;
    }

    // Alles OK!
    return TB_OK;
}

// ******************************************************************
// Windows-Hauptfunktion
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   char* pcCmdLine,
                   int iShowCmd)
{
    tbResult Result;

    // Initialisierung
    Result = InitApplication();
    if(Result == TB_CANCELED) return 0;
    else if(Result)
    {
        MessageBox(NULL, "Fehler beim Initialisieren der Anwendung!",
                   "Fehler", MB_OK | MB_ICONEXCLAMATION);
        return 1;
    }

    // Nachrichtenschleife
    tbDoMessageLoop(Render, Move);

    // Herunterfahren
    ExitApplication();

    return 0;
}

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

David Scherfgen

Administrator

Beiträge: 10 382

Wohnort: Hildesheim

Beruf: Wissenschaftlicher Mitarbeiter

  • Private Nachricht senden

2

23.11.2003, 18:06

Was ist denn der "Mist", der dabei rauskommt?
Am besten lädst Du mal einen Screenshot hoch oder beschreibst genauer, was nicht funktioniert. Vielleicht ist es ja richtig, so wie es ist, und Du hast nur die Texture-Stage-States auf unpassende Werte gesetzt?