Direct XPerts?

This is a discussion on Direct XPerts? within the Game Programming forums, part of the General Programming Boards category; anyone good with direct x? please please have a look at the following code, i know it's sorta big but ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    Direct XPerts?

    anyone good with direct x?
    please please have a look at the following code, i know it's sorta big but if you view the debug.txt file that results from running the program you will see where the problem is (the surface is always busy, flip never occurs)

    i'm new to direct x and building up a mini-wrapper, it will be open source and everything so there is incentive in helping me please someone have a look at this:

    www.conceptofzero.com/directx.zip

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Your problem is in your rgb_to_dword() method, it's not unlocking the surface. I've not looked into why, because a more common (and easier) method to set a background colour is blit it using a DDBLTFX structure. Also, if you want WIN32_LEAN_AND_MEAN then you should define it in every file that includes window.h.

    And don't get wrapperitus, Microsoft provides a pretty decent wrapper in ddutil.h and ddutil.cpp (in the samples directory).

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    thanks for the pointer

    thanks for your help it looks like you're right, and the reason i'm working on this project is because ddutil doesnt include initialization or any of the other features that i'm wanting to include, would you mind showing me another way to set a color key without converting an RGB to a DWORD?

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    A COLORREF (which is produced by the RGB macro) is a typedef of a DWORD. There shouldn't be any conversion needed. Here's the clear method from ddutil.cpp, which shows how it might be done -

    Code:
    HRESULT CDisplay::Clear( DWORD dwColor )
    {
        if( NULL == m_pddsBackBuffer )
            return E_POINTER;
    
        // Erase the background
        DDBLTFX ddbltfx;
        ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
        ddbltfx.dwSize      = sizeof(ddbltfx);
        ddbltfx.dwFillColor = dwColor;
    
        return m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );
    }

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    that sets the background color yes..

    i believe you are misunderstanding me, or i am misunderstanding you, i wish to set the color key using a function, how would the code you provided do this?
    sorry maybe i'm missing something, but i think you misunderstood my question, and thanks for the help so far

  6. #6
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Personally i do this (pulled directly from my current DDraw project, getting an inside peek and all, you lucky bastard, you ):

    Code:
    DWORD DDColorMatch(IDirectDrawSurface7 * pdds, COLORREF rgb)
    {
        COLORREF                rgbT;
        HDC                     hdc;
        DWORD                   dw = CLR_INVALID;
        DDSURFACEDESC2          ddsd;
        HRESULT                 hres;
    
        // Match color
        if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK)
        {
            rgbT = GetPixel(hdc, 0, 0);     // Save current pixel value
            SetPixel(hdc, 0, 0, rgb);       // Set our value
            pdds->ReleaseDC(hdc);
        }
    
        //lock the surface
        ddsd.dwSize = sizeof(ddsd);
        while ((hres = pdds->Lock(NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING)
            ;
        if (hres == DD_OK)
        {
            dw = *(DWORD *) ddsd.lpSurface;
            if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32)
                dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1;  // Mask
            pdds->Unlock(NULL);
        }
    
        //Put it back
        if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK)
        {
            SetPixel(hdc, 0, 0, rgbT);
            pdds->ReleaseDC(hdc);
        }
        return dw;
    }
    //-----------------------------------------------------------------------------
    
    LPDIRECTDRAWSURFACE7 CSurfaceManager::ColorKeyEnable(LPDIRECTDRAWSURFACE7 pTexture)
    {
    	DDCOLORKEY              ddck;
    
        ddck.dwColorSpaceLowValue = DDColorMatch(pTexture, RGB(255, 0, 255));
    	ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowValue;
        pTexture->SetColorKey(DDCKEY_SRCBLT, &ddck);
    
    	return pTexture;
    }
    //-----------------------------------------------------------------------------
    It sets the color key to (255,0,255) which is what i use for everything, but you can easily change the functions to pass in any value you want.

    Used just like this:

    pTexture = ColorKeyEnable(pTexture);
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Direct Input shutting down improperly
    By Deo in forum Game Programming
    Replies: 3
    Last Post: 06-14-2005, 07:54 AM
  2. Direct x 8 include files
    By Zoalord in forum Game Programming
    Replies: 2
    Last Post: 03-17-2004, 04:07 PM
  3. Direct X
    By MicroFiend in forum C++ Programming
    Replies: 2
    Last Post: 03-21-2003, 02:34 PM
  4. Direct Music Illegal Static Member Call error
    By FwyWice in forum Game Programming
    Replies: 4
    Last Post: 11-30-2002, 05:14 PM
  5. Direct Music Trouble
    By FwyWice in forum Game Programming
    Replies: 5
    Last Post: 11-29-2002, 04:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21