Direct Draw

Sharky Forums


Results 1 to 12 of 12

Thread: Direct Draw

  1. #1
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600

    Question Direct Draw

    I am coding a game in direct draw.
    Since 8 bit color is pretty cruddy (for games) I wish to use 32 bit (24 is not an option since it doesn't work for me)

    how do you set up a palette for 32 bit color
    (all the tutorials use 8 bit, no higher



    note: I am using C++

  2. #2
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600
    please anyone

  3. #3
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600
    There has got to be one of the 22000 members who programs direct draw in C++ with more than 265 color


    PLEASE HELP ME (within a couple days would work)

  4. #4
    Goldfish DarkAvenger's Avatar
    Join Date
    Dec 2001
    Location
    India --> Australia
    Posts
    72
    Did you check out the link I posted in my thread, Ironblayde's tutorials? They're quite good and deal with 16-bit towards the middle and end (I assume 16-bit is OK too because you said you didn't want 8-bit).

    What specifically do you want, BTW? There are no palettes in 32-bit (AFAIK), so I don't know what exactly you're looking for when you say 'setting up a palette'.

  5. #5
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600
    all the examples of DDraw are in 8 bit color (which does need a palatte)
    now that I want to code in 32 I don't know what to do
    do I even need to attach a palette to the surfaces for just go for it and start the blting

  6. #6
    Goldfish DarkAvenger's Avatar
    Join Date
    Dec 2001
    Location
    India --> Australia
    Posts
    72
    Nope, no palettes or anything, just create the surfaces and blit.

  7. #7
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600
    Originally posted by DarkAvenger
    Nope, no palettes or anything, just create the surfaces and blit.
    YAY thank you

    man that makes my job SOOOO much easier

    thanks for you help

    if you have you code posted somewhere (the 16 bit color stuff) I would like to see it, I am still relativly new with C++/DDraw

  8. #8
    Goldfish DarkAvenger's Avatar
    Join Date
    Dec 2001
    Location
    India --> Australia
    Posts
    72
    Well, this is basically what I do in normal circumstances for loading 16-bit bitmaps, it's the same as in the tutorials I linked to.

    Code:
    int LoadBitmapFile(LPDIRECTDRAWSURFACE7   
    lpdds, int xDest, int yDest)
    {
        HDC hSrcDC;           // source DC - memory device context
        HDC hDestDC;          // destination DC - surface device context
        HBITMAP hbitmap;      // handle to the bitmap resource
        BITMAP bmp;           // structure for bitmap info
        int nHeight, nWidth;  // bitmap dimensions
    
        // first load the bitmap
        if ((hbitmap = (HBITMAP)LoadImage(hinstance,"C:\pic.bmp",
    IMAGE_BITMAP,
    0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION)) 
    == NULL)        
    
    return(FALSE);
    
        // create a DC for the bitmap to use
        if ((hSrcDC = CreateCompatibleDC(NULL)) == NULL)
            return(FALSE);
    
        // select the bitmap into the DC
        if (SelectObject(hSrcDC, hbitmap) == NULL)
        {
            DeleteDC(hSrcDC);
            return(FALSE);
        }
    
        // get image dimensions
        if (GetObject(hbitmap, sizeof(BITMAP), &bmp) == 0)
        {
            DeleteDC(hSrcDC);
            return(FALSE);
        }
    
        nWidth = bmp.bmWidth;
        nHeight = bmp.bmHeight;
    
        // retrieve surface DC
        if (FAILED(lpdds->GetDC(&hDestDC)))
        {
            DeleteDC(hSrcDC);
            return(FALSE);
        }
    
        // copy image from one DC to the other
        if (BitBlt(hDestDC, xDest, yDest,      
                   nWidth, nHeight, hSrcDC, 
                   0, 0, SRCCOPY) == NULL)
        {
            lpdds->ReleaseDC(hDestDC);
            DeleteDC(hSrcDC);
            return(FALSE);
        }
    
        // kill the device contexts
        lpdds->ReleaseDC(hDestDC);
        DeleteDC(hSrcDC);
    
        // return success
        return(TRUE);
    }
    That ought to work.

    Is that the code you were looking for, or do you want stuff on creating surfaces etc.

    IIRC there isn't anything special in 16-bit as opposed to 8-bit, just no palette attaching. Come to think of it I've completely forgotten palettes !

    [EDIT]Oops, wrong function name and obsolete argument!
    Last edited by DarkAvenger; 04-12-2002 at 04:52 PM.

  9. #9
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600
    thanks for the code

    do you know if using DCs is slower than loading the bitmap yourself and using bltfast

  10. #10
    Goldfish DarkAvenger's Avatar
    Join Date
    Dec 2001
    Location
    India --> Australia
    Posts
    72
    By bitmap loading yourself you mean actually opening the file and manually reading in all the data? I think that method is what many people use, but I haven't had any need to use it just yet, because bitmap loading is fast enough for me.

    BltFast() is definitely the way to go, unless you need to use any special effects via the DDBLTFX structure.

  11. #11
    Hammerhead Shark
    Join Date
    Jan 2002
    Location
    0xC12F6D9A
    Posts
    1,600
    Originally posted by DarkAvenger
    unless you need to use any special effects via the DDBLTFX structure.
    like clipped sprites

  12. #12
    Goldfish DarkAvenger's Avatar
    Join Date
    Dec 2001
    Location
    India --> Australia
    Posts
    72
    I don't think clipping is via the DDBLTFX structure (I've never studied them in detail), IIRC it's through the LPDIRECTDRAWCLIPPER structure. DDBLTFX is mainly used for filling surfaces with a colour, or even for rotation. I only use Blt() when I want to fill my surfaces, everywhere else it's BltFast().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •