1 / 12

Chapter 6. DirectDraw Interface

Chapter 6. DirectDraw Interface. IUnknown IDirectDraw IDirectDrawSurface IDirectDrawPalette IDirectDrawClipper. IDirectDraw 설정. IDirectDraw 전역변수 선언 DirectDraw 개체 설정 Primary surface 설정. DirectDraw 전역 변수 선언. 비디오 하드웨어를 관리할 개체의 Interface 포인터 예약 surface: 이미지를 저장하는 데 사용되는 개체 선언

penny
Download Presentation

Chapter 6. DirectDraw Interface

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6. DirectDraw Interface • IUnknown • IDirectDraw • IDirectDrawSurface • IDirectDrawPalette • IDirectDrawClipper

  2. IDirectDraw 설정 • IDirectDraw 전역변수 선언 • DirectDraw 개체 설정 • Primary surface 설정

  3. DirectDraw 전역 변수 선언 • 비디오 하드웨어를 관리할 개체의 Interface 포인터 예약 • surface: 이미지를 저장하는 데 사용되는 개체 선언 • 8bit color에 대한 팔레트 관리 개체 선언 LPDIRECTDRAW lpDirectDrawObject ; // direct draw object LPDIRECTDRAWSURFACE lpPrimary; // primary surface LPDIRECTDRAWPALETTE lpPrimaryPalette; // its palette

  4. DirectDraw 개체 초기화 if( FAILED( DirectDrawCreate( NULL, &lpDirectDrawObject, NULL ) ) ) return FALSE; • DirectDraw 개체를 생성 후 lpDirectDrawObject 에 이 개체의 포인터 저장 • 협력 수준 설정 : 운영 체제 및 다른 응용 프로그램들과 비디오 하드웨어 공유의 범위 설정 • 화면 해상도 설정 if( FAILED(lpDirectDrawObject->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN ) ) ) return FALSE; if( FAILED(lpDirectDrawObject->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_DEPTH ) ) ) // ref Defines.h return FALSE;

  5. Primary Surface 만들기 • 현재 모니터에 표시되는 이미지가 포함된 표면으로서, 비디오 메모리에 저장 • 디스플레이 모드와 동일한 크기 및 색 depth를 갖는 표면 생성 DDSURFACEDESC ddsd; // direct draw surface descriptor ddsd.dwSize(ddsd) ddsd.dwFlags=DDSD_CAPS; // table 6.5 ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE //table 6.6 if FAILED(lpDirectDrawObject->CreateSurface(&ddsd,&lpPrimary, NULL))) return FALSE;

  6. 팔레트 설정 • CreatePalette : DirectDraw Palette를 만들고, 주 표면에 팔레트를 첨부한 후 , 팔레트의 포인터를 반환한다. LPDIRCTDRAWPALETTE CreatePalette( LPDIRECTDRAWFURFAE surface) { PALETTENTRY pe[COLORS] ; // new palette LPDIRECTDRAWPALETTE lpDDpalette; // direct draw palette for(int I=0; I < COLORS; I++ ) pe[i].peRed = pe[i].peGreen = pe[i].peBlue=0; if(FAILED( lpDirectDrawObject->CreatePalette(DDPCAPS_8BITS, pe, &lpDDPalette, NULL ))) return FALSE; suface->SetPalette(lpDDPalette); return lpDDPalette; }

  7. 그래픽 로드 • 이미지 로드 작업을 통해 얻은 bitmap 이미지의 팔레트를 주표면 팔레트에 로드 한 후 주표면에 이미지를 그린다. BOOL LoadImages(){ //load pictures from disk //draw the first image to the primary surface if(!background.load("bckgnd.bmp")) //read from file return FALSE; //read failed if(!background.setpalette(lpPrimaryPalette)) //set palette return FALSE; //set palette failed if(!background.draw(lpPrimary)) //draw to surface return FALSE; //draw failed return TRUE; //all steps succeeded } //LoadImages

  8. BMP File Reader CLASS BMP FILE READER CLASSclass CBmpFileReader{ //bmp file input class protected: BITMAPFILEHEADER m_BMPFileHead; //bmp header BITMAPINFOHEADER m_BMPFileInfo; //bmp file information RGBQUAD m_rgbPalette[COLORS]; //the palette BYTE *m_cImage; //the image public: CBmpFileReader(); //constructor ~CBmpFileReader(); //destructor BOOL load(char *filename); //load from file BOOL draw(LPDIRECTDRAWSURFACE surface); //draw image BOOL setpalette(LPDIRECTDRAWPALETTE palette); //set palette};

  9. BMP File Reader Class : drawSurface BOOL CBmpFileReader::draw(LPDIRECTDRAWSURFACE surface){ DDSURFACEDESC ddsd; //direct draw surface descriptor BYTE *dest,*src; //destination and source pointers int src_width; //width of source //init surface descriptor memset(&ddsd,0,sizeof(DDSURFACEDESC)); ddsd.dwSize=sizeof(ddsd); //lock down surface if(FAILED(surface->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL))) return FALSE;

  10. BMP File Reader Class : drawSurface //calculate addresses and width dest=(BYTE*)ddsd.lpSurface; //destination src=m_cImage+ ((m_BMPFileInfo.biHeight-1)*m_BMPFileInfo.biWidth); //trim bmp if too wide if(m_BMPFileInfo.biWidth>ddsd.lPitch)src_width=ddsd.lPitch; else src_width=m_BMPFileInfo.biWidth; //move data to surface for(int i=0; i<m_BMPFileInfo.biHeight; i++){ memcpy(dest,src,src_width); dest+=ddsd.lPitch; src-=src_width; } //clean up and return surface->Unlock(NULL); return TRUE; } //draw

  11. BMP File Reader Class : Set Palette BOOL CBmpFileReader::setpalette(LPDIRECTDRAWPALETTE palette){ PALETTEENTRY pe[COLORS]; //intermediate palette //construct pe[] for(int i=0; i<COLORS; i++){ //for each palette entry pe[i].peRed=m_rgbPalette[i].rgbRed; //set red pe[i].peGreen=m_rgbPalette[i].rgbGreen; //set green pe[i].peBlue=m_rgbPalette[i].rgbBlue; //set blue } //load direct draw palette to surface palette->SetEntries(NULL,0,COLORS,pe); return TRUE; }

  12. Demo 00 실행 • Code file • Bmp.h • Bmp.cpp • Ddsetup.cpp • Defines.h • Main.cpp • Media file • Bckgnd.bmp • Lib file • Ddraw.lib

More Related