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
*hust*
Wenn ich direkt in so ein Thema einsteige lerne ich besser und viel schneller.
Dh. ich lerne fast immer aus Bsp. und Tuts. oder Büchern.
Desshalb suche ich ein Buch, indem schon GrunkKenntnisse vorausgesetzt werden, und dann genau auf die SpieleProgrammierung eingegangen wird.
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 |
/************************************************** WinMain.cpp Chapter 2 2-D Drawing Demo (Draw2D) Programming Role-Playing Games with DirectX, 2nd Edition by Jim Adams (Jan 2004) Required libraries: D3D9.LIB and D3DX9.LIB **************************************************/ // Include files #include <windows.h> #include <stdio.h> #include "d3d9.h" #include "d3dx9.h" #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") // Window handles, class and caption text HWND g_hWnd; HINSTANCE g_hInst; static TCHAR g_szClass[] = L"Draw2DClass"; static TCHAR g_szCaption[] = L"Draw2D Demo by Jim Adams"; // The Direct3D and Device object IDirect3D9 *g_pD3D = NULL; IDirect3DDevice9 *g_pD3DDevice = NULL; // The 2-D vertex format and descriptor typedef struct { FLOAT x, y, z; // 2-D coordinates FLOAT rhw; // rhw FLOAT u, v; // Texture coordinates } sVertex; #define VERTEXFVF (D3DFVF_XYZRHW | D3DFVF_TEX1) // Vertex buffer IDirect3DVertexBuffer9 *g_pVB = NULL; // Texture IDirect3DTexture9 *g_pTexture = NULL; // Function prototypes int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, \ LPSTR szCmdLine, int nCmdShow); long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, \ WPARAM wParam, LPARAM lParam); BOOL DoInit(); BOOL DoShutdown(); BOOL DoFrame(); BOOL SetupMeshes(); int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, \ LPSTR szCmdLine, int nCmdShow) { WNDCLASSEX wcex; MSG Msg; g_hInst = hInst; // Create the window class here and register it wcex.cbSize = sizeof(wcex); wcex.style = CS_CLASSDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInst; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = NULL; wcex.lpszMenuName = NULL; wcex.lpszClassName = g_szClass; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wcex)) return FALSE; // Create the Main Window g_hWnd = CreateWindow(g_szClass, g_szCaption, WS_CAPTION | WS_SYSMENU, 0, 0, 400, 400, NULL, NULL, hInst, NULL ); if(!g_hWnd) return FALSE; ShowWindow(g_hWnd, SW_NORMAL); UpdateWindow(g_hWnd); // Run init function and return on error if(DoInit() == FALSE) return FALSE; // Start message pump, waiting for signal to quit ZeroMemory(&Msg, sizeof(MSG)); while(Msg.message != WM_QUIT) { if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } if(DoFrame() == FALSE) break; } // Run shutdown function DoShutdown(); UnregisterClass(g_szClass, hInst); return Msg.wParam; } long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, \ WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } BOOL DoInit() { D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; BYTE *Ptr; sVertex Verts[4] = { { 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, 0.0f }, { 350.0f, 50.0f, 1.0f, 1.0f, 1.0f, 0.0f }, { 50.0f, 350.0f, 1.0f, 1.0f, 0.0f, 1.0f }, { 350.0f, 350.0f, 1.0f, 1.0f, 1.0f, 1.0f } }; // Do a windowed mode initialization of Direct3D if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) return FALSE; if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) return FALSE; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = FALSE; if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice))) return FALSE; // Create the vertex buffer and set data g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex)*4, 0, \ VERTEXFVF, D3DPOOL_DEFAULT, \ &g_pVB, NULL); g_pVB->Lock(0,0, (void**)&Ptr, 0); memcpy(Ptr, Verts, sizeof(Verts)); g_pVB->Unlock(); // Load the texture map D3DXCreateTextureFromFileEx(g_pD3DDevice, L"Texture.bmp", D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, D3DCOLOR_RGBA(0,0,0,255), NULL, NULL, &g_pTexture); return TRUE; } BOOL DoShutdown() { // Release vertex buffer if(g_pVB != NULL) g_pVB->Release(); // Release texture if(g_pTexture != NULL) g_pTexture->Release(); // Release device and 3D objects if(g_pD3DDevice != NULL) g_pD3DDevice->Release(); if(g_pD3D != NULL) g_pD3D->Release(); return TRUE; } BOOL DoFrame() { // Clear device backbuffer g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, \ D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0); // Begin scene if(SUCCEEDED(g_pD3DDevice->BeginScene())) { g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true); g_pD3DDevice->SetRenderState(D3DRS_ALPHAREF, 0x01); g_pD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); // Set the vertex stream, shader, and texture g_pD3DDevice->SetStreamSource(0, g_pVB, 0, sizeof(sVertex)); g_pD3DDevice->SetFVF(VERTEXFVF); g_pD3DDevice->SetTexture(0, g_pTexture); // Draw the vertex buffer g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // Release texture g_pD3DDevice->SetTexture(0, NULL); g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); // End the scene g_pD3DDevice->EndScene(); } // Display the scene g_pD3DDevice->Present(NULL, NULL, NULL, NULL); return TRUE; } |
schicken?Zitat
#include "d3d9.h"
#include "d3dx9.h"
Werbeanzeige