Èñâ¸ÞÀÎ

 

 

½ºÅ©¸³ÅͶõ?

directXÀÇ ¼Ò°³

 

 

direct»ý¼º,ÇÁ·Î¼¼¼­µ¶Á¡,¸ðµå¼ÂÆÃ

´ÙÀÌ·ºÆ®¹öÆÛ»ý¼º Àü¹Ý¿¡ ´ëÇØ

 

 

¸éÀÇ »ý¼º°ú Çø®ÇÎ,ºñÆ®¸Êº¹»ç

´ÙÀÌ·ºÆ® ÆÄ·¿Æ® °ü¸®

 

 

Lock,unlock,Blt,BltFast

Direct Sound

 

 

 

 

 

     

   À̹ø¿¡´Â ´ÙÀÌ·ºÆ® ¹öÆÛ »ý¼º°ú ºñÆ®¸Ê¿¡ °üÇؼ­ ¾Ë¾Æ º¾½Ã´Ù.
        ±×Àü¿¡ Áö³­¹ø¿¡ Çß´ø °Í¿¡ ´ëÇÏ¿© Àá½Ã »ìÆì º¸°í °©½Ã´Ù.

        // 1Â÷ Ç¥¸é(Primary Surface)¸¸ »ý¼ºÇϱâ
        LPDIRECTDRAWSURFACE lpPrimary;
        DDSURFACEDESC           ddsd;

        ZeroMemory(&ddsd, sizeof(ddsd));
        ddsd.dwSize = sizeof(ddsd);
        ddsd.dwFlags = DDSD_CAPS;
        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
        lpDD->CreateSurface(&ddsd, &lpPrimary, NULL);

        À×? Áö³­¹ø°Å¿Í´Â ´Ù¸¥µ¥....--;
        ´Ù¸¥°Í ¾îº¸ÀÌ¿¹¿ä~ ´ÜÁö ÇÔ¼ö Çϳª°¡ ÀÖÁÒ? ¸Þ¸ð¸®¸¦ Ŭ¸®¾î
        ÇØÁÖ´Â ÇÔ¼ö¹Û¿¡...

        LPDIRECTDRAWSURFACE´Â IDirectDrawSurfaceÀÇ Æ÷ÀÎÅÍ ÇüÀÔ´Ï´Ù.
        ÂÁ~ DDSURFACEDESC´Â »ý¼ºµÉ Ç¥¸éÀÇ Æ¯¼ºÀ» ¾Ë·ÁÁÖ´Â ±¸ÃÊüÀÔ
    ´Ï´Ù.
        À½... ¹¹~´Ù¸¥°ÍÀº ¾îºÌÀÌÁÒ~

        Áö³­¹ø¿¡ »©¸ÔÀº °ÍÀÌ ÀÖÁÒ~ ¹»±î¿ä? ¹»±î? ¹»±î.....(²ôÀû~²ôÀû~)
        Áö²û±îÁö »ý¼º½ÃŲ °ÍÀ» Á¾·á½ÃÄÑ¾ß °ÚÁÒ~
        Á¦°ÅÇÏ´Â ¹æ¹ýÀº...

        lpPrimary->Release();                
        lpDD->Release();

        ¿ä°Å...¹Ù·Î ¿ä°Å¶ø´Ï´Ù. À½...°£´ÜÇÏÁÒ~

        ¾ðÁ¦Àΰ¡? Áú¹®¶õÀ» ÅëÇØ ÇѱÛÀ̳ª ¹®ÀÚ¸¦ ¾î¶»°Ô Âï³Ä°í ÇϽôõ
        ±º¿ä~ º¸Åë À©µµ¿ìÁî API¸¦ ¹è¿ìÁö ¾Ê°í ±×³É À©µµ¿ìÁî ÇÁ·Î±×·¥
        À» ÇϽðڴٰí ÇÑ´Ù¸é ´ç¿¬ ÀÌ·±ÂÊÀÇ ¹æ¹ýÀ» ¾Ë¼ö°¡ ¾øÀ» °Ì´Ï´Ù.

        ´ÙÀ½ ¿¹Á¦¸¦ ¸ÕÀú º¸ÁÒ~

        <¿¹Á¦ : ´ÙÀÌ·ºÆ®¿¡¼­ ±ÛÀÚÂï±â >
        HDC hdc;
        if(lpDDSPrimary->GetDC(&hdc) == DD_OK)
        {
            Rectangle(hdc, ....);
            SetTextColor(hdc, ....);
            SetBkCOlor(hdc, ....);
            TextOut(hdc, ....);
            lpPrimary->ReleaseDC(hdc);
        }

        GDI¸¦ »ç¿ëÇÏ´Â °ÍÀ̵¥, ÀÌ°ÍÀÌ ¹«¾ðÁö´Â À©µµ¿ì °­Á¶õÀ» Âü°í
        Çؼ­ ÀÌÇظ¦ ÇϼÌÀ¸¸é ÇÕ´Ï´Ù. ´ÙÀÌ·ºÆ® µå·Î¿ì Ç¥¸éÀº DC¸¦ ¾ò
        ¾î GDI ÇÔ¼ö¸¦ »ç¿ëÇÏ°Ô ÇØÁֹǷΠÇÁ¶ó¸Ó¸®¿¡¼­ °£´ÜÈ÷ GDIÇÔ¼ö
        ¸¦ »ç¿ëÇÒ¼ö ÀÖ´Â °ÍÀÌÁÒ~
        À§ ¿¹Á¦ ÇÔ¼ö¿¡ ´ëÇؼ­´Â À©µµ¿ìÁî API¹ÙÀ̺íÀ» ÂüÁ¶ ÇØÁÖ¼¼¿ä~


        <¼Ò½º: À§ÀÇ ¿¹Á¦ Àüü ¼Ò½º>

        #include <windows.h>
        #include <ddraw.h>

        BOOL initDirectDraw(HWND hWnd);
        void closeDirectDraw();
        void Draw();

        LPDIRECTDRAW lpDD = NULL;
        LPDIRECTDRAWSURFACE lpPrimary = NULL;
                .
                .
        // À©µµ¿ì ÇÁ·Î½ÃÁ®¿Í ¸ÞÀÎ ÇÔ¼ö´Â »ý·« --;
        // °øÅëºÎºÐÀ̹ǷÎ...
                    .
                .
        BOOL initDirectDraw(HWND hWnd)
        {
        HRESULT hr;
        // »ý¼º°ú ¸ðµå ¼³Á¤
        hr = DirectDrawCreate(NULL, &lpDD, NULL);
        if(hr != DD_OK) return FALSE;
        hr = lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE |
                                                DDSCL_FULLSCREEN);
        if(hr != DD_OK) return FALSE;
        hr = lpDD->SetDisplayMode(640, 480, 8); //640*480*256 Mode
        if(hr != DD_OK) return FALSE;
        // 1Â÷ Ç¥¸é »ý¼º
        DDSURFACEDESC ddsd;
        ZeroMemory

(&ddsd, sizeof(ddsd));
        ddsd.dwSize = sizeof(ddsd);
        ddsd.dwFlags = DDSD_CAPS;
        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
        lpDD->CreateSurface(&ddsd, &lpPrimary, NULL);

        return TRUE;
        }

        // DirectDraw Primary ¸¦ ¼Ò¸ê½ÃÅ´.
        void closeDirectDraw()
        {
        if(lpPrimary != NULL)
                lpPrimary->Release();
        if(lpDD != NULL)
                lpDD->Release();
        }
        void Draw()
        {
        LPSTR str = "Hello!, ~";
        HRESULT hr;
        HDC hDC;

        hr = lpDDSPrimary->GetDC(&hDC);
        if(hr == DD_OK)
        {
                TextOut(hDC, 300, 200, str, strlen(str));
                lpPrimary->ReleaseDC(hDC);
 }
        }

        3. ºñÆ®¸Ê
        °ÔÀÓÀ» ¸¸µç´Ù¸é PCX¸¦ ¸¹ÀÌ »ç¿ëÇßÀ» °Ì´Ï´Ù. Á¦ÀÛ°ú »ç¿ëÇϱâ
        ÆíÇÏ´Ù´Â ÀÌÀ¯¸¸À¸·Î....À½...
        ±×·±µ¥ À©µµ¿ìÁî¿¡¼­´Â ºñÆ®¸ÊÀÌ Á¸Àç ÇÑ´Ù´Â °ÍÀº ÀÌ¹Ì ÆäÀÌÆ®
        ºê·¯½¬¸¦ ÅëÇØ ¾Ë°í °è½ÃÁÒ?

        À©µµ¿ìÁî´Â ºñÆ®¸Ê ±âº»À¸·Î »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù.
        ±×·³...µµ´ëü ¾î¶² ±¸Á¶¸¦ ÇÏ°í Àֱ⿡ ºñÆ®¸ÊÀ» »ç¿ëÇÒ±î¿ä~

         < DIB ±¸Á¶ >
     +-------------------+
     | BITMAPFILEHEADER  |
     +-------------------+
     | BITMAPINFOHEADER  |  --+--> BITMAPINFO
     +-------------------+    |
     | RGBQUAD          |  --+
     +-------------------+
     | Image Data        |
     +-------------------+

        À©µµ¿ìÁî´Â ÀÇÁ¸Àû ºñÆ®¸Ê(DDB)°ú ÀåÄ¡ µ¶¸³Àû ºñÆ®¸Ê (DIB)
        µÎ°¡Áö¸¦ Á¦°øÇÕ´Ï´Ù. ÀÇÁ¸Àû ºñÆ®¸ÊÀº ÀϹÝÀûÀ¸·Î »ç¿ëÇÏ´Â
        ºñÆ®¸ÊÀ» ÀǹÌÇÕ´Ï´Ù.
        
        // BITMAPFILEHEADER
        typedef struct tagBITMAPFILEHEADER {
            WORD bfType;            // ASCII °ª "BM"
                DWORD bfSize;           // ÆÄÀÏ »çÀÌÁî
                WORD bfReserved1;
                WORD bfReserved2;
                DWORD bfOffBits;        // ÆÄÀÏ Ã³À½ºÎÅÍ bitmap±îÁö ¹ÙÀÌÆ® ¼ö
        } BITMAPFILEHEADER;
        
        BITMAPFILEHEADER´Â À§¿Í °°ÀÌ ¼±¾ð µÇ¾î ÀÖ½À´Ï´Ù.
        À×? ÀÌ°ÍÀÌ ÀüºÎ ÇÊ¿ä ÇÑ°ÍÀº ¾Æ´Ï¿©¿ä~ ¿©±â¼­ ÇÊ¿äÇÑ °ÍÀº bfType¿Í
        bfSizeÀε¥..bfType´Â ÀÌ ÆÄÀÏÀÌ ºñÆ®¸ÊÀÎÁö¸¦ ³ªÅ¸³À´Ï´Ù. ºñÆ®¸ÊÀº
        16Áø¼ö·Î 4d42ÀÌ°í WORD·Î "BM"À» ³ªÅ¸³À´Ï´Ù.
        ±×¸®±¸ bfSize´Â ÆÄÀÏ »çÀÌÁî Àε¥..ºñÆ®¸Ê ÆÄÀÏ¿¡¼­
        BITMAPINFOHEADERºÎÅÍÀÇ Æ÷ÀÎÅ͸¦ °è»êÇϴµ¥ »ç¿ëÇÕ´Ï´Ù.

        BITMAPFILEHEADER bmfh;
        dwDibSize = bmfh.bfSize - sizeof(BITMAPFILEHEADER);
        

        // BITMAPINFO
        typedef struct tagBITMAPINFO {
        BITMAPINFOHEADER bmiHeader;
        RGBQUAD bmiColors[1];
        } BITMAPINFO;
        º¸´Ù½ÃÇÇ BITMAPINFOHEADER¿Í RGBQUAD·Î ±¸¼º µÇ¾î ÀÖ½À´Ï´Ù.

        // BITMAPINFOHEADER
        typedef struct tagBITMAPINFOHEADER{ // bmih
                DWORD  biSize;
            LONG   biWidth;                       // X Å©±â
            LONG   biHeight;              // Y Å©±â
            WORD   biPlanes;          // Plane¼ö Àε¥ Ç×»ó 1
            WORD   biBitCount;
            DWORD  biCompression;     // ¾ÐÃà ÇüÅÂ.
            DWORD  biSizeImage;       // ¹ÙÀÌÆ® ´ÜÀ§·Î ºñÆ®¸ÊÀÇ Å©±â.
            LONG   biXPelsPerMeter;   // ¹ÌÅÍ´ç ¼öÆò Çȼ¿ ¼ö
            LONG   biYPelsPerMeter;   // ¹ÌÅÍ´ç ¼öÁ÷ Çȼ¿ ¼ö
            DWORD  biClrUsed;
            DWORD  biClrImportant;    // Áß¿äÇÑ Ä÷¯¼ö
        } BITMAPINFOHEADER;

        biSize´Â BITMAPINFOHEADER±¸Á¶ÀÇ Å©±â
        biBitCount´Â Çȼ¿´ç ºñÆ® ¼ö
        biClrUsed´Â »ç¿ëµÈ Ä®·¯ ¼ö¸¦ ¶æÇÏ¸ç °ªÀÌ 0ÀÌ¸é ºñÆ®¸ÊÀº
        biBitCount¿¡ ´ëÇÏ´Â ÃÖ´ëÀÇ Ä÷¯¼ö¸¦ »ç¿ëÇÕ´Ï´Ù.

        // RGBQUAD
        typedef struct tagRGBQUAD {
           BYTE rgbBlue;
           BYTE rgbGreen;
           BYTE rgbRed;
           BYTE rgbReserved;
        } RGBQUAD;

        DIBÀÇ Ä®·±´Â ÀÌ ±¸Á¶·Î Ç¥Çö µÇ´Âµ¥.. 16Ä®·¯ ºñÆ®¸ÊÀº
        16 RGBQUAD±¸Á¶,256Ä®·¯´Â 256 RGBQUAD±¸Á¶, ¿¹¿ÜÀûÀ¸·Î
        24ºñÆ® Ä®·¯´Â Ä®·¯ Å×À̺íÀÌ ¾ø´ä´Ï´Ù.

        ÇöÀç DIB°¡ °¡Áö°í ÀÖ´Â Ä®·¯¼ö¸¦ °è»êÇÏ·Á¸é....

                BITMAPINFO lpBi;
                ...
                ...
        if(lpBi->bmiHeader.biClrUsed != 0)
                nColor = lpBi->bmiHeader.biClrUsed;
        else
                switch(lpBi->bmiHeader.biBitCount)
                {
                case 1:  nColor = 2;   break;
                case 4:  nColor = 16;  break;
                case 8:  nColor = 256; break;
                case 24: nColor = 0;   break;
                }

        °£´ÜÇÏÁÒ..À½..¿©±â¼­ Ä®·¯ ¼ö¸¦ °è»êÇÏ´Â ÀÌÀ¯´Â ³ªÁß¿¡
        ¼³¸íÇÒ Palette»ý¼º¿¡ ÇÊ¿äÇϱ⠶§¹®ÀÔ´Ï´Ù.

        (Âü°í·Î ÀúÀåµÇ´Â ¹æ½ÄÀº bottom-up¹æ½ÄÀ¸·Î ÀúÀå µË´Ï´Ù.)

        // À̹ÌÁö µ¥ÀÌÅ͸¦ ¾ò´Â ¹æ¹ý
        lpBi + lpBi->bmiHeader.biSize + (nColor * sizeof(RGBQUAD));

        À¸¾Ç~....Ãâ±Ù ½Ã°£ÀÌ....ÆÈ·¹Æ® ºÎºÐÀº »ý·«...´ÙÀ½ ±âȸ¿¡..
        Çϵµ·Ï ÇÏÁÒ...¹«·Á Çѽ𣵿¾È...±Ã¸® ³¡¿¡ ²ôÀûÀ̴µ¥...

        ´ÙÀ½¿¡ °­Á¿¡ ÀÖ±âÀü¿¡...´ÙÀÌ·ºÆ® ¿¢½ºÀÇ ¿¹Á¦Áß¿¡
        SDK\SAMPLES\MISC\ÀÇ  DDUTIL.CPP¸¦ Çѹø¾¿ ºÐ¼®ÇØÁÖ¼¼¿ä~