Форум программистов, компьютерный форум CyberForum.ru

Перенос из directx8 в directx9, ошибка в SetVertexShader - C++

Восстановить пароль Регистрация
 
vovanexe
Сообщений: n/a
16.05.2014, 22:14     Перенос из directx8 в directx9, ошибка в SetVertexShader #1
Доброе время суток.
Есть кусок кода написанного для directx8

C++
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
#include <d3dx8.h>
#include <mmsystem.h>
#include <C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\WinNT.h>
#include <d3dx8mesh.h>
#include <Windows.h>
#include "C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Include\dinput.h"
 
 
 
 
 
#include <windows.h>
#include <dinput.h>
#include <utility>
#include <vector>
 
 
 
////////////////////////////////////////////////////
#pragma comment(lib, "d3d8.lib")
#pragma comment(lib, "d3dx8.lib")
#pragma comment (lib,"dinput8.lib")
#pragma comment (lib,"dxguid.lib")
#include <stdio.h>
 
#pragma comment(lib, "D3d8.lib") //directX 8
#pragma comment(lib, "D3dx8.lib")
#include <d3dx8.h>
 
 
LPDIRECT3D8 g_pD3D = NULL;
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;
 
 
void init(HWND hWnd)
{
    //First of all, create the main D3D object. If it is created successfully we 
    //should get a pointer to an IDirect3D8 interface.
    g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
 
    //Get the current display mode
    D3DDISPLAYMODE d3ddm;
    g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
 
    //Create a structure to hold the settings for our device
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
 
    //Fill the structure. 
    //We want our program to be windowed, and set the back buffer to a format
    //that matches our current display mode
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = d3ddm.Format;
 
    //For depth buffering (e.g.) the z-buffer
    d3dpp.BackBufferCount = 1;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.EnableAutoDepthStencil = TRUE;
 
    //Create a Direct3D device.
    g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice);
 
        //Turn on back face culling. This is becuase we want to hide the back of our polygons
    g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
 
 
    //Turn on z-buffering
    g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
 
 
 
}
 
void de_init()
{
    g_pD3DDevice->Release();
    g_pD3DDevice = NULL;
 
    g_pD3D->Release();
    g_pD3D = NULL;
}
 
 
 
// The function takes the position of our pyramid in our world and renders
// it... simple as that!.
void draw_pyramid(float x, float y, float z)
{
    struct my_vertex
    {
        FLOAT x, y, z;  // D3DFVF_XYZ
        DWORD colour;   // D3DFVF_DIFFUSE
    };
    my_vertex v[] =
    {
        { -0.5f + x, -0.5f + y, 0.5f + z, 0x11111111 },  //[1] - front
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xff00ff00 },  //[2]
        { 0.5f + x, -0.5f + y, 0.5f + z, 0xff33f9ff },  //[3]
 
        { 0.5f + x, -0.5f + y, -0.5f + z, 0x33333333 },  //    - back
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xffff2200 },  //
        { -0.5f + x, -0.5f + y, -0.5f + z, 0xfff00000 },  //
 
        { -0.5f + x, -0.5f + y, -0.5f + z, 0xffffff11 },  //    - left
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xffff2200 },  //
        { -0.5f + x, -0.5f + y, 0.5f + z, 0xff88ff00 },  //
 
        { 0.5f + x, -0.5f + y, 0.5f + z, 0xffffff00 },  //    - right
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xff222200 },  //
        { 0.5f + x, -0.5f + y, -0.5f + z, 0xffaaff00 }   //
    };
    UINT my_vertex_description = (D3DFVF_XYZ | D3DFVF_DIFFUSE);
 
    IDirect3DVertexBuffer8 * DX_vb;
    g_pD3DDevice->CreateVertexBuffer(sizeof(v), 0, my_vertex_description, D3DPOOL_MANAGED, &DX_vb);
 
    // Copy our array which is in computer memory over to the directX memory.. using that pointer we
    // just created etc.
    unsigned char *temp_pointer_vb;
    DX_vb->Lock(0, 0, &temp_pointer_vb, 0);
    memcpy(temp_pointer_vb, v, sizeof(v));
    DX_vb->Unlock();
 
    g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
 
    // Draw our triangle.
    g_pD3DDevice->SetStreamSource(0, DX_vb, sizeof(my_vertex));
    g_pD3DDevice->SetVertexShader(my_vertex_description);
    g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4);
 
    DX_vb->Release();
}
 
 
// Not really done much matrix stuff yet!.. but be patient!
void Render()
{
    if (!g_pD3DDevice)return;
 
    // Clear the back buffer to a blue color
    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
 
    // These few lines of code is so that our 3D pyramid rotates while the program is running.
    static float angle = 0.0f;
    angle += 0.0005f;
    //~~~*~~~~ Create a matrix
    D3DXMATRIX mx;
    //~~~*~~~~ Do somthing to our empty matrix.
    D3DXMatrixRotationY(&mx, angle); // angle in radians...eg. 1 degree = PI/180
    //~~~*~~~~ Use the matrix! No use having a matrix if we don't use it!
    g_pD3DDevice->SetTransform(D3DTS_WORLD, &mx);
    
 
    // CALL OUR PYRAMID FUCTION HERE!!!!!!!!!
    draw_pyramid(0.0f, 0.0f, 0.0f);
    // After rendering the scene we display it.
    g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
 
void mainloop()
{
    Render();
}
 
 
 
 
 
long _stdcall MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if (uMsg == WM_DESTROY)
    {       de_init();
        PostQuitMessage(0);
    }
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
 
 
int _stdcall WinMain(HINSTANCE i, HINSTANCE, char* k, int)
{
    MSG msg;
    char szname[] = "DirectX3D";
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
        GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
        szname, NULL };
    RegisterClassEx(&wc);
    HWND hWnd = CreateWindowEx(WS_EX_APPWINDOW,
        szname, "Pyramid",
        WS_OVERLAPPEDWINDOW,//for fullscreen make into WS_POPUP
        50, 50, 600, 600, //for full screen GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
        GetDesktopWindow(), NULL, wc.hInstance, NULL);
 
    // Initilise or directX code here!
    // INIT OUR DIRECTX ONCE HERE AT THE START HERE!!!!!!!!!!!!!!!!!!!!!!!!!
    init(hWnd);
 
    ShowWindow(hWnd, SW_SHOW);
    UpdateWindow(hWnd);
 
 
    // Message loop. Note that this has been modified to allow
    // us to execute if no messages are being processed.
    while (1)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        {
            if (!GetMessage(&msg, NULL, 0, 0))
                break;
            DispatchMessage(&msg);
        }
 
        // Idle-time processing - call our loop function in game.cpp
        // CALLING OUR DIRECTX CODE IN GAME.CPP FROM HERE!!!!!!!!!!!!!!!!!
        mainloop();
    }
    return 0;
}
При переносе в directx9 кое где менял синтаксис, но не могу понять что делать тут,

ругается на g_pD3DDevice->SetVertexShader(my_vertex_description); (108 строка)
получаю ошибки:
error C2664: "HRESULT IDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9 *)": невозможно преобразовать аргумент 1 из "HRESULT" в "IDirect3DVertexShader9 *"
ntelliSense: аргумент типа "HRESULT" несовместим с параметром типа "IDirect3DVertexShader9 *"


то что перенес в 9-ый

C++
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
/////////////////////////////////////////////////////////////////////////////////////////////////////
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pD3DDevice = NULL;
 
 
 
void init(HWND hWnd)
{
    //First of all, create the main D3D object. If it is created successfully we 
    //should get a pointer to an IDirect3D8 interface.
    g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
 
    //Get the current display mode
    D3DDISPLAYMODE d3ddm;
    g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
 
    //Create a structure to hold the settings for our device
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
 
    //Fill the structure. 
    //We want our program to be windowed, and set the back buffer to a format
    //that matches our current display mode
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = d3ddm.Format;
 
    //For depth buffering (e.g.) the z-buffer
    d3dpp.BackBufferCount = 1;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.EnableAutoDepthStencil = TRUE;
 
    //Create a Direct3D device.
    g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice);
 
    /*
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    g_pD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
    g_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    g_pD3DDevice->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_LINEAR);
    g_pD3DDevice->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_LINEAR);
    */
    //Turn on back face culling. This is becuase we want to hide the back of our polygons
    g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
 
 
    //Turn on z-buffering
    g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
 
 
 
}
 
void de_init()
{
    g_pD3DDevice->Release();
    g_pD3DDevice = NULL;
 
    g_pD3D->Release();
    g_pD3D = NULL;
}
 
 
void draw_pyramid(float x, float y, float z)
{
    struct my_vertex
    {
        FLOAT x, y, z;  // D3DFVF_XYZ
        DWORD colour;   // D3DFVF_DIFFUSE
    };
    my_vertex v[] =
    {
        { -0.5f + x, -0.5f + y, 0.5f + z, 0x11111111 },  //[1] - front
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xff00ff00 },  //[2]
        { 0.5f + x, -0.5f + y, 0.5f + z, 0xff33f9ff },  //[3]
 
        { 0.5f + x, -0.5f + y, -0.5f + z, 0x33333333 },  //    - back
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xffff2200 },  //
        { -0.5f + x, -0.5f + y, -0.5f + z, 0xfff00000 },  //
 
        { -0.5f + x, -0.5f + y, -0.5f + z, 0xffffff11 },  //    - left
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xffff2200 },  //
        { -0.5f + x, -0.5f + y, 0.5f + z, 0xff88ff00 },  //
 
        { 0.5f + x, -0.5f + y, 0.5f + z, 0xffffff00 },  //    - right
        { 0.0f + x, 0.5f + y, 0.0f + z, 0xff222200 },  //
        { 0.5f + x, -0.5f + y, -0.5f + z, 0xffaaff00 }   //
    };
    HRESULT my_vertex_description = (D3DFVF_XYZ | D3DFVF_DIFFUSE);
 
    IDirect3DVertexBuffer9 * DX_vb;
    g_pD3DDevice->CreateVertexBuffer(sizeof(v), 0, my_vertex_description, D3DPOOL_MANAGED, &DX_vb, NULL);
 
    // Copy our array which is in computer memory over to the directX memory.. using that pointer we
    // just created etc.
    unsigned char *temp_pointer_vb;
    DX_vb->Lock(0, 0, reinterpret_cast<void**>(&temp_pointer_vb), 0);
    memcpy(temp_pointer_vb, v, sizeof(v));
    DX_vb->Unlock();
 
    g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
 
 
    // Draw our triangle.
    g_pD3DDevice->SetStreamSource(0, DX_vb, sizeof(my_vertex),0);
    g_pD3DDevice->SetVertexShader(my_vertex_description);
    g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4);
 
    DX_vb->Release();
}
 
 
// Not really done much matrix stuff yet!.. but be patient!
void Render()
{
    if (!g_pD3DDevice)return;
 
    // Clear the back buffer to a blue color
    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
 
    // These few lines of code is so that our 3D pyramid rotates while the program is running.
    static float angle = 0.0f;
    angle += 0.0005f;
    //~~~*~~~~ Create a matrix
    D3DXMATRIX mx;
    //~~~*~~~~ Do somthing to our empty matrix.
    D3DXMatrixRotationY(&mx, angle); // angle in radians...eg. 1 degree = PI/180
    //~~~*~~~~ Use the matrix! No use having a matrix if we don't use it!
    g_pD3DDevice->SetTransform(D3DTS_WORLD, &mx);
 
 
    // CALL OUR PYRAMID FUCTION HERE!!!!!!!!!
    draw_pyramid(0.0f, 0.0f, 0.0f);
    // After rendering the scene we display it.
    g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
 
void mainloop()
{
    Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Что надо изменить в g_pD3DDevice->SetVertexShader что б наступило счастье?
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
16.05.2014, 22:14     Перенос из directx8 в directx9, ошибка в SetVertexShader
Посмотрите здесь:

C++ Где скачать DirectX9 SDK???
C++ Перенос битов
C++ DirectX9 Direct3D
C++ Перенос кода
перенос кода в С++ C++
C++ Первый опыт с DirectX9. Странное поведение программы
Перенос массива в функцию и еще одна ошибка C++
Перенос кода на C++11 C++

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
Ответ Создать тему
Опции темы

Текущее время: 05:55. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru