Jump to content
  • Advertisement


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


DirectX 8, where's DirectDraw??

This topic is 6090 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

I''m currently making a game engine using the Direct3D 8 SDK. I would like to know where to find some source code for writing a basic DirectDraw wrapper for Direct3D 8. Your help is appreciated.

Share this post

Link to post
Share on other sites
But if you have the choice, it will probably be better doing it with DX7. This way you should get (AFAIK): more speed than with using the 3d stuff, more versatility (in some cases), and some other pros. I think that, at the current time, that decision of taking DD away was a bad move... but in the future D3d will surely be a better option.

--H. Hernán Moraldo

Share this post

Link to post
Share on other sites
Original post by DoctorK
This way you should get (AFAIK): more speed than with using the 3d stuff

AFAIK, Modern 3D cards (3dfx voodoo 3 upwards) are heavily optimised for drawing textured triangles at the expense of framebuffer access (pixel plotting and blitting). Its even worse for cards like the GeForce, because while you have the framebuffer locked to write pixels to it, the GPU has to idle.

If you`re planning to use modern hardware, you get more speed and flexibility by using D3D8 (you can use alpha blending, and hardware accelerated scaling and rotation). Its harder to write though...

The tutorial InvaderX mentioned is well worth a look.

Share this post

Link to post
Share on other sites
Agreed. It should be just as fast or faster, expecially if you are doing rotation, scaling, and blending.

If you have a geForce3, watch nVidia''s image processing sample. It can do a find edges filter at 100+ fps. That''s really, really fast (and 2D).

Share this post

Link to post
Share on other sites
Thanks a lot, but you''re kinda late . I already figured out a wrapper (without D3DXSprite), and I''m no longer in the mood to learn another wrapper :D. However, how do I make my program load a 640x480 texture and display it correctly? Currently, the texture is loaded w/ default parameters (0,0 for width&height), and it looks like a 256x256 texture stretched to 640x480! How do I make it not stretch? (In other words, can I load just one part (256x256) from the texture and display that on one part (0.4 x 0.5333) of the material, and then load the next part, and display it on the next part of the material?

Here''s the code for my simple wrapper functions:

// Create Rectangle (Creates a rectangular primitive w/ size specified)
LPDIRECT3DVERTEXBUFFER8 CreateRectangle(float x, float y, float w, float h)
float PanelWidth = w;
float PanelHeight = h;

dx8.pd3dDevice->CreateVertexBuffer(4 * sizeof(PANELVERTEX), D3DUSAGE_WRITEONLY,

g_pVertices->Lock(0, 4 * sizeof(PANELVERTEX), (BYTE**)&pVertices, 0);

//Set all the colors to white
pVertices[0].d = pVertices[1].d = pVertices[2].d = pVertices[3].d = 0xffffffff;

//Set positions and texture coordinates
pVertices[0].x = pVertices[3].x = -320 + x;
pVertices[1].x = pVertices[2].x = -320 + PanelWidth + x;

pVertices[0].y = pVertices[1].y = 240 - y;
pVertices[2].y = pVertices[3].y = 240 - PanelHeight - y;

pVertices[0].z = pVertices[1].z = pVertices[2].z = pVertices[3].z = 1.0f;
pVertices[1].u = pVertices[2].u = 1.0f;
pVertices[0].u = pVertices[3].u = 0.0f;

pVertices[0].v = pVertices[1].v = 0.0f;
pVertices[2].v = pVertices[3].v = 1.0f;


return g_pVertices;

// similar to DDraw one, but sets a texture & displays a rectangular primitive.
void Blt(LPDIRECT3DTEXTURE8 texture, int x, int y, int w, int h)
dx8.pd3dDevice->SetTexture(0, texture);
dx8.pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
dx8.pd3dDevice->SetStreamSource(0, CreateRectangle((float)x, (float)y, (float)w, (float)h), sizeof(PANELVERTEX));
dx8.pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);

// Loads texture & returns pointer to it
LPDIRECT3DTEXTURE8 LoadTexture(char *filename, int w, int h)
// Set black as our source color key. Use 0xFFFF00FF for magenta instead.
// Use 0x00000000 for no ''color key'' substitution
D3DCOLOR colorkey = 0xFF000000;
// The D3DX function will fill in the following image info for us
//D3DXIMAGE_INFO SrcInfo; // Optional

// Load image from file - maintain size of original file.
// It is also possible to specify a new height/width and ask D3DX to filter
// the image to the new size (stretch/shrink). See SDK docs for details.
D3DXCreateTextureFromFileEx( dx8.pd3dDevice, filename, w, h, 0, 0,
colorkey, NULL , NULL, &pd3dTexture);
// Check the return value here, etc

// Remember, textures sizes may be larger or smaller than your image,
// to allow for legal texture sizes & maximums on user''s hardware
return pd3dTexture;

Please look over my code, and suggest a method to solve the problem mentioned above.

Thanks for all your help!

Share this post

Link to post
Share on other sites
D3DX tries to do alot of work for you, but in some cases, it may produce suboptimal results.

Try this...

1. Create a 256x256 texture (remember, you can ask the device what it''s max dimensions are before you load textures)

2. Call IDirect3DTexture8->GetSurfaceLevel to get the surface interface.

3. Call D3DXLoadSurfaceFromFileA to load only a subset into that surface.

Yes, sometimes it can be alot of work, but once you get the wrapper together, this is much better than DirectDraw looking forward to "modern cards". Also, current cards support much bigger textures and future cards will drop the powers of 2 requirements. So, you have to jump through some hoops, but Direct3D is still a better way to go from the standpoint of learning longer term skills.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!