DirectDraw 어플리케이션 구현 | |||
| |||
첨부의 모듈을 이용하면 라이브러리 링크도 할 필요 없다. (지가 알아서 링크도 해주도록 원소스를 살짝 수정했음) 다음과 같은 순서로 프로그램을 만들어보도록 하자. 1. DirectX를 설치한다. 2. Tools -> include 디렉토리와 lib 디렉토리 세팅을 한다. (설치된 디렉토리로 친절하게 세팅해준다) 3. 다이얼로그 기반 MFC 어플리케이션을 생성한다. 4. 첨부의 파일을 생성된 프로젝트의 로컬 디렉토리에 복사하고 프로젝트에 추가 시킨다. 5. 메인어플리케이션 상단에 1) # include "DirecControl.h"를 선언한다 2) 다음을 글로벌 베리어블로 선언한다. CDirectControl m_Control 3) InitInstance()모듈 알맹이를 싹 지우고 다음과 같이 모듈을 써준다. BOOL CtestApp::InitInstance() { m_pMainWnd = m_Control.CreateFullScreen(800,600,16); if (!m_pMainWnd) return FALSE; m_Control.CreateOffScreenSurface( (LPCTSTR)"1",IDB_BITMAP1); m_Control.GetSurface( (LPCTSTR)"1")->SetRender(TRUE); return TRUE; } 4) OnIdle 이벤트를 메인 어플에 추가해준다. 그리고 하기와 같이 기술해 준다. BOOL CtestApp::OnIdle(LONG lCount) { MSG msg; if(::PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE)){ if (msg.message == WM_QUIT) PostQuitMessage(0); TranslateMessage(&msg); DispatchMessage(&msg); } m_Control.Render(TRUE,TRUE,TRUE); } --------------------- The code itself is fairly limited to displaying bitmaps on the screen (FULLSCREEN MODE) using DirectDraw but it shows the concepts of using wrappers to make your programs far easier to use. I could have put it all in a DLL but realised that this would not be simple for you all to use. Anyway, here is how you use the libraries. 1. Include the following header into your Application Header or StdAfx.h. E.g #include "DirectControl.h" 2. Create an instance of the CDirectControl Object. For example: CDirectControl m_Control; Please note that this should be placed either as a global variable or inside the Application class header (i.e. not temporary) 3. In the App Init Instance call the following code: m_pMainWnd = m_Control.CreateFullScreen(800,600,16); if (!m_pMainWnd) return FALSE; Replace the 800 and 600 with the required x & y resolutions that you want to use. Replace the 16 with the bits-per-pixel required. My program does not maintain or handle the Palette because I was only really using hi-color modes for the bitmaps. 4. You can now use the Controller to create bitmaps (from the resource) using the code : m_Control.CreateOffScreenSurface("My Bitmap",IDB_IMAGE); The first parameter is the object identifier that I use to manipulate or select the object at a further time. The second parameter is the resource id of the bitmap. You also need to tell the controller that the bitmap is available to be rendered. The default is false so you need to set the visibility by using the code: m_Control.GetSurface("My Bitmap")->SetRender(TRUE); 5. The bitmaps are defaulted to the top left of the screen (x=0,y=0) but you can alter its position by using: m_Control.GetSurface("My Bitmap")->SetPosition(10,10); Relating to the x & y screen co-ordinates. The program automatically clips to the screen. 6. Once you have created your bitmap/s you can render the screen by calling: m_Control.Render(TRUE,FALSE,FALSE); The first parameter decides if you want to clear the screen first before rendering. The second decides whether you want to render any bitmaps that have been flagged renderable. the third parameter decides whether you want to update the Screen. I did it this way because you dont want to update the screen all the time e.g. if you want to use one bitmap , change its position and render it again then update the screen. Ok. What I suggest is that you look at the example project I have done. If anyone wishes to expand it further etc. I would welcome and more additional source code or comments. Please dont laugh at my code. I just wanted Direct X to be easy for everyone. Enjoy. Tags: DirectDraw DirectDraw Sample Source DirectDraw 샘플 DirectX DirectX 게임 기본 소스 DirectX 게임 프로그래밍 DirectX 어플리케이션 샘플 윈도우즈 | |||
| |||
| |||
Login for comment |
OTHER POSTS IN THE SAME CATEGORY 특정 디스크 드라이브 숨기기 및 엑세스 금지하게 하기 |