tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
8
ZUGRIFFE
1677
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Nizomi Nizomi ist offline Mitglied Silber
    Registriert seit
    Apr 2004
    Beiträge
    64
    Hi,
    wie lasse ich DirectX im Fenster laufen?
    Wie ich mit DirectDraw probiert habe
    den Display Mode zu setzen kam ne Fehlermeldung zurück =/
    ich hab DDSCL_NORMAL Flag beim Cooperative Level gehabt
    und habe bei Display Mode angeben
    400,500,8,0

    also 400 breit, 500 groß und 8bit
    so groß wie das Fenster war...
     

  2. #2
    alixander alixander ist offline Mitglied Silber
    Registriert seit
    Mar 2004
    Beiträge
    70
    Wenn du DirectDraw im Fenstermodu verwenden willst, dann musst du unbedingt den Clipper für das Fenster aktivieren, da DirectDraw ansonsten nicht weiß, in welchen Bereich gezeichnet werden darf.
    Die Erzeugung des Clippers ist denkbar einfach

    Code :
    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
    
     
    lpdd = Zeiger auf das  DirectDrawObjekt;
    lpddsP =Zeichenoberfläche
     
    LPDIRECTDRAWCLIPPER lpddClip=NULL; //Zeiger auf den Clipper
     
    //nun das Clipper-Objekt anlegen und Rückgabewert abfangen
    if(FAILED(lpdd->CreateClipper(NULL,&lpddClip,NULL)))
    {
        //Fehlerbehandlung
    }
     
    //nun noch dem Clipper sagen zu welchem Fenster er gehört 
    if(FAILED(lpddClip->SetHWnd(0,Handle)))
    {
        //Fehlerbehandlung
    }
     
    //und als letztes den Clipper mit der Zeichenoberflächer verbinden
    if(FAILED(lpddsP->SetClipper(lpddClip)))
    {
      //Fehlerbehandlung
    }
     
    //und schon ist direct Draw bereit für den Fensterbetrieb
     

  3. #3
    Nizomi Nizomi ist offline Mitglied Silber
    Registriert seit
    Apr 2004
    Beiträge
    64
    hmm
    Ja und wohin das ganze?
    Ich habe keine Zeicheroberfläche (Surface) wenn ich kein Display Mode setten kann oder?
    =/
     

  4. #4
    Registriert seit
    Apr 2002
    Ort
    Delmenhorst (Niedersachsen)
    Beiträge
    3.567
    moin


    Wie siehts bei dir eigentlich mit den Grundlagen aus?
    Oder programmierst du gerade einfach mal drauf los?!


    mfg
    umbrasaxum
     

  5. #5
    Nizomi Nizomi ist offline Mitglied Silber
    Registriert seit
    Apr 2004
    Beiträge
    64
    Kommt nun drauf an was du mit Grundlagen meinst....
     

  6. #6
    Registriert seit
    Apr 2002
    Ort
    Delmenhorst (Niedersachsen)
    Beiträge
    3.567
    moin


    Z.B. Direct X in einem Fenster "laufen" lassen.


    mfg
    umbrasaxum
     

  7. #7
    Nizomi Nizomi ist offline Mitglied Silber
    Registriert seit
    Apr 2004
    Beiträge
    64
    Ich versteh grad nich was du meinst
    wie meine Grundfunktionen aufgebaut sind oda was? x-x
     

  8. #8
    Flegmon Flegmon ist offline Mitglied Brokat
    Registriert seit
    Aug 2004
    Beiträge
    351
    Er meint damit, ob du Ahnung von Direct Draw hast. Zum Displaymode. Den Deisplaymode brauchst du nur einstellen wenn du ein Vollbildprogramm machst!
    Zeichenoberfläche = Primäre Oberfläche!
     

  9. #9
    Nizomi Nizomi ist offline Mitglied Silber
    Registriert seit
    Apr 2004
    Beiträge
    64
    JA aber bisher nur mit Fullscreen hab bissel rumprobiert habe aber noch ein Problem
    meine Files:

    bouncy_main.cpp:
    Code :
    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
    
    #include <windows.h>
    #include <FreeImage.h>
    #include <ddraw.h>
    #include "bouncy_resource.h"
    #include "bouncy_functions.h"
    #include "bouncy_classes.h"
     
    BitMapObject bmoBall;
    BitMapObject bmoBackground;
    HBITMAP hBall;
    HWND hWnd;
    CBouncyBall BallClass;
     
    LPDIRECTDRAW7 lpDD;
    LPDIRECTDRAWSURFACE7 lpDDSPrimary;
    LPDIRECTDRAWSURFACE7 lpDDSBack;
    LPDIRECTDRAWCLIPPER  lpDDClipper;
     
    int Bouncy_Points;
    bool done;
    bool bRunGame;
     
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
        switch(message){
            case WM_SIZE:
            {
                SetWindowPos(hWnd,0,0,0,400,500,SWP_NOMOVE | SWP_NOZORDER);
                return(0);
            }break;
            case WM_COMMAND:
            {
                switch(LOWORD(wParam)){
                    case MENUID_CLOSE:
                    {
                        PostMessage(hWnd,WM_DESTROY,0,0);
                        return(0);
                    }break;
                }
            }break;
            case WM_KEYDOWN:
            {
            switch(wParam){
                case VK_ESCAPE:
                {
                    PostMessage(hWnd,WM_DESTROY,0,0);
                    return(0);
                }break;
            }
            }break;
            case WM_DESTROY:
            {
                done=true;
                return(0);
            }break;
            case WM_ACTIVATE:
            {
                if( LOWORD( wParam ) == WA_INACTIVE )
    {
        
        bRunGame = false;
    }
    else
    {
        
        bRunGame = true;
    }
            }break;
            default:break;
        }
        return(DefWindowProc(hWnd,message,wParam,lParam));
    }
    int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow){
        MSG message;
        WNDCLASSEX bouncyMain;
        bouncyMain.cbSize=sizeof(WNDCLASSEX);
        bouncyMain.style=CS_HREDRAW|CS_VREDRAW;
        bouncyMain.lpfnWndProc=WindowProc;
        bouncyMain.cbClsExtra=0;
        bouncyMain.cbWndExtra=0;
        bouncyMain.hInstance=hinst;
        bouncyMain.hIcon=LoadIcon(NULL,IDI_WINLOGO);
        bouncyMain.hCursor=LoadCursor(NULL,IDC_ARROW);
        bouncyMain.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
        bouncyMain.lpszMenuName=MAKEINTRESOURCE(MAIN_MENU);
        bouncyMain.lpszClassName="BouncyMainClass";
        bouncyMain.hIconSm=LoadIcon(NULL,IDI_WINLOGO);
        if(!RegisterClassEx(&bouncyMain))return(0);
        if(!(hWnd=CreateWindowEx(NULL,
                                 "BouncyMainClass",
                                 "Bouncy Ball",
                                 WS_BORDER | WS_SYSMENU | WS_VISIBLE,
                                 200, 200,
                                 400, 500,
                                 NULL,
                                 NULL,
                                 hinst,
                                 NULL)))return(0);
        ShowWindow(hWnd,SW_SHOWNORMAL);
        UpdateWindow(hWnd);
        if(!Bouncy_Init())return(0);
        FreeImage_Initialise(false);
        done=false;
        while(!done){
            while(PeekMessage(&message,hWnd,0,0,PM_REMOVE)){
                TranslateMessage(&message);
                DispatchMessage(&message);
            }
            GameLoop();
        }
        Bouncy_EndDDraw();
        PostQuitMessage(0);
        return(0);
    }
    bool Bouncy_Init(void){
        if(!Bouncy_InitDDraw())return(false);
        return(true);
    }
    bool Bouncy_InitDDraw(void){
        HRESULT ddrval;
        ddrval=DirectDrawCreateEx(NULL,(LPVOID *)&lpDD,IID_IDirectDraw7,NULL);
        if(ddrval!=DD_OK){
            return(false);
        }
        ddrval=lpDD->SetCooperativeLevel(hWnd,DDSCL_NORMAL);
        if(ddrval!=DD_OK){
            lpDD->Release();
            return(false);
        }
        DDSURFACEDESC2 ddsd;
        ZeroMemory(&ddsd,sizeof(ddsd));
        ddsd.dwSize=sizeof(ddsd);
        ddsd.dwFlags=DDSD_CAPS;
        ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE;
        ddrval=lpDD->CreateSurface(&ddsd,&lpDDSPrimary,NULL);
        if(ddrval!=DD_OK){
            lpDD->Release();
            return(false);
        }
    ZeroMemory(&ddsd, sizeof(ddsd));
     
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwWidth = 400; 
    ddsd.dwHeight = 500; 
    ddrval=lpDD->CreateSurface(&ddsd,&lpDDSBack,NULL);
    if(ddrval!=DD_OK){
        lpDD->Release();
        lpDDSPrimary->Release();
        return(false);
    }
    ddrval=lpDD->CreateClipper(0,&lpDDClipper,NULL);
    if(ddrval!=DD_OK){
        lpDD->Release();
        lpDDSPrimary->Release();
        lpDDSBack->Release();
        return(false);
    }
    ddrval=lpDDClipper->SetHWnd(0,hWnd);
    if(ddrval!=DD_OK){
        lpDDClipper->Release();
        lpDDSPrimary->Release();
        lpDDSBack->Release();
        lpDD->Release();
        return(false);
    }
    ddrval=lpDDSPrimary->SetClipper(lpDDClipper);
    if(ddrval!=DD_OK){
            lpDDClipper->Release();
        lpDDSPrimary->Release();
        lpDDSBack->Release();
        lpDD->Release();
        return(false);
    }
        return(true);
    }
    bool Bouncy_EndDDraw(void){
        if(lpDDSBack){
            lpDDSBack->Release();
            lpDDSBack=NULL;
        }
        if(lpDDSPrimary){
            lpDDSPrimary->SetClipper(NULL);
            lpDDClipper=NULL;
            lpDDSPrimary->Release();
            lpDDSPrimary=NULL;
        }
        if(lpDD){
            lpDD->Release();
            lpDD=NULL;
        }
        return(true);
    }
    bool GameLoop(){
        if(bRunGame){
            DrawAll();
        }
        return(true);
    }
    bool DrawAll(){
        DDSURFACEDESC2 ddsd;
        UCHAR *VRam;
        int Linewidth;
        int x,y;
        ZeroMemory(&ddsd,sizeof(ddsd));
        ddsd.dwSize=sizeof(ddsd);
        lpDDSBack->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT,NULL);
        Linewidth=ddsd.lPitch;
        VRam=(UCHAR *)ddsd.lpSurface;
        for(y=0;y<200;y++){
        for(x=0;x<200;x++){
            VRam[x+y*Linewidth]=245;
        }
        }
        lpDDSBack->Unlock(NULL);
        Bouncy_Flip();
        return(true);
    }
    bool Bouncy_Flip(void){
        RECT rect;
        ZeroMemory(&rect,sizeof(rect));
        GetClientRect(hWnd,&rect);
        POINT p1;
        POINT p2;
        p1.x=rect.left;
        p1.y=rect.top;
        p2.x=rect.right;
        p2.y=rect.bottom;
        ClientToScreen(hWnd,&p1);
        ClientToScreen(hWnd,&p2);
        rect.left=p1.x;
        rect.top=p1.y;
        rect.right=p2.x;
        rect.bottom=p2.y;
        lpDDSPrimary->Blt(&rect,lpDDSBack,NULL,DDBLT_WAIT,NULL);
        return(true);
    }
    bouncy_functions.h:
    Code :
    1
    2
    3
    4
    5
    6
    
    bool Bouncy_Init(void);
    bool GameLoop();
    bool DrawAll();
    bool Bouncy_InitDDraw(void);
    bool Bouncy_EndDDraw(void);
    bool Bouncy_Flip(void);
    bouncy_classes.h:
    Code :
    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
    
    #include <windows.h>
    class BitMapObject
    {
        private:
          HDC hdcMemory;
          HBITMAP hbmNewBitMap;
          HBITMAP hbmOldBitMap;
          int iWidth, iHeight;
        public:
          BitMapObject();
          ~BitMapObject();
          void Load(HDC hdcCompatible, HBITMAP hLoad);
          void Create(HDC hdcCompatible, int width, int height);
          void Destroy();
          int GetWidth();
          int GetHeight();
          operator HDC();
    };
     
    BitMapObject::BitMapObject()
    {
        hdcMemory=NULL;
        hbmOldBitMap=NULL;
        hbmNewBitMap=NULL;
        iWidth=0;
        iHeight=0;
    }
    BitMapObject::~BitMapObject(){
        if(hdcMemory)Destroy();
    }
    void BitMapObject::Load(HDC hdcCompatible, HBITMAP hLoad){
        if(hdcMemory)Destroy();
        hdcMemory=CreateCompatibleDC(hdcCompatible);
        hbmNewBitMap=hLoad;
        hbmOldBitMap=(HBITMAP)SelectObject(hdcMemory,hbmNewBitMap);
        BITMAP bmp;
        GetObject(hbmNewBitMap,sizeof(BITMAP),(LPVOID)&bmp);
        iWidth=bmp.bmWidth;
        iHeight=bmp.bmHeight;
    }
    void BitMapObject::Create(HDC hdcCompatible, int width, int height){
        if(hdcMemory)Destroy();
        hdcMemory=CreateCompatibleDC(hdcCompatible);
        hbmNewBitMap=CreateCompatibleBitmap(hdcCompatible,width,height);
        hbmOldBitMap=(HBITMAP)SelectObject(hdcMemory,hbmNewBitMap);
        iWidth=width;
        iHeight=height;
    }
    void BitMapObject::Destroy(){
        SelectObject(hdcMemory,hbmOldBitMap);
        DeleteObject(hbmNewBitMap);
        DeleteDC(hdcMemory);
        hdcMemory=NULL;
        hbmOldBitMap=NULL;
        hbmNewBitMap=NULL;
        iWidth=0;
        iHeight=0;
    }
    BitMapObject::operator HDC(){
        return(hdcMemory);
    }
    int BitMapObject::GetWidth(){
        return(iWidth);
    }
    int BitMapObject::GetHeight(){
        return(iHeight);
    }
     
    class CBouncyBall
    {
        private:
        float x,y;
        float vx,vy;
        public:
        CBouncyBall();
        ~CBouncyBall();
        bool SetX(float nx);
        bool SetY(float ny);
        float GetX();
        float GetY();
        float GetVX();
        float GetVY();
        bool SetVX(float nvx);
        bool SetVY(float nvy);
    };
    CBouncyBall::CBouncyBall(){
        x=y=0;
        vx=vy=0;
    }
    CBouncyBall::~CBouncyBall(){
        x=y=0;
        vx=vy=0;
    }
    float CBouncyBall::GetX(){
        return(x);
    }
    float CBouncyBall::GetY(){
        return(y);
    }
    bool CBouncyBall::SetX(float nx){
        x=nx;
        return(true);
    }
    bool CBouncyBall::SetY(float ny){
        y=ny;
        return(true);
    }
    bool CBouncyBall::SetVX(float nvx){
        vx=nvx;
        return(true);
    }
    bool CBouncyBall::SetVY(float nvy){
        vy=nvy;
        return(true);
    }
    float CBouncyBall::GetVX(){
        return(vx);
    }
    float CBouncyBall::GetVY(){
        return(vy);
    }
    bouncy_resource.rc:
    Code :
    1
    2
    3
    4
    5
    6
    
    #include "bouncy_resource.h"
     
    MAIN_MENU MENU
    {
        MENUITEM "&Close" MENUID_CLOSE
    }
    bouncy_resource.h:
    Code :
    1
    2
    
    #define MENUID_CLOSE 1001
    #define MAIN_MENU 1000

    so nun hab ich das Problem das aus welchem Grund auch immer ich beim Starten nur komische Grafikverzehrungen sehe =/
     

Ähnliche Themen

  1. C# und DirectX
    Von time-master im Forum Literatur
    Antworten: 0
    Letzter Beitrag: 26.03.06, 00:16
  2. DirectX
    Von DerAndere im Forum Microsoft Windows
    Antworten: 10
    Letzter Beitrag: 08.11.04, 21:54
  3. DirectX
    Von lindin im Forum VisualStudio & MFC
    Antworten: 5
    Letzter Beitrag: 15.07.04, 12:55
  4. directx sdk 8.0
    Von VIshNou im Forum C/C++
    Antworten: 1
    Letzter Beitrag: 20.03.02, 16:12