PDA

View Full Version : Anyone here familiar with DirectX?


Ecrofirt
06-24-2004, 07:40 AM
Just wondering.

I'm starting to learn DirectX 7 for a game I'm doing.

RiZ III
06-24-2004, 07:53 AM
Are u using DirectDraw or D3D? Im good with DDraw and been messing around with D3D. The D3DX library is really nice.

Ecrofirt
06-24-2004, 08:15 AM
I figured I'd start with DirectDraw, since it's similiar to BitBlt which I'm used to.

I'm using it in Visual Basic, and I'm reading tutorials and stuff, but some of this is still over my head.

RiZ III
06-24-2004, 08:16 AM
Yea it takes a while to figure it out. But the results are nice :D

Ecrofirt
06-24-2004, 08:27 AM
Here's the thing that's really bugging me now.


Dim ddsd1 As DDSURFACEDESC2 'this describes the primary surface
Dim ddsd2 As DDSURFACEDESC2 'this describes the bitmap that we load
Dim ddsd3 As DDSURFACEDESC2 'this describes the size of the screen

Those three are dimensioned, and then later on, this happens:

'load the bitmap into a surface - backdrop.bmp
ddsd2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH 'default flags
ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
'An offscreenplain means that
'the user never actually gets to see the surface - it is just an are in memory.

ddsd2.lWidth = ddsd3.lWidth 'the ddsd3 structure already holds the size
'of the screen. We could replace it with 640 and 480 - it would have the same effect

ddsd2.lHeight = ddsd3.lHeight
'this is where the surface is created. You use the DDraw object to create a
'surface from the specified file name using the above description.

Where ddsd2 has values set to ddsd3's values. The problem is, before this, there is no mention of ddsd3 anywhere in the code. And the tutorial program (which this is copied from) works, which leaves me baffled.

RiZ III
06-24-2004, 08:52 AM
Arent all three defined up there as show? It has to be defined somewhere. Maybe in a header file or something.

Ecrofirt
06-24-2004, 08:54 AM
It's VB. There aren't any header files. that's what's so odd about it.

RiZ III
06-24-2004, 08:56 AM
hmm. That is really odd. Sorry dont know what to tell ya.

aaaaa0
06-24-2004, 09:25 AM
Are you absolutely sure ddsd3 isn't getting passed into some API which is filling it out before this?

Where's the source for this sample?

Maybe is working because ddsd3 is uninitalized and just happens to be all zeros, and maybe zero just happens to mean "use default size".

???

Ecrofirt
06-24-2004, 09:31 AM
www.directx4vb.com article (http://216.5.163.53/DirectX4VB/Tutorials/DirectX7/DD_Fullscreen.asp)

the only other spot where I see ddsd3 before what I pasted is here:


'get the screen surface and create a back buffer too
ddsd1.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
ddsd1.lBackBufferCount = 1
Set primary = dd.CreateSurface(ddsd1)

'Get the backbuffer
Dim caps As DDSCAPS2
caps.lCaps = DDSCAPS_BACKBUFFER
Set backbuffer = primary.GetAttachedSurface(caps)
backbuffer.GetSurfaceDesc ddsd3


Maybe that's it, and I just don't understand it enough. It lookes to me like it's getting the surface description from ddsd3, but ddsd3 hasn't had anything done to it yet.

this is at the beginning of the initialization of the program.

RiZ III
06-24-2004, 09:36 AM
Well actually since ddsd2 is the description for the bitmap you load, it doesnt really matter what you set its height/widht initially depending on how you do it. A lot of examples load the bitmap with the GDI functions, read the width and height from there and the description gets set from there when you do that.

Thats what might be happening in the example ur looking at.

Ecrofirt
06-24-2004, 09:43 AM
Hmm, maybe.

overbose
06-24-2004, 10:44 AM
I've enabled 'vb' and 'vb.net' syntax highlighting on the code tag.

aaaaa0
06-24-2004, 11:19 AM
www.directx4vb.com article (http://216.5.163.53/DirectX4VB/Tutorials/DirectX7/DD_Fullscreen.asp)

the only other spot where I see ddsd3 before what I pasted is here:


backbuffer.GetSurfaceDesc ddsd3


Maybe that's it, and I just don't understand it enough. It lookes to me like it's getting the surface description from ddsd3, but ddsd3 hasn't had anything done to it yet.

this is at the beginning of the initialization of the program.

What that line of code is probably doing is telling the backbuffer to copy its parameters into ddsd3.

Look in the documentation for the parameters for the GetSurfaceDesc API to verify that's what it does.

(I don't use VB, everything I write is in C.)

aaaaa0
06-24-2004, 11:22 AM
Found it:

http://msdn.microsoft.com/archive/en-us/ddraw7/directdraw7/vbddref_77tu.asp?frame=true


DirectDraw 7.0
DirectDrawSurface7.GetSurfaceDesc

The DirectDrawSurface7.GetSurfaceDesc method retrieves a description of the surface in its current condition.

object.GetSurfaceDesc(surface As DDSURFACEDESC2)

Parameters

object - Object expression that resolves to a DirectDrawSurface7 object.
surface - DDSURFACEDESC2 type to be filled with the current description of this surface.

Error Codes

If the method fails, it raises an error, and Err.Number can be set to one of the following values:

DDERR_INVALIDOBJECT
DDERR_INVALIDPARAMS


BTW, I would seriously suggest you skip DX7.

The DX7 interfaces are totally obsolete now, you'd be much better off learning DX9 instead. Use VB.NET or C#.NET instead. (Or if you want to go older-school, plain old C :-) ).

DaMan121
06-24-2004, 11:32 AM
Havent followed it much, but I dont think DirectDraw stuff has changed since 7, so if he is only screwin around with that, theres not much use for 9... until he starts on shaders that is :)

aaaaa0
06-24-2004, 12:02 PM
Havent followed it much, but I dont think DirectDraw stuff has changed since 7, so if he is only screwin around with that, theres not much use for 9... until he starts on shaders that is :)

DirectDraw is obsolete. They stopped supporting it after DX7.

MS merged DirectDraw and D3D in DX8, it's just called DirectX Graphics now and handles both 2D and 3D.

So I think he might as well just skip to DX9.

maharg
06-24-2004, 12:23 PM
DirectDraw has always been a bit lame. All it gives you, reliably, is a framebuffer. If the card could do any more high level processing (polygon drawing, certain kinds of hardware blting), it was pretty unlikely you'd ever get to use it.

aaaaa0
06-24-2004, 12:26 PM
DirectDraw has always been a bit lame. All it gives you, reliably, is a framebuffer. If the card could do any more high level processing (polygon drawing, certain kinds of hardware blting), it was pretty unlikely you'd ever get to use it.

Ya, it was (more or less) conceived of when all a video card could reliably do, was give you a framebuffer.

:-)

Diffense
06-24-2004, 12:38 PM
Ecrofirt, directraw may very well be sufficient for what you are doing.

If all you're doing is a 2d game then all you need is access to the frame buffer and the ability to copy bits around. No need to burden yourself with 3d concepts in order to do simpe things.

If you need direct, unimpeded access to the frame buffer directdraw (of which 7 is the last version) is all you've got so I'd hardly call it obsolete.

Unfortunately, I can't help you directly with the VB stuff.

maharg
06-24-2004, 12:58 PM
Ya, it was (more or less) conceived of when all a video card could reliably do, was give you a framebuffer.

:-)

To be sure, but it's still really weird that no effort was ever put into making it more useful until they merged it with d3d, finally. I guess it just wasn't high priority enough.

aaaaa0
06-24-2004, 01:16 PM
If you need direct, unimpeded access to the frame buffer directdraw (of which 7 is the last version) is all you've got so I'd hardly call it obsolete.

DirectDraw is obsolete. Everything that you can do with DirectDraw, you can pretty much do better with DX9.

If you just want CPU driven access to the frame buffer, just setup your swap chain, grab the back buffer from DX, LockRect(), and party on. (No you can't get access to the front buffer, but why would you want to? That would just cause flickering when you update anything.)

If you want to do something more sophisticated with sprites you can use ID3DXSprite if you want. It will handle all the state setting and stuff for you, and basically emulates 2D blits with 3D. As a side benefit, everything works much faster.

The only tradeoff is the code is a bit more complicated.

I still think he's better off just learning DX9.