Teen Programmers Unite  
 

 

Return to forum top

DirectDraw Questions

Posted by Cortez [send private reply] at June 04, 2003, 09:49:04 AM

1.How can I control the frame rate in DirectDraw?
2.I use double buffer. When I re-execute program in debug (VC++ 6.0), one layer(DDSurface) starts cleaned, but the other (always the same layer) includes the image from the previous runs. I delete the DD object on exit, and I also tried using ->Release() for the back surface, but it says "Unhandled exception" on exit.

Posted by CViper [send private reply] at June 04, 2003, 04:46:46 PM

You always have to clear the buffers, otherwise they can contain random data (which might be the image from the previous run).

"I delete the DD object on exit" .. I hope you don't try to use the C++ delete-operator on the DD object? =)

You should always release the interfaces in the reverse order as you allocated them, i.e. if you first created the IDirectDraw interface then the primary IDirectDrawSurface and finally the secondary surface (back buffer), you should release first the secondary surface, then the primary surface and finally the IDirectDraw interface.

Posted by Cortez [send private reply] at June 06, 2003, 03:19:29 AM

I don't know, I did cleaning in the reverse order and it's just how it is :( I modified a tutorial file on Gamedev.net and working on it for learning. Here the current thing:

www27.brinkster.com/hexiumpdc/dxtemp.zip

I can't find the error :(

Posted by CViper [send private reply] at June 06, 2003, 06:48:57 AM

Weird.. just compiled & ran the application, and it worked fine for me (no exceptions / errors).

Although I noticed two things:
1) you don't clear the backbuffer each frame... you can do that by calling

DDBLTFX bltfx;
memset( &bltfx, 0, sizeof( DDBLTFX ) ); bltfx.dwSize = sizeof( DDBLTFX );
bltfx.dwFillColor = 0x00000000; // 0xAARRGGBB
lpDDSBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx );

2) You don't set a clipping area.. if you set a clipping area, Blt() automatically clips the surface you're blitting (that way you won't trash any memory). I think BltFast() ignores the clipping area anyway (you usually should stick to Blt() - with hardware acceleration there's almost no performance gain in using BltFast()).

[Edit] Another thing - you're using an old DirectDraw version (the oldest actually). You should consider start using the DirectX 7 interfaces (IDirectDraw7, IDirectDrawSurface7 etc).
If you wish, I can send you a short demo (source code) I wrote for school a while ago.[/Edit]
Posted by Cortez [send private reply] at June 06, 2003, 11:19:06 AM

I'm using DX came with VC++ 6.0 and I've been working on DirectDraw less than a week, so i'm realy lame.


I also don't know how to set a clipping area :( and one thing, if you go out of bounds in the program with the tile, say upwards, it doesn't refresh until you go back inside the screen (lemme guess, all about clipping area..) Is it an error for DirectDraw (BltFast was called with the error waiting flag)?

"If you wish, I can send you a short demo (source code) I wrote for school a while ago."

It'll be great :) darkangel064 at yahoo.com

Posted by CViper [send private reply] at June 06, 2003, 04:53:33 PM

First, you should download the new DirectX SDK (that is, if you have a decent internet connection - it's huge).

You can download the demo from http://www.newq.net/stuff/ddraw_demo.zip

Most of the interesting DirectDraw code can be found in the x_dd_base.h / x_dd_base.cpp files. (note: the line drawing / clipping algorithm is based on the code presented in "Tricks of the Windows Game Programming Gurus").
The CreateDirectDraw() function also includes code for initializing the clipper =)

The code actually "doing something" is in the animation.cpp / animation.h files.

Just ask if you need anything clarified. The code is a bit messy...

Posted by Cortez [send private reply] at June 07, 2003, 09:07:27 AM

Thanks! I probably won't be able to find enough time to read it until 16th of this month :( I've too many exams, the finals. I hope the topic won't be locked until then though.

Posted by Mike_L [send private reply] at June 08, 2003, 05:46:20 PM

I don't think you should bother with the new DirectX SDK. Most people don't use DirectDraw features that came out after DirectX 2.0. You should install the DirectX SDK examples from your VC++6.0 CDs and learn how they work. It can be quite difficult to set up VC++ to use a new version of DirectX.

I looked at your dxtemp.zip project and noticed that it has a lot of unneccessary stuff in it. It also seems to be very very poorly organized. It sounds like you need to understand the very basic concepts of graphics programming and DirectDraw operation. I suggest you look for a more organized tutorial; something that's basic.

I played around with DirectDraw a while back. I put one of my projects, Gorbin Fire Demo, on my website. (http://www.tamale.net/) I made a C++ class, DDrawPane, that encapsulates DirectX. The program draws a simple moving fire pattern. The code isn't the best I've written (I wrote it six years ago), but it demonstrates the proper way to use DirectX.

I also have exams this week. To add insult to injury, the heartless administrators of my school (COD) decided that the summer quarter should begin immediately after the spring quarter ends. My last exam is on Thursday, and the next quarter starts on Monday.

Posted by CViper [send private reply] at June 09, 2003, 06:07:29 AM

Most DirectX SDKs automatically set up VC++ to use the new headers/libraries. Otherwise you just have to add the correct paths under Tools->Options->Directories.

Whatever - you could probably compile my demo using a earlier DirectDraw version. Start be removing the '7' at the end of each direct draw interface name =)

/me is right now enjoying his 10-week (?) summer vacation :p

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.