Couple of simple directdraw questions.

This is a discussion on Couple of simple directdraw questions. within the Game Programming forums, part of the General Programming Boards category; I have a couple of quick questions about DirectDraw that I was hoping someone could clear up for me. N00b ...

  1. #1
    Deo
    Deo is offline
    Registered User
    Join Date
    May 2005
    Posts
    73

    Couple of simple directdraw questions.

    I have a couple of quick questions about DirectDraw that I was hoping someone could clear up for me. N00b so these are simple questions that I want cleared up before I continue...

    ================================================== ======================
    The first is about a backbuffer surface and its palette.

    - Why do I need to set the palette up for this surface if everything being displayed to the user is on the primary surface? All of the code I have seen sets up the backbuffer surface palette, but I don't understand why. I comment out this code and my program seems to work perfectly fine. My question: So why is it there?

    Ex 1-1:
    Code:
    DDSURFACEDESC ddsd;
    
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |DDSCAPS_FLIP | DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
    	
    hRes = gDirectDrawObject->CreateSurface(&ddsd, &gPrimarySurface, NULL);
    
    if(hRes != DD_OK)
      return false;
    
    if(!createBlackPalette(&gPrimaryPalette))
      return false;
    	
    hRes = gPrimarySurface->SetPalette(gPrimaryPalette);
    
    if(hRes != DD_OK)
      return false;
    
    DDSCAPS ddscaps;
    
    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
    
    if(FAILED(gPrimarySurface->GetAttachedSurface(&ddscaps, &gSecondarySurface)))
      return false;
    
    /* If I comment this section out the program still works fine it appears
    if(!createBlackPalette(&gSecondaryPalette)) // Just creates an palette all values = 0.
      return false;
    
    if(FAILED(gSecondarySurface->SetPalette(gSecondaryPalette)))
      return false;
    */
    continued...
    Code:
    bool loadImages()
    {
      if(!_BACKGROUND_IMAGE_.load("stars.bmp"))
        return false;
    
      if(!_BACKGROUND_IMAGE_.setPalette(gPrimaryPalette)) // _BACKGROUND_IMAGE_ is my bitmap object.
        return false;
    
    /* If I comment this section out the program still works fine it appears
      if(!_BACKGROUND_IMAGE_.setPalette(gSecondaryPalette))  // Set backbuffer surface palette to color table of my bitmap.
        return false;
    */
      if(!_BACKGROUND_IMAGE_.draw(gPrimarySurface))
        return false;
    
      if(!_BACKGROUND_IMAGE_.draw(gSecondarySurface))
        return false;
    
      return true;
    }
    
    ... gPrimarySurface->Flip(NULL, DDFLIP_WAIT);
    ================================================== ======================
    Second is about releasing attached surfaces.

    - I thought I read somewhere that when you release a surface all of its attached surfaces are automatically released. Is this true? Code snippets I've seen explicitly release backbuffers.

    Code:
    case WM_DESTROY:
      if(gDirectDrawObject != NULL)
      {
        if(gSecondarySurface != NULL)    // <--- This is backbuffer attached to primary surface.
          gSecondarySurface->Release();  // <--- These two lines needed?
    				
        if(gPrimarySurface != NULL)
          gPrimarySurface->Release();
    				
        gDirectDrawObject->Release();
      }
    			
      ShowCursor(true);
      PostQuitMessage(0);
    break;
    ================================================== =======================
    Last question has to do with images used for a game.

    - Is it true all images used in a game have to use the same palette? I've only drawn one image to the screen at a time so far (N00B, no sprites yet) and two images with different palettes = disaster unless I explicitly alter the primary surface palette before I display a new image. I'm just not sure how to go about making the game artwork if this is the case. What do you guys do? Make all of the artwork into one big file to ensure a common color table? I suck at drawing so I use 3D packages (3D studio max) so rendering = different color tables, no? (Photoshop CS2 = my 2D package).
    ================================================== =======================

    thnx for any help

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Try using the part of DirectX that is actually supported and I might help. DirectDraw as it is has not been around since DirectX 7.0. It is all now called DirectGraphics and if you attempt to use DirectDraw instead of Direct3D to get things done, you are working against the API not with it.

  3. #3
    Deo
    Deo is offline
    Registered User
    Join Date
    May 2005
    Posts
    73
    thnx for the info.. i was not aware of that as I'm rather new to this sort of programming. Bought a book a long time ago, but didn't have time to get going until now... so the book is quite outdated...

    nice to know I have wasted much of my time.. perhaps i should just go do a nose dive off my roof now

    hopefully DirectGraphics is similar to DirectDraw or I'm gonna be ........ed!

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Well whether or not you want to nose dive off your roof or not is totally up to you, however given that the acceleration due to gravity is 9.8 meters per second per second, I don't recommend it.

    But for some good books on Direct3D programming I recommed you head over to www.amazon.com and buy a book that was written within the last 2 years or so.
    There are several there that are very good and they are not that expensive. Heck as it is now, a tank of gas is more expensive than the books and the books will get you a lot further in DirectX than a tank of gas will on the road.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a couple of questions about System.String
    By Elkvis in forum C# Programming
    Replies: 5
    Last Post: 02-17-2009, 02:48 PM
  2. A couple of Basic questions
    By ozumsafa in forum C Programming
    Replies: 8
    Last Post: 09-26-2007, 05:06 PM
  3. Couple of Questions
    By toonlover in forum Windows Programming
    Replies: 10
    Last Post: 07-14-2006, 02:04 AM
  4. Couple Quick Questions
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 12-15-2001, 05:20 PM
  5. couple questions for newb
    By bluehead in forum C++ Programming
    Replies: 10
    Last Post: 11-24-2001, 03:32 AM

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