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

koschka

Community-Fossil

Beiträge: 2 862

Wohnort: Dresden

Beruf: Student

  • Private Nachricht senden

21

09.05.2006, 20:42

zuerst werden Pixel im Backbuffer gesetzt, dann wird dieser mit dem Frontbuffer (das was du siehtst) geflippt, also "ausgetauscht".

T-VIRUS

Alter Hase

  • »T-VIRUS« ist der Autor dieses Themas

Beiträge: 548

Wohnort: Göttingen(West)/Nordhausen(Ost)

Beruf: Schüler

  • Private Nachricht senden

22

09.05.2006, 20:54

Ja okay das kannte ich ja schon :p
Ich versteh es nur nicht genau wie man mit Variablen zeinet :(
Meine Blog:)

Wer Bugs im Text findet kann sie melden, fix erscheint irgendwann :D

MFG T-VIRUS

koschka

Community-Fossil

Beiträge: 2 862

Wohnort: Dresden

Beruf: Student

  • Private Nachricht senden

23

09.05.2006, 20:56

WAs meinst du mit "Variablen zeichnet" ???

T-VIRUS

Alter Hase

  • »T-VIRUS« ist der Autor dieses Themas

Beiträge: 548

Wohnort: Göttingen(West)/Nordhausen(Ost)

Beruf: Schüler

  • Private Nachricht senden

24

09.05.2006, 21:17

Okay lassen wir das erstmal mit der Frage ;)

Aber ich hab wieder ein Problem!!!
Aus irgend einem Grund stürtzt mein Programm ab :(
Hier mal der Code:

//Main.cpp

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;
}


//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
#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


//Engine.cpp

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()
{
}


Hoffe ihr findet den Fehler :(
Ich glaube aber das es an der Sekondären Oberfläche liegt da ich sie nicht initalisieret hab da ich nicht weiß wie :(
Meine Blog:)

Wer Bugs im Text findet kann sie melden, fix erscheint irgendwann :D

MFG T-VIRUS

25

09.05.2006, 22:01

Solange du immer noch das extern da stehen hast sag ich garnix mehr :D
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

Lemming

Alter Hase

Beiträge: 550

Beruf: Schüler

  • Private Nachricht senden

26

09.05.2006, 23:41

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 :(
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 ;)...

in diesem dummies buch steht, aber drin, wie man die sekundäre oberfläche intialisiert. wenn auch in nicht so schönem code.. aber das wesentlich lässt sich trotzdem rauslesen...

außerdem :
-weg mit den externs ;)

-im konstruktor kannst du auch die member-initialisierung nutzen:

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


{
} 
Es gibt Probleme, die kann man nicht lösen.
Für alles andere gibt es C++...

T-VIRUS

Alter Hase

  • »T-VIRUS« ist der Autor dieses Themas

Beiträge: 548

Wohnort: Göttingen(West)/Nordhausen(Ost)

Beruf: Schüler

  • Private Nachricht senden

27

10.05.2006, 11:36

Geheiligt sei dieses Forum :)
Danke für den hinweis ;)

Leider ist das Dümmies buch auf C und nicht meinem geliebten C++ :'( aber ich gebe mein bestes damit es auch in meinem C++ Style(Der nich grad der beste ist) klappt :)
Meine Blog:)

Wer Bugs im Text findet kann sie melden, fix erscheint irgendwann :D

MFG T-VIRUS

Anonymous

unregistriert

28

10.05.2006, 11:42

@ T-VIRUS: Das bringt dich kein bisschen weiter, ich hab auch ne Zeit lang viel abgeschrieben. Klar du denkst, dann kannst du coole 3D Games machen, aber du solltest dann eher Gute 2D Games schreiben, die auch ganz und gar von dir sind als einfach ne 3D Engine mit total viel abgeschriebenen Code wovon das meiste sogar noch von den ganzen Usern hier berichtigt wurde. Bücher sind nicht dazu da um abzuschreiben, sonst wäre der Kauf ja sinnlos. Du kannst kleinere Pseudocodes abschreiben und dann mit denen herumprobieren, bis du genau die Funktion hast, die du haben willlst. Und glaub mir, so kommst du VIEL schneller zu deinem Ziel, die 3D Engine wird eh nicht laufen, wenn du so weiter machen, außerdem ist das kein Community Projekt.

Hoffe du nimmst dir das zu Herzen ;)

MfG DarkRaider

T-VIRUS

Alter Hase

  • »T-VIRUS« ist der Autor dieses Themas

Beiträge: 548

Wohnort: Göttingen(West)/Nordhausen(Ost)

Beruf: Schüler

  • Private Nachricht senden

29

10.05.2006, 11:53

@Darkraider:
Ich schreib doch keinen Code ab ;) Ich hab mir vieles selbst beigebracht :)

Außer dem soll das ne 2D Engine werden mit der ich ein kleines Game zusammen bauen werde :)

Bis ich eine coole 3D Engine geschrieben hab wird es eh noch ein langer weg sein ;)

Ich selbst versuche auch soviel wie möglich zulernen den das ab schreiben nichts bringt ist mir klar :P

Aber mal eine kleine Frage->Was ist den nun Pseudocode?
Ich hab schon einiges darüber gelesen aber schlau draus werd ich nicht :(

Okay hab mich in Wikipedia.de mal eingelesen und habs doch verstanden ;) ist doch simpler als ich dachte :)

Ich glaube etwas Pseudocode kann wirklich nicht schaden ;)

Hast dua auch ICQ dann würd ich mich mal mit dir unterhalten wie ich mich noch verbesern kann :)
Meine Blog:)

Wer Bugs im Text findet kann sie melden, fix erscheint irgendwann :D

MFG T-VIRUS

Anonymous

unregistriert

30

10.05.2006, 12:57

Mh ja hier: 285-762-736

Sorry, hatte wohl einiges falsch verstanden, aber mein letzter Beitrag kann ja anderen Usern auch nicht schaden ;)

MfG DarkRaider.

Werbeanzeige