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

Schnitter

Treue Seele

  • »Schnitter« ist der Autor dieses Themas

Beiträge: 141

Wohnort: Remshalden

Beruf: Schüler

  • Private Nachricht senden

1

07.08.2007, 23:06

Problem mit CreateDevice

So, ich meld' mich auch mal wieder.
Und zwar versuche ich gerade, ohne die tribase-engine das Buch durchzumachen(nur zum Lernen). Ich hab die Matrix-Klasse geschrieben und auch die Vektor-Klasse.

Jetzt sieht mein Code so aus(Das erste Dreieck):

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
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
#include <d3dx9.h>
#include <d3d9.h>
#include "main.hpp"
#include <iostream>
#include <windows.h>
#include "CApplication.hpp"
#include "vector3.hpp"
#include "Matrix.hpp"
#include "Color.hpp"
#include <DXErr9.h>

IDirect3D9* pD3D;
IDirect3DDevice9* pDevice;
D3DPRESENT_PARAMETERS PP;
HWND hWnd;

int width = 800;
int height = 600;

float elapsed = 0.0f;



#define DEG_TO_RAD(x)       ((x) * 0.0174532925199432957692369076848f)  // Grad -> Bogenmaß




struct Vertex
{
    Vector3 pos;
    DWORD color;
};

Vertex gVertizes[3];


using namespace std;

void initPP();
bool initD3D();
void render( float seconds);
void move( float seconds);
bool initScene();





int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int showCmd)
{
    WNDCLASSEX wndClass;
    TCHAR name[] = TEXT("TEST");
    MSG msg;
    



    wndClass.cbSize         = sizeof(WNDCLASSEX);
    wndClass.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
    wndClass.lpfnWndProc    = MsgProc;
    wndClass.cbClsExtra     = 0;
    wndClass.cbWndExtra     = 0;
    wndClass.hInstance      = hInstance;
    wndClass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground  = (HBRUSH)(COLOR_WINDOW);
    wndClass.lpszMenuName   = NULL;
    wndClass.lpszClassName  = name;
    wndClass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

    if(RegisterClassEx(&wndClass) == 0)
    {
        MessageBox(hWnd, "Error: RegisterClassEx()", "Error!", MB_OK | MB_ICONERROR);
        return 0;
    }
    hWnd = CreateWindowEx(NULL, name, "Demo!", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            GetSystemMetrics(SM_CXSCREEN)/2-(width/2),
            GetSystemMetrics(SM_CYSCREEN)/2-(height/2),
            width, 
            height, 
            NULL, NULL, hInstance,
            NULL);

    if(hWnd == NULL)
    {
        MessageBox(hWnd, "CreateWindowEx() failed", "Error!", MB_OK | MB_ICONERROR);
        return 0;
    }



        initPP();
    if(!initD3D())
         return 0;

    initScene();



    ShowWindow(hWnd, SW_SHOW);

    RECT Rect;
    SetRect(&Rect, 0, 0, width, height);
    AdjustWindowRect(&Rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE);
    width = Rect.right - Rect.left;
    height = Rect.bottom - Rect.top;

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);

        render(elapsed);
        move( 0.1f );
    }

    UnregisterClass(name, hInstance);

    if(pD3D != NULL)
        pD3D->Release();

    if(pDevice != NULL)
        pDevice->Release();


    return (int) msg.wParam;

}


LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case (WM_PAINT):
        {
            //PAINTSTRUCT paint;


            //BeginPaint(hWnd, &paint);

            //FillRect(paint.hdc, &paint.rcPaint, reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)));

            //EndPaint(hWnd, &paint);

        }break;
    case (WM_KEYDOWN):
        {
            switch(wParam)
            {
            case VK_ESCAPE:
                PostMessage(hWnd, WM_CLOSE, 0, 0);
                return 0;
                break;
            }
        }break;
    case (WM_DESTROY):
        {
            PostQuitMessage(0);
            return 1;
        }break;
        

    default:
        break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
} 
bool initD3D()
{
    if(FAILED(pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
    {
        MessageBox(hWnd, "Fehler beim Erstellen der D3D-Schnittstelle!", "", MB_OK | MB_ICONERROR);
        return false;
    }
    HRESULT hr;

    if(FAILED(hr = pD3D->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        hWnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &PP,
        &pDevice)))
    {
        MessageBox(hWnd, "CreateDevice() failed!", "", MB_OK | MB_ICONERROR);
        MessageBox(hWnd, DXGetErrorDescription9(hr), "", MB_OK | MB_ICONERROR);
        return false;
    }


    return true;
}
void render( float seconds)
{
    Matrix mRotation(matrixRotationZ(DEG_TO_RAD(elapsed*90.0f)));
    Matrix mTranslation(matrixTranslation(Vector3(0.0f, 0.0f, 2.0f)));

    //Beide Matrizen kombinieren und als Weltmatrix einsetzen

    pDevice->SetTransform(D3DTS_WORLD, reinterpret_cast<D3DMATRIX*>(&(mRotation*mTranslation)));


    if(FAILED(pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 63), 1.0f, 0)))
    {
        MessageBox(hWnd, "Fehler beim clearen!", "", MB_OK | MB_ICONERROR);
        return;
    }



    pDevice->BeginScene();

    if(FAILED(pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, gVertizes, sizeof(Vertex))))
    {
        MessageBox(hWnd, "Fehler beim Rendern des Dreiecks!", "", MB_OK | MB_ICONERROR);
        return;
    }

    pDevice->EndScene();
    pDevice->Present(NULL, NULL, NULL, NULL);


}

void move(float seconds)
{
    elapsed += seconds;
}
void initPP()
{
    PP.Windowed                     = true;
    PP.hDeviceWindow                = hWnd;
    PP.SwapEffect                   = D3DSWAPEFFECT_DISCARD;
    PP.BackBufferFormat             = D3DFMT_UNKNOWN;
    PP.BackBufferWidth              = width;
    PP.BackBufferHeight             = height;
    PP.BackBufferCount              = 1;
    PP.MultiSampleType              = D3DMULTISAMPLE_4_SAMPLES;
    PP.MultiSampleQuality           = 0; 
    PP.EnableAutoDepthStencil       = false;
    PP.AutoDepthStencilFormat       = D3DFMT_D16;
    PP.Flags                        = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
    PP.FullScreen_RefreshRateInHz   = D3DPRESENT_RATE_DEFAULT;
    PP.PresentationInterval         = PP.Windowed ? D3DPRESENT_INTERVAL_IMMEDIATE : D3DPRESENT_INTERVAL_ONE;

}
bool initScene()
{
    if(FAILED(pDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE)))
    {
        MessageBox(hWnd, "setFVF() failed!", "", MB_OK | MB_ICONERROR);
        return false;
    }
    pDevice->SetRenderState(D3DRS_LIGHTING, false); 
    pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

    float aspect = static_cast<float>(width) / static_cast<float>(height);
    
    Matrix mProjection = matrixProjection(DEG_TO_RAD(90.0f), aspect, 0.1f, 100.0f);

    //Einsetzen

    pDevice->SetTransform(D3DTS_PROJECTION, reinterpret_cast<D3DMATRIX*>(&mProjection));


    gVertizes[0].pos   = Vector3(0.0f, 1.0f, 0.0f);
    gVertizes[1].pos   = Vector3(1.0f, -1.0f, 0.0f);
    gVertizes[2].pos   = Vector3(-1.0f, -1.0f, 0.0f);

    gVertizes[0].color = Color(1.0f, 0.0f, 0.0f);
    gVertizes[1].color = Color(0.0f, 1.0f, 0.0f);
    gVertizes[2].color = Color(0.0f, 0.0f, 1.0f);






    return true;
}

Ich bekomme direkt am Anfang den Error, dass CreateDevice() failed, und die ErrorDescription: Invalid Call. Ich kann' mir darunter relativ wenig vorstellen, probier aber schon seit Tagen damit herum, komm' aber nicht auf den Fehler.


Hoffe, einer von euch sieht ihn.

ChrisJ

Alter Hase

Beiträge: 487

Wohnort: Schweich

Beruf: Schüler

  • Private Nachricht senden

2

08.08.2007, 00:18

C-/C++-Quelltext

1
PP.BackBufferFormat = D3DFMT_UNKNOWN;


darf man das?
"Don't trust your eyes: They are a hell of a lot smarter than you are"

Schnitter

Treue Seele

  • »Schnitter« ist der Autor dieses Themas

Beiträge: 141

Wohnort: Remshalden

Beruf: Schüler

  • Private Nachricht senden

3

08.08.2007, 00:22

Das kommt von hier:
http://zfx.info/Tutorials.php?ID=62

Und, da ich es ja im Fenstermodus laufen lasse, hab ich das eben auf UNKNOWN gesetzt.

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

4

08.08.2007, 09:38

Überprüf mal ob deine D3DPRESENT_PARAMETERS für deine Hardware gültige Angaben haben. Kannst dir ja ne Liste der möglichen Display Modi ausgeben lassen.
@D13_Dreinig

ThomasS

Frischling

Beiträge: 50

Wohnort: Landshut

Beruf: Student

  • Private Nachricht senden

5

08.08.2007, 11:07

Wenn CreateDevice() fehlschlägt, steht der Grund normalerweise in den Debug-Ausgaben von DirectX, die man über die Systemsteuerung aktivieren kann (ist im Buch beschrieben).

Werbeanzeige