DirectDraw / Double Buffering

Started by
4 comments, last by ReturnZero 24 years, 2 months ago
Hello I am doing a sample application to help me better understand Directx and double buffering. However, I ran into problems that no one can seem to solve. I created two buffers, and I am trying to just write simple text to the back buffer and then flip it to the front, however it is not working This is how I created the two buffers -> // ** THE START OF SURFACES ** // Clears out Memory for size ZeroMemory(&ddsd, sizeof(ddsd)); ZeroMemory(&ddscaps, sizeof(ddscaps)); // Gets pointer to primary surface ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; hret = lpdd->CreateSurface(&ddsd, &lpsurfpri, NULL); if(hret != DD_OK) DebugWindow(" FAILED - Surfaces Not Created - Primary Surface "); // Gets Pointer to the back surface ddscaps.dwCaps = DDSCAPS_BACKBUFFER; hret = lpsurfpri->GetAttachedSurface(&ddscaps, &lpsurfbac); if (hret != DD_OK) DebugWindow(" FAILED - Back Surface Not Created < or attached > "); This is how I am doing the Flip and the TextOut() if(bActive) // Test if the app is active { if(lpsurfpri->GetDC(&hdc) == DD_OK) // Test for valid HDC { if(bFront) { TextOut(hdc,10,10,frontmsg,strlen(frontmsg)); bFront = !(bFront); } else { TextOut(hdc,10,10,backmsg,strlen(backmsg)); bFront = !(bFront); } } lpsurfpri->ReleaseDC(hdc); //lpsurfpri->Blt(&rect,lpsurfbac,NULL, DDBLT_WAIT, NULL ); } //lpsurfbac->Lock(); while(1) { hret = lpsurfpri->Flip(NULL, DDFLIP_WAIT); if(hret == DD_OK) { break; } if(hret == DDERR_SURFACELOST) { hret = lpsurfpri->Restore(); if(hret != DD_OK) { break; } } if(hret != DDERR_WASSTILLDRAWING) { break; } } //lpsurfbac->UnLock(); Now I dont get any syntax errors, just logical ones. I cant get the text to be drawn, any of it. I just get a blank black screen. I dont know what else to say, other than PLZ HELP ! Thanx again, for any help will be greatly apprecitated ReturnZero
Advertisement
It may be that your background and font colors are the same so you cannot see your text, so you need to set their respective colors. The modified routine would look something like this:
if( lpsurfpri->GetDC( &dc ) == DD_OK )
{
if( bFront )
{
SetBkColor(hdc, RGB( 0, 0, 0));
SetTextColor(hdc, RGB(0, 255, 255));
TextOut(hdc, 0, 0, frontmsg, lstrlen(frontmsg));
lpBack->ReleaseDC(hdc);
}
else
{
SetBkColor(hdc, RGB(255, 0, 0));
SetTextColor(hdc, RGB(0, 255, 255));
TextOut(hdc, 0, 0, backmsg, lstrlen(backmsg));
lpBack->ReleaseDC(hdc);
}

bFront = !bFront;
}

Also I don''t think that you need the line:
if( hRet != DD_OK )
in your flip function, it should look more like:
while( 1 )
{
hr = lpPrimary->Flip(NULL, 0);
if (hr == DD_OK)
break;

if (hr == DDERR_SURFACELOST)
{
hr = lpPrimary->Restore();
if (hr != DD_OK)
break;
}

if (hr != DDERR_WASSTILLDRAWING)
break;
}

---Ranok---
Hello
Im sorry Ranok, however, I tried what youtold me and it did not work, I still just have a plain blank screen with nothing happening. Any other idea''s ?
Thanx anyway for trying though
Make your code write out to a file the DDraw error code if a DDraw function fails... then run it, and check the log files to see what you get (if anything).

Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com
Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
I think the problem is that you get the DC to the primary surface and render the text to this DC.

When you perform the flip, the back buffer overwrites the primary buffer, therefore removing the text you''ve just drawn.

Change if(lpsurfpri->GetDC(&hdc) == DD_OK) to
if(lpsurfbac->GetDC(&hdc) == DD_OK) and it should work.

No sense being pessimistic. It wouldn''t work anyway.
===========================There are 10 types of people in the world. Those that understand binary and those that don't.( My views in no way reflect the views of my employer. )
Hello again
So far I have taken all the advice given to me, and none has worked thus far. I think it is my hardware ( I have a crappy video card ). I am triple checked, and I am now getting the dc to the back surface, and then flipping it. I have changed it to different colors, and none has worked thus far. I could not get the file io thing to work, for some reason, when I tried to use it, my application would execute, but it would not show me a window, I am still looking in to that. ANy other advice would be greatly apprecitated...I am in dire need of this fixed...Thank you

This topic is closed to new replies.

Advertisement