🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Directx Blitting Problem form a Beginner

Started by
1 comment, last by Lafo 24 years, 10 months ago
Well, your code looks good, but there is a little problem : in the main loop (after the while (1) {...) you have to blt the image in each frame, like this :
while(1)
{

hr = g_pDDS->Blt(&rectDest, g_pVaisseau, &rectSrc, DDBLT_WAIT,NULL);

and so on
}
Now, you could say : "Why?". The key is inside the Flip Method. When you call it, the Video Board "exchanges" the primary surface with the secondary surface. In fact, it thinks the primary surface is the secondary, and vice versa. This will happen each time you call Flip.

Good luck....

Advertisement
Hi, I'm creating my first directX application
and I'm having problems blitting. I'm using ddutil.cpp that comes with directx 6.1.

Here is a part of my code:

void Game_Init(void)
{
g_pVaisseau = DDLoadBitmap(g_pDD, "vaisseau.bmp",0,0);
ShowCursor(0);

}

void Game_Main(void)
{
HRESULT hr;

RECT rectSrc, rectDest;
rectSrc.left = rectSrc.top = 0;
rectDest.left = rectSrc.top = 0;
rectSrc.right = rectSrc.bottom = 150;
rectDest.right = rectDest.bottom = 150;

hr = g_pDDS->Blt(&rectDest, g_pVaisseau, &rectSrc, DDBLT_WAIT,NULL);

while(1)
{
hr = g_pDDS->Flip(NULL, 0);
if (hr == DD_OK)
break;
if (hr = DDERR_SURFACELOST)
{
hr= g_pDDS->Restore();
if (FAILED(hr))
break;
}
if (hr != DDERR_WASSTILLDRAWING)
break;
}

}

My program start without problem, but nothing is drawn to the screen. My application quit normally when I press ESC which means the prog isn't freeze.

Know my problem?

well actually the guy who posted before me is correct in the fact that you need to blit each loop.. but if you Blit once it should still give you a flicker of the blitted bmp in video memory so you would see something..dirty memory.. but it would still be the bmp if it was blitted.

It sounds almost like your BMP isn't loading correctly.
Check the return codes from the ddutil routine that loads your bitmap.
It's been awhile..but make sure you created a surface for that bmp to be loaded into. I remember some routines in ddutil.cpp used to create surfaces on the fly.. but you might want to make your own and see if you can load the bmp into it.

So..
1: Check your return codes (no matter what dx routine)
2: Make sure your bmp exists... if stored in a directory like c:\pix\pix.bmp.. you would say c:\\pix\\pix.bmp when loading.
3: Make sure you have enough video mem. maybe the surface is trying to create in vid ram.. and you are set at 1280x1024 24 bit color and you have a 2 meg vid card with double buffer active. You probably wont be able to load the bmp at that point.
4: always blit through a loop... do your flips... and umm.. maybe clear the display before a blit to see if anything shows up.. But I recommend that you take off clearing the display each loop ( that will slow yah down..unless you are doing dirty rects routines)

Latez bro,
DL

This topic is closed to new replies.

Advertisement