Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


A Problem in DirectDraw

This topic is 6586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,folks... Now,I have a problem while I used DirectDraw,it shows as the following: First, I created a DirectDraw primary surface with one back surface,and then attached the back surface to the primary sufrace...the section of the source code as the following:
hRet = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7, NULL);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, "DirectDrawCreateEx FAILED");

    // Get exclusive mode

    hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, "SetCooperativeLevel FAILED");

    // Set the video mode to 640x480x8

    hRet = g_pDD->SetDisplayMode(640, 480, 8, 0, 0);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, "SetDisplayMode FAILED");

    // Create the primary surface with 1 back buffer

    ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwBackBufferCount = 1;
    hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, "CreateSurface FAILED");

    // Get a pointer to the back buffer

    ZeroMemory(&ddscaps, sizeof(ddscaps));
    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
    hRet = g_pDDSPrimary->GetAttachedSurface(&ddscaps, &g_pDDSBack);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, "GetAttachedSurface FAILED");

Second,I wrote some texts into the back surface,ant then fliped the back surface to the primary surface,as you think,these texts displayed on the screen at once,but later,I wrote the other texts into the other location on the back surface ,and then fliped it again,but some  bizarreries were appeared---the texts written at the 1st time was disappear without any reason <img src="sad.gif" width=15 height=15 align=middle>,but the texts written at the 2nd time was displayed normally,the goal
of mine was display the two part texts on the screen step by step(response the keybord input from the users),but it was failure!
WHY THE FIRST PART TEXTS WOULD DISAPPEAR WHILE I PLACED THE SECOND PART ON THE BACK SURFACE? dear friends,can you help me out? <img src="smile.gif" width=15 height=15 align=middle> the section of the code as the following:
//in the windows messages handle function

  {   switch (wParam)
            case VK_RETURN:
	     SetBkColor(hdc, RGB(0,0, 255));
              SetTextColor(hdc, RGB(255, 255, 0));
              TextOut(hdc,50 ,50+50*nTextNo ,
	     while (TRUE)
                   hRet = g_pDDSPrimary->Flip(NULL,DDFLIP_WAIT );
                   if (hRet == DD_OK)
                    if (hRet == DDERR_SURFACELOST)
                      hRet = g_pDDSPrimary->Restore();
                      if (hRet != DD_OK)
                      if (hRet != DDERR_WASSTILLDRAWING)
		  if (nTextNo>=5)
	      case VK_ESCAPE:
               case VK_F12:
                   PostMessage(hWnd, WM_CLOSE, 0, 0);
                    return 0L;

Any help will be much thankful!!!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Correct me if i''m wrong but:

- frontbuffer=empty
- backbuffer=empty

You write text to the back buffer.
situation is now:
- frontbuffer=empty
- backbuffer=1st text.

You flip the surfaces.
- frontbuffer=1st text
- backbuffer=empty

Write text to the backbuffer:
- frontbuffer=1st text
- backbuffer=2nd text

If this is the case, try copying, after the first write+flip, the contents of the frontbuffer (which at this point contains text1), to the backbuffer (which at this point is empty).
Now all the text should be in both buffers.

Hope this works,
Sven Vermeulen, Netherlands.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!