Problem with CreateSurface function (DirectDraw)

This is a discussion on Problem with CreateSurface function (DirectDraw) within the Game Programming forums, part of the General Programming Boards category; Code: LPDIRECTDRAW7 lpdd; DirectDrawCreateEx(NULL,(void**)&lpdd,IID_IDirectDraw7,NULL); lpdd->SetCooperativeLevel(hHandle,DDSCL_NORMAL); if((lpdd->SetDisplayMode(1024,768,16,0,0))!=DD_OK) { return(0); } //directDraw surface description struct DDSURFACEDESC2 ddsd; //directDraw interface pointer LPDIRECTDRAWSURFACE7 lpddsprimary; ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    41

    Problem with CreateSurface function (DirectDraw)

    Code:
    LPDIRECTDRAW7 lpdd;
    DirectDrawCreateEx(NULL,(void**)&lpdd,IID_IDirectDraw7,NULL); 
    lpdd->SetCooperativeLevel(hHandle,DDSCL_NORMAL);
    if((lpdd->SetDisplayMode(1024,768,16,0,0))!=DD_OK)
    	{
    	return(0);
    	}
    //directDraw surface description struct
    DDSURFACEDESC2 ddsd;
    //directDraw interface pointer
    LPDIRECTDRAWSURFACE7 lpddsprimary;
    ddsd.dwSize=sizeof(ddsd);
    ddsd.dwFlags=DDSD_CAPS;
    ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE;
    if(lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DDERR_INVALIDCAPS)
    	{
    	ShowWindow(hHandle,SW_MINIMIZE);
    	}
    I've changed out the error flags until I found the one that the CreateSurface function returned. I cannot figure out why this is happening and I have no idea how to fix it. Any help?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    DirectDraw is dead. Face it. Use D3D.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Since you usually want to have a back buffer in addition to the primary surface, you may consider something like this:

    Code:
    memset(&ddsd, 0, sizeof(ddsd));
    
    ddsd.dwSize = sizeof(ddsd);   
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Why are you using deprecated DirectDraw interfaces? In the new D3D SDK they specifically state that while they attempt to maintain compatibility with previous versions, this can no longer be guaranteed as it relates to DirectDraw interfaces. D3D will be backwards compatible but since DirectDraw is now inside of D3D, they can no longer guarantee it's backwards compatibility and they are no longer supporting DirectDraw or addressing DirectDraw issues - neither are the video card manufacturers.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    41
    DirectDraw is still there and still functional. Face it. -I- for one want to learn the roots.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    ...yet not supported. Future drivers may not even implement the old interfaces correctly so you are treading on thin ice using it.

    Just use Direct3D for 2D. It's simple. And you can get to the surface using IDirect3DTexture9 to get a pointer to the IDirect3DSurface9 interface.

    But the days of locking and unlocking surfaces for the most part are gone. Everything can be done via shaders, SetRenderTarget() and render to texture operations.

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    41
    Well Bubba, I'll take your word for it. Only trouble is, now I need to find some resources that teach the Direct3D for 2D interfaces, since this book I have is completely horrible.

    Of course any help from the folks on here would be appreciated. With DirectDraw I was able to create the object and pointer, but the CreateSurface function errored when I called it. Now I am stuck between Scylla and Charybdis.

  8. #8
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    You wont really be able to do 2d stuff with Direct3D it will just look like its in 2d. They decided to kill DirectDraw becouse rotating a bitmap is crazy slow, so now you just create a graphical object and blit the bitmap on.

  9. #9
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    There are simple ways of getting 2d into 3d. Its honestly not as hard as you might think. Good tutorials are onGamedev.

    And Bubba is right, DD is encapsulated inside of D3D, in essence you could think of 2d as being 3d with a constantly 0 z-vector... but thats oversimplyfying I suppose. In any event, check it out, you'll tons of good stuff, or even check out stuff on this forum.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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