// ************************** class MyDeviceEnumerator : public DeviceEnumerator { public: protected: virtual void enumDevice(DeviceDescription &deviceDescription); private: }; void MyDeviceEnumerator::enumDevice(DeviceDescription &deviceDescription) { ::OutputDebugString(deviceDescription.deviceName()+String(" ")+deviceDescription.deviceDescription()+String("\n")); return; } DDPIXELFORMAT The DDPIXELFORMAT structure describes the pixel format of a DirectDrawSurface object for the IDirectDrawSurface4::GetPixelFormat method. typedef struct _DDPIXELFORMAT{ DWORD dwSize; DWORD dwFlags; DWORD dwFourCC; union { DWORD dwRGBBitCount; DWORD dwYUVBitCount; DWORD dwZBufferBitDepth; DWORD dwAlphaBitDepth; DWORD dwLuminanceBitCount; // new for DirectX 6.0 DWORD dwBumpBitCount; // new for DirectX 6.0 } DUMMYUNIONNAMEN(1); union { DWORD dwRBitMask; DWORD dwYBitMask; DWORD dwStencilBitDepth; // new for DirectX 6.0 DWORD dwLuminanceBitMask; // new for DirectX 6.0 DWORD dwBumpDuBitMask; // new for DirectX 6.0 } DUMMYUNIONNAMEN(2); union { DWORD dwGBitMask; DWORD dwUBitMask; DWORD dwZBitMask; // new for DirectX 6.0 DWORD dwBumpDvBitMask; // new for DirectX 6.0 } DUMMYUNIONNAMEN(3); union { DWORD dwBBitMask; DWORD dwVBitMask; DWORD dwStencilBitMask; // new for DirectX 6.0 DWORD dwBumpLuminanceBitMask; // new for DirectX 6.0 } DUMMYUNIONNAMEN(4); union { DWORD dwRGBAlphaBitMask; DWORD dwYUVAlphaBitMask; DWORD dwLuminanceAlphaBitMask; // new for DirectX 6.0 DWORD dwRGBZBitMask; DWORD dwYUVZBitMask; } DUMMYUNIONNAMEN(5); } DDPIXELFORMAT, FAR* LPDDPIXELFORMAT; Members dwSize Size of the structure, in bytes. This member must be initialized before the structure is used. dwFlags Optional control flags. DDPF_ALPHA The pixel format describes an alpha-only surface. DDPF_ALPHAPIXELS The surface has alpha channel information in the pixel format. DDPF_ALPHAPREMULT The surface uses the premultiplied alpha format. That is, the color components in each pixel are premultiplied by the alpha component. DDPF_BUMPLUMINANCE The luminance data in the pixel format is valid, and the dwLuminanceBitMask member descibes valid luminance bits for a luminance-only or luminance-alpha surface. DDPF_BUMPDUDV Bump-map data in the pixel format is valid. Bump-map information is in the dwBumpBitCount, dwBumpDuBitMask, dwBumpDvBitMask, and dwBumpLuminanceBitMask members. DDPF_COMPRESSED The surface will accept pixel data in the specified format and compress it during the write operation. DDPF_FOURCC The dwFourCC member is valid and contains a FOURCC code describing a non-RGB pixel format. DDPF_LUMINANCE The pixel format describes a luminance-only or luminance-alpha surface. DDPF_PALETTEINDEXED1 DDPF_PALETTEINDEXED2 DDPF_PALETTEINDEXED4 DDPF_PALETTEINDEXED8 The surface is 1-, 2-, 4-, or 8-bit color indexed. DDPF_PALETTEINDEXEDTO8 The surface is 1-, 2-, or 4-bit color indexed to an 8-bit palette. DDPF_RGB The RGB data in the pixel format structure is valid. DDPF_RGBTOYUV The surface will accept RGB data and translate it during the write operation to YUV data. The format of the data to be written will be contained in the pixel format structure. The DDPF_RGB flag will be set. DDPF_STENCILBUFFER The surface encodes stencil and depth information in each pixel of the z-buffer. This flag can only be used if the DDPF_ZBUFFER flag is also specified. DDPF_YUV The YUV data in the pixel format structure is valid. DDPF_ZBUFFER The pixel format describes a z-buffer surface. DDPF_ZPIXELS The surface contains z information in the pixels. dwFourCC FourCC code. For more information see, Four Character Codes (FOURCC). dwRGBBitCount RGB bits per pixel (4, 8, 16, 24, or 32). dwYUVBitCount YUV bits per pixel (4, 8, 16, 24, or 32). dwZBufferBitDepth Z-buffer bit depth (8, 16, 24, or 32). dwAlphaBitDepth Alpha channel bit depth (1, 2, 4, or 8) for an alpha-only surface (DDPF_ALPHA). For pixel formats that contain alpha information interleaved with color data (DDPF_ALPHAPIXELS), you must count the bits in the dwRGBAlphaBitMask member to obtain the bit-depth of the alpha component. For more information, see Remarks. dwLuminanceBitCount Total luminance bits per pixel. This member applies only to luminance-only and luminance-alpha surfaces. dwBumpBitCount Total bump-map bits per pixel in a bump-map surface. dwRBitMask Mask for red bits. dwYBitMask Mask for Y bits. dwStencilBitDepth Bit depth of the stencil buffer. This member specifies how many bits are reserved within each pixel of the z-buffer for stencil information (the total number of z-bits is equal to dwZBufferBitDepth minus dwStencilBitDepth). dwLuminanceBitMask Mask for luminance bits. dwBumpDuBitMask Mask for bump-map U-delta bits. dwGBitMask Mask for green bits. dwUBitMask Mask for U bits. dwZBitMask Mask for z bits. dwBumpDvBitMask Mask for bump-map V-delta bits. dwBBitMask Mask for blue bits. dwVBitMask Mask for V bits. dwStencilBitMask Mask for stencil bits within each z-buffer pixel. dwBumpLuminanceBitMask Mask for luminance in a bump-map pixel. dwRGBAlphaBitMask and dwYUVAlphaBitMask and dwLuminanceAlphaBitMask Masks for alpha channel. dwRGBZBitMask and dwYUVZBitMask Masks for z channel. Remarks The dwAlphaBitDepth member reflects the bit depth of an alpha-only pixel format (DDPF_ALPHA). For pixel formats that include the alpha component with color components (DDPF_ALPHAPIXELS), the alpha bit depth is obtained by counting the bits in the various mask members. The following example function returns the number of bits set in a given bitmask: WORD GetNumberOfBits( DWORD dwMask ) { WORD wBits = 0; while( dwMask ) { dwMask = dwMask & ( dwMask - 1 ); wBits++; } return wBits; } The unions in this structure have been updated to work with compilers that don't support nameless unions. If your compiler doesn't support nameless unions, define the NONAMELESSUNION token before including the Ddraw.h header file. CallbackData::ReturnType MainWindow::activateAppHandler(CallbackData &someCallbackData) { #if 0 if(!mDirectDraw.isOkay())return (CallbackData::ReturnType)FALSE; if(someCallbackData.wParam()) { mDirectDraw->setCooperativeLevel(*this,DirectDraw::CoopFlags(DirectDraw::Exclusive|DirectDraw::FullScreen)); // mDirectDraw->setDisplayMode(800,600,24); // Surface primarySurface; // SurfaceDescription surfaceDescription; // SurfaceCapabilities surfaceCapabilities(SurfaceCapabilities::Capabilities(SurfaceCapabilities::PrimarySurface|SurfaceCapabilities::Device3D)); // surfaceDescription.flags(SurfaceDescription::Capabilities); // surfaceDescription.width(800); // surfaceDescription.height(600); // surfaceDescription.surfaceCapabilities(surfaceCapabilities); // DirectDrawError errorResult(mDirectDraw->createSurface(surfaceDescription,primarySurface)); } else mDirectDraw->restoreDisplayMode(); #endif return (CallbackData::ReturnType)FALSE; } CallbackData::ReturnType MainWindow::displayChangeHandler(CallbackData &someCallbackData) { #if 0 if(!mDirectDraw.isOkay())return (CallbackData::ReturnType)FALSE; if(!mDirectDraw->testCooperativeLevel())::OutputDebugString("testCooperativeLevel failed\n"); else ::OutputDebugString("testCooperativeLevel succeeded\n"); #endif return (CallbackData::ReturnType)FALSE; } enum RenderState{RenderStateTextureHandler=D3DRENDERSTATE_TEXTUREHANDLE, RenderStateAntialias=D3DRENDERSTATE_ANTIALIAS,RenderStateTextureAddress=D3DRENDERSTATE_TEXTUREADDRESS, RenderStateTexturePerspective=D3DRENDERSTATE_TEXTUREPERSPECTIVE,RenderStateWrapU=D3DRENDERSTATE_WRAPU, RenderStateWrapV=D3DRENDERSTATE_WRAPV,RenderStateZEnable=D3DRENDERSTATE_ZENABLE, RenderStateFillMode=D3DRENDERSTATE_FILLMODE,RenderStateShadeMode=D3DRENDERSTATE_SHADEMODE, RenderStateLinePattern=D3DRENDERSTATE_LINEPATTERN,RenderStateMonoEnable=D3DRENDERSTATE_MONOENABLE, RenderStateROP2=D3DRENDERSTATE_ROP2,RenderStatePlaneMask=D3DRENDERSTATE_PLANEMASK, RenderStateZWriteEnable=D3DRENDERSTATE_ZWRITEENABLE,RenderStateAlphaTestEnable=D3DRENDERSTATE_ALPHATESTENABLE, RenderStateLastPixel=D3DRENDERSTATE_LASTPIXEL,RenderStateTextureMag=D3DRENDERSTATE_TEXTUREMAG, RenderStateTextureMin=D3DRENDERSTATE_TEXTUREMIN,RenderStateSrcBlend=D3DRENDERSTATE_SRCBLEND, RenderStateDestBlend=D3DRENDERSTATE_DESTBLEND,RenderStateTextureMapBlend=D3DRENDERSTATE_TEXTUREMAPBLEND, RenderStateCullMode=D3DRENDERSTATE_CULLMODE,RenderStateZFunc=D3DRENDERSTATE_ZFUNC, RenderStateAlphaRef=D3DRENDERSTATE_ALPHAREF,RenderStateAlphaFunc=D3DRENDERSTATE_ALPHAFUNC, RenderStateDitherEnable=D3DRENDERSTATE_DITHERENABLE, RenderStateAlphaBlendEnable=D3DRENDERSTATE_ALPHABLENDENABLE, RenderStateFogEnable=D3DRENDERSTATE_FOGENABLE, RenderStateSpecularEnable=D3DRENDERSTATE_SPECULARENABLE,RenderStateZVisible=D3DRENDERSTATE_ZVISIBLE, RenderStateSubPixel=D3DRENDERSTATE_SUBPIXEL,RenderStateStippledAlpha=D3DRENDERSTATE_STIPPLEDALPHA, RenderStateFogColor=D3DRENDERSTATE_FOGCOLOR,RenderStateFogTableMode=D3DRENDERSTATE_FOGTABLEMODE, RenderStateFogTableStartD3DRENDERSTATE_FOGTABLESTART,RenderStateFogTableEnd=D3DRENDERSTATE_FOGTABLEEND, RenderStateFogTableDensity=D3DRENDERSTATE_FOGTABLEDENSITY,RenderStateStippleEnable=D3DRENDERSTATE_STIPPLEENABLE, RenderStateEdgeAntialias=D3DRENDERSTATE_EDGEANTIALIAS,RenderStateColorKeyEnable=D3DRENDERSTATE_COLORKEYENABLE, RenderStateBorderColor=D3DRENDERSTATE_BORDERCOLOR,RenderStateTextureAddressU=D3DRENDERSTATE_TEXTUREADDRESSU, RenderStateTextureAddressV=D3DRENDERSTATE_TEXTUREADDRESSV,RenderStateMipMapLODBias=D3DRENDERSTATE_MIPMAPLODBIAS, RenderStateZBias=D3DRENDERSTATE_ZBIAS,RenderStateRangeFogEnable=D3DRENDERSTATE_RANGEFOGENABLE, RenderStateAnisotropy=D3DRENDERSTATE_ANISOTROPY,RenderStateFlushBatch=D3DRENDERSTATE_FLUSHBATCH, RenderStateTranslucentSortIndependent=D3DRENDERSTATE_TRANSLUCENTSORTINDEPENDENT, RenderStateStencilEnable=D3DRENDERSTATE_STENCILENABLE,RenderStateStencilFail=D3DRENDERSTATE_STENCILFAIL, RenderStateStencilZFail=D3DRENDERSTATE_STENCILZFAIL,RenderStateStencilPass=D3DRENDERSTATE_STENCILPASS, RenderStateStencilFunc=D3DRENDERSTATE_STENCILFUNC,RenderStateStencilRef=D3DRENDERSTATE_STENCILREF, RenderStateStencilMask=D3DRENDERSTATE_STENCILMASK,RenderStateStencilWriteMask=D3DRENDERSTATE_STENCILWRITEMASK, RenderStateTetxureFactor=D3DRENDERSTATE_TEXTUREFACTOR,RenderStateStipplePattern31=D3DRENDERSTATE_STIPPLEPATTERN31, RenderStateWrap0=D3DRENDERSTATE_WRAP0,RenderStateWrap7=D3DRENDERSTATE_WRAP7, RenderStateForceDoubleWord=D3DRENDERSTATE_FORCE_DWORD}; surfaceDescription.flags(SurfaceDescription::Capabilities); // |SurfaceDescription::BackBufferCount surfaceDescription.surfaceCapabilities(surfaceCapabilities); // surfaceDescription.backBufferCount(1); // |SurfaceCapabilities::Complex|SurfaceCapabilities::Flip PixelFormat pixelFormat; BltEffects bltEffects; DirectDrawError status; mDirectDraw->setCooperativeLevel(*this,DirectDraw::CoopFlags(DirectDraw::Exclusive|DirectDraw::FullScreen)); mDirectDraw->setDisplayMode(DisplayWidth,DisplayHeight,DisplayBPP); mDirectDraw->restoreAllSurfaces(); mPrimarySurface.getPixelFormat(pixelFormat); // BltEffects bltEffects; // for(int i=0;i<100;i++) // { // bltEffects.fillColor(pixelFormat.bBitMask()); // mPrimarySurface.blt(bltEffects,Surface::BltFlags((int)Surface::BltColorFill|(int)Surface::BltEffects)); // bltEffects.fillColor(pixelFormat.rBitMask()); // mPrimarySurface.blt(bltEffects,Surface::BltFlags((int)Surface::BltColorFill|(int)Surface::BltEffects)); // bltEffects.fillColor(pixelFormat.gBitMask()); // mPrimarySurface.blt(bltEffects,Surface::BltFlags((int)Surface::BltColorFill|(int)Surface::BltEffects)); // } #if 0 // SurfaceDescription surfaceDescription; // if(!mPrimarySurface.lock(surfaceDescription).okResult())::OutputDebugString("Lock Failed\n"); DWORD ticks(::GetTickCount()); if(!mPrimarySurface.lock(FALSE))::OutputDebugString("Lock Failed\n"); else { int width(mPrimarySurface.width()); int height(mPrimarySurface.height()); mPrimarySurface.setBits(255); for(int rep=0;rep<200;rep++) { for(int x=100;x<200;x++) { mPrimarySurface.circle(Point(x,100),50,0); mPrimarySurface.circle(Point(x,100),50,255); } } // for(int colorIndex=0;colorIndex<255;colorIndex++) // { // mPrimarySurface.setBits(colorIndex); // for(int row=0;row1024 then increment eax jle @@return ; ... otherwise return inc eax ; increment value in eax @@return: ENDM ;if 0 ;********************** mov eax,[esi].DirectTriEdge@@mxLeft ; move mxLeft into eax shl eax,BitShift ; multiply by 2048 add eax,[esi].DirectTriEdge@@mDXLeft ; add in the delta roundEAX ; adjust and round the value mov [esi].DirectTriEdge@@mxLeft,eax ; this is new mxLeft verifyLeft ; check/adjust mxLeft mov eax,[esi].DirectTriEdge@@mxRight ; move mxRight into eax shl eax,BitShift ; multiply by 2048 add eax,[esi].DirectTriEdge@@mDXRight ; add in the delta roundEAX ; adjust and round the value mov [esi].DirectTriEdge@@mxRight,eax ; this is new mxRight verifyRight ; check/adjust mxRight mov eax,[esi].DirectTriEdge@@muLeft ; move muLeft into eax shl eax,BitShift ; multiply by 2048 add eax,[esi].DirectTriEdge@@mDULeft ; add in the delta roundEAX ; adjust and round the value mov [esi].DirectTriEdge@@muLeft,eax ; this is new muLeft mov eax,[esi].DirectTriEdge@@muRight ; move muRight into eax shl eax,BitShift ; multiply by 2048 add eax,[esi].DirectTriEdge@@mDURight ; add in the delta roundEAX ; adjust and round the value mov [esi].DirectTriEdge@@muRight,eax ; this is new muRight mov eax,[esi].DirectTriEdge@@mvLeft ; move mvLeft into eax shl eax,BitShift ; multiply by 2048 add eax,[esi].DirectTriEdge@@mDVLeft ; add in the delta roundEAX ; adjust and round the value mov [esi].DirectTriEdge@@mvLeft,eax ; this is new mvLeft mov eax,[esi].DirectTriEdge@@mvRight ; move mvRight into eax shl eax,BitShift ; multiply by 2048 add eax,[esi].DirectTriEdge@@mDVRight ; add in the delta roundEAX ; adjust and round the value mov [esi].DirectTriEdge@@mvRight,eax ; this is new mvRight inc y ; increment y ;********************** ;endif if 0 initialize MACRO mov eax,[esi].DirectTriEdge@@my2 ; move my2 into eax sub eax,[esi].DirectTriEdge@@my0 ; eax has (y2-y0) mov [esi].DirectTriEdge@@mDY,eax ; move (y2-y0) into mDY variable mov eax,[esi].DirectTriEdge@@mx2 ; move x2 into eax sub eax,[esi].DirectTriEdge@@mx0 ; eax has (x2-x0) shl eax,BitShift ; multiply result by 2048 for precision divide eax,[esi].DirectTriEdge@@mDY ; eax has (x2-x0)/(y2-y0) mov [esi].DirectTriEdge@@mDXLeft,eax ; this is mDXLeft mov eax,[esi].DirectTriEdge@@mx1 ; move x1 into eax sub eax,[esi].DirectTriEdge@@mx0 ; eax has (x1-x0) shl eax,BitShift ; multiply result by 2048 for precision divide eax,[esi].DirectTriEdge@@mDY ; eax has (x1-x0)/(y2-y0) mov [esi].DirectTriEdge@@mDXRight,eax ; this is mDXRight mov eax,[esi].DirectTriEdge@@mu2 ; move u2 into eax sub eax,[esi].DirectTriEdge@@mu0 ; eax has (u2-u0) shl eax,BitShift ; multiply result by 2048 for precision divide eax,[esi].DirectTriEdge@@mDY ; eax has (u2-u0)/(y2-y0) mov [esi].DirectTriEdge@@mDULeft,eax ; this is mDULeft mov eax,[esi].DirectTriEdge@@mu1 ; move u1 into eax sub eax,[esi].DirectTriEdge@@mu0 ; eax has (u1-u0) shl eax,BitShift ; multiply result by 2048 for precision divide eax,[esi].DirectTriEdge@@mDY ; eax has (u1-u0)/(y2-y0) mov [esi].DirectTriEdge@@mDURight,eax ; this is mDURight mov eax,[esi].DirectTriEdge@@mv2 ; move v2 into eax sub eax,[esi].DirectTriEdge@@mv0 ; eax has (v2-v0) shl eax,BitShift ; multiply result by 2048 for precision divide eax,[esi].DirectTriEdge@@mDY ; eax has (v2-v0)/(y2-y0) mov [esi].DirectTriEdge@@mDVLeft,eax ; this is mDVLeft mov eax,[esi].DirectTriEdge@@mv1 ; move v1 into eax sub eax,[esi].DirectTriEdge@@mv0 ; eax has (v1-v0) shl eax,BitShift ; multiply result by 2048 for precision divide eax,[esi].DirectTriEdge@@mDY ; eax has (v1-v0)/(y2-y0) mov [esi].DirectTriEdge@@mDVRight,eax ; this is mDVRight mov eax,[esi].DirectTriEdge@@mx0 ; move x0 into eax mov [esi].DirectTriEdge@@mxLeft,eax ; mxLeft=x0 mov [esi].DirectTriEdge@@mxRight,eax ; mxRight=x0 mov eax,[esi].DirectTriEdge@@mu0 ; move u0 into eax mov [esi].DirectTriEdge@@muLeft,eax ; muLeft=u0 mov [esi].DirectTriEdge@@muRight,eax ; muRight=u0 mov eax,[esi].DirectTriEdge@@mv0 ; move v0 into eax mov [esi].DirectTriEdge@@mvLeft,eax ; mvLeft=v0 mov [esi].DirectTriEdge@@mvRight,eax ; mvRight=v0 ENDM endif ; cmp eax,[esi].DirectTriEdge@@mx2 ; is mxLeft less than x2 ; jge @@noChangeDir ; if not then continue ; shl eax,BitShift ; adjust mxLeft for precision sub eax,[esi].DirectTriEdge@@mDXLeft ; subtract out mDXLeft, this is adjusted mxLeft mov [esi].DirectTriEdge@@mxLeft,eax ; save adjusted mxLeft mov ebx,[esi].DirectTriEdge@@my1 ; move y1 into ebx register sub ebx,y ; subtract (y1-y) mov ecx,[esi].DirectTriEdge@@mx1 ; move x1 into ecx register sub ecx,[esi].DirectTriEdge@@mx2 ; subtract (x1-x2) shl ecx,BitShift ; adjust eax for precision divide ecx,ebx ; eax has (x1-x2)/(y1-y), result to eax mov [esi].DirectTriEdge@@mDXLeft,eax ; this is new mDXLeft mov ebx,[esi].DirectTriEdge@@mxLeft ; move mxLeft into ebx register add ebx,eax ; ebx has mxLeft+mDXLeft shr ebx,BitShift ; adjust eax for precision mov [esi].DirectTriEdge@@mxLeft,ebx ; this is new mxLeft @@noChangeDir: