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
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 |
// INCLUDES /////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN #define INITGUID #include <windows.h> //Eigene Includes: #include "Engine.h" HWND main_window_handle = NULL; HINSTANCE main_instance = NULL; char buffer[80]; LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = WINDOW_CLASS_NAME; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, WINDOW_CLASS_NAME, WINDOW_CLASS_NAME, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); UpdateWindow(hwnd); main_window_handle = hwnd; main_instance = hThisInstance; CEngine Engine; //Spiel starten: Engine.InitGame(); // Spielschleife: while(1) { if (PeekMessage(&messages,NULL,0,0,PM_REMOVE)) { if (messages.message == WM_QUIT) break; TranslateMessage(&messages); DispatchMessage(&messages); } //Hier läuft das Spiel ab: Engine.MainGame(); } //Hier wird das Spiel herrunter gefahren: Engine.ShutdownGame(); return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (message) { case WM_CREATE: break; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } |
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 |
#ifndef Engine_H #define Engine_H //Compilierer Includes: #include <windows.h> //Eigene Includes: #include "DirectX/ddraw.h" // DEFINES //////////////////////////////////////////////// // defines for windows const char WINDOW_CLASS_NAME[20]="Game"; // class name const unsigned long WINDOW_WIDTH=800; // size of window const unsigned long WINDOW_HEIGHT=600; const unsigned long SCREEN_WIDTH=800; // size of screen const unsigned long SCREEN_HEIGHT=600; const unsigned long SCREEN_BPP=16; // bits per pixel // MACROS ///////////////////////////////////////////////// // these read the keyboard asynchronously #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) // this builds a 16 bit color value in 5.5.5 format (1-bit alpha mode) #define _RGB16BIT555(r,g,b) ((b & 31) + ((g & 31) << 5) + ((r & 31) << 10)) // this builds a 16 bit color value in 5.6.5 format (green dominate mode) #define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11)) // TYPES ////////////////////////////////////////////////// class CEngine { public: //Konstruktor/Destruktor: CEngine(); ~CEngine(); //Spiel starten: void InitGame(); //Fenster Stuff: void InitWindow(); //Grafik Stuff: void InitDirectDraw(); void InitPrimarySurface(); void InitSecondarySurface(); //Tastatur(Eingaben)Stuff: void InitDirectInput(); //SoundStuff: void InitDirectSound(); //Hauptteil des Spiels: void MainGame(); //Spiel beenden: void ShutdownGame(); //Fenster Stuff: void ReleaseWindow(); //Grafik Stuff: void ReleaseDirectDraw(); void ReleasePrimarySurface(); void ReleaseSecondarySurface(); //Tastatur(Eingaben)Stuff: void ReleaseDirectInput(); //SoundStuff: void ReleaseDirectSound(); private: //DirectX Stuff: LPDIRECTDRAW7 lpdd; // dd object LPDIRECTDRAWSURFACE7 lpddsprimary; // dd primary surface LPDIRECTDRAWSURFACE7 lpddsback; // dd back surface LPDIRECTDRAWPALETTE lpddpal; // a pointer to the created dd palette DDSURFACEDESC2 ddsd; // a direct draw surface description struct DDSCAPS2 ddscaps; // a direct draw surface capabilities struct HRESULT ddrval; // result back from dd calls }; #endif //Engine_H |
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 |
#include "Engine.h" //Fenster Hanlder: extern HWND main_window_handle; extern HINSTANCE main_instance; extern char buffer[80]; //Konstruktor/Destruktor: CEngine::CEngine() { lpdd = NULL; // dd object lpddsprimary = NULL; // dd primary surface lpddsback = NULL; // dd back surface lpddpal = NULL; // a pointer to the created dd palette } CEngine::~CEngine() { } //Grafik Stuff: void CEngine::InitGame() { InitDirectDraw(); InitPrimarySurface(); InitSecondarySurface(); InitDirectSound(); InitDirectInput(); } void CEngine::InitDirectDraw() { // this function is where you do all the initialization // for your game // create object and test for error if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK) { MessageBox(main_window_handle, "Das DirectX Objekt konnte nicht erstellt werden!", "Fehler beim erstellen des DX Objekts", MB_OK); PostMessage(main_window_handle, WM_DESTROY,0,0); } // set cooperation level to windowed mode normal if ((lpdd->SetCooperativeLevel(main_window_handle, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))!=DD_OK) { MessageBox(main_window_handle, "Die Kooperationsebene konnte nicht gesetzt werden!", "Kooperationsfehler", MB_OK); PostMessage(main_window_handle, WM_DESTROY,0,0); } // set the display mode if ((lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,16,0,0))!=DD_OK) { MessageBox(main_window_handle, "Die Bildschrimgröße konnte nicht angepasst werden!", "Display Fehler", MB_OK); PostMessage(main_window_handle, WM_DESTROY,0,0); } } void CEngine::InitPrimarySurface() { // Create the primary surface memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // set the flags to validate both the capabilities // field and the backbuffer count field ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // we need to let dd know that we want a complex // flippable surface structure, set flags for that ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; // set the backbuffer count to 1 ddsd.dwBackBufferCount = 1; if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK) { MessageBox(main_window_handle,"Die Primäroberfäche konnte nicht erstellt werden!", "Fehler beim erstellen der Primär Oberfläche",MB_OK); PostMessage(main_window_handle, WM_DESTROY,0,0); } // query for the backbuffer or secondary surface // notice the use of ddscaps to indicate what // we are requesting ddscaps.dwCaps = DDSCAPS_BACKBUFFER; // get the surface lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback); } void CEngine::InitSecondarySurface() { } //Tastatur(Eingaben)Stuff: void CEngine::InitDirectInput() { } //SoundStuff: void CEngine::InitDirectSound() { } //Spielteil: void CEngine::MainGame() { // check of user is trying to exit if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE)) { MessageBox(main_window_handle, "Spiel wurde unterbrochen!", "Spiel wird beendet!", MB_OK); PostMessage(main_window_handle, WM_DESTROY,0,0); } // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! USHORT *back_buffer = NULL, // used to draw *dest_ptr = NULL, // used in line by line copy *src_ptr = NULL; // " " // erase secondary back buffer memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // lock the secondary surface lpddsback->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL); // get video pointer to secondary surface back_buffer = (USHORT *)ddsd.lpSurface; // clear back buffer out, remember in 16bit mode there are // 2 bytes per pixel, so watch out for addressing and multiplying // issues in this code // linear memory if (ddsd.lPitch == SCREEN_WIDTH*2) memset(back_buffer,0,SCREEN_WIDTH*SCREEN_HEIGHT*(SCREEN_BPP/8)); else { // non-linear memory // make copy of video pointer dest_ptr = back_buffer; // clear out memory one line at a time for (int y=0; y < SCREEN_HEIGHT; y++) { // clear next line memset(dest_ptr,0,SCREEN_WIDTH*(SCREEN_BPP/8)); // advance pointer to next line dest_ptr+=(ddsd.lPitch/2); } // end for y } // end else // perform game logic... // draw the next frame into the secondary back buffer // plot 5000 random pixels for (unsigned int index = 0; index < 5000; index++) { int x = rand()%SCREEN_WIDTH; int y = rand()%SCREEN_HEIGHT; UCHAR red = rand()%256; UCHAR green = rand()%256; UCHAR blue = rand()%256; // back_buffer is a short pointer, BUT lpitch is in bytes // so divide by 2, to get number of "pixels" or words back_buffer[x+y*(ddsd.lPitch/2)] = _RGB16BIT565(red, green, blue); } // end for index // unlock secondary buffer lpddsback->Unlock(NULL); // flip pages if(lpddsprimary->Flip(NULL, DDFLIP_WAIT)!=DD_OK) { MessageBox(main_window_handle,"Es gab einen Fehler beim flippen!", "Flipping Fehler!",MB_OK); PostMessage(main_window_handle, WM_DESTROY,0,0); } } //Spielbeenden: void CEngine::ShutdownGame() { ReleaseSecondarySurface(); ReleasePrimarySurface(); ReleaseDirectDraw(); ReleaseDirectInput(); ReleaseDirectSound(); } //Fenster Stuff: void CEngine::ReleaseWindow() { main_window_handle=NULL; main_instance=NULL; } //Grafik Stuff: void CEngine::ReleaseDirectDraw() { // this function is where you shutdown your game and // release all resources that you allocated // release the directdraw object if (lpdd!=NULL) lpdd->Release(); } void CEngine::ReleasePrimarySurface() { // first release the primary surface if (lpddsprimary!=NULL) lpddsprimary->Release(); } void CEngine::ReleaseSecondarySurface() { // first release the secondary surface if(lpddsback!=NULL) lpddsback->Release(); } //Tastatur(Eingaben)Stuff: void CEngine::ReleaseDirectInput() { } //SoundStuff: void CEngine::ReleaseDirectSound() { } |
logisch. du hast keine sekundäre oberfläche. beim rendern versuchst du aber sie zu sperren und danach mit memset zu beschreiben. das erzeugt ne zugrifssverletzung und das proggie semmelt ab ...Zitat von »"T-VIRUS"«
Ich glaube aber das es an der Sekondären Oberfläche liegt da ich sie nicht initalisieret hab da ich nicht weiß wie
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
//Konstruktor: CEngine::CEngine(): lpdd(NULL), // dd object lpddsprimary(NULL), // dd primary surface lpddsback(NULL), // dd back surface lpddpal(NULL) // a pointer to the created dd palette { } |
Anonymous
unregistriert
Anonymous
unregistriert
Werbeanzeige