Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert 2D GDI+ to DirectDraw

215 views
Skip to first unread message

Siegfried Heintze

unread,
Feb 27, 2009, 1:24:01 PM2/27/09
to
Darn! I was looking at a good response to one of my old posts and outlook
express decided to suddenly referesh with and my response was gone!

Does anyone know where I might retrieve the old message?

I think this was my original query:

I have some gdiplus graphics written in C++ and I wanted to investigate
better performance using DirectDraw. How would I convert them? The problem
with every direct draw example I have seen is that they draw very fancy 3D
images and I want a minimal DirectDraw program that just draws some
rectangles, text, line segments and images with no fancy 3D projections,
textures or lighting effects (to begin with). Then I would like a second
example that has just minimal 3d projects: maybe rotating some text in 3D.
I've looked thru all the examples that come with the SDK and several books
and every example is far more sophisticated than what I want.

Thanks,
Siegfried


Ron Francis

unread,
Feb 27, 2009, 6:14:12 PM2/27/09
to
"Siegfried Heintze" <sieg...@heintze.com> wrote in message
news:eKjTgiQm...@TK2MSFTNGP02.phx.gbl...

I can't help you find your old post but ...
The DirectX SDK has some simple tutorials on how to set up a DX window and create a device.
1: Creating a device
2: Rendering vertices
3: Using Matrices
etc.
That is what you would need for rotating something in 3d.

For emulating simple GDI+ calls, you still have to create the device as above, but you can draw
directly to a surface.
Look at GetBackBuffer( ) that will give you a surface to draw on. Or you can create your own surface
with CreateOffscreenPlainSurface( ) or CreateRenderTarget( )
The basic idea is that you clear your surface, draw to it and Present( ) it at the end which blits
the surface to front buffer and becomes visible.
Have a look at D3DXCreateLine( ) for drawing lines and rectangles.
ColorFill( ) will draw filled rectangles.
D3DXGetImageInfoFromFile( ) and D3DXLoadSurfaceFromFile( ) will load and display a bitmap.

It is a pretty simple set of commands though, and if you wanted to draw a circle for example, you
would have to write your own algorithm.

Hope that helps.
Ron.

Siegfried Heintze

unread,
Mar 3, 2009, 8:53:08 PM3/3/09
to
Thank you! The previous post said something about drawing a triangle first
so I have a surface to draw on? Does that make any sense?


Ron Francis

unread,
Mar 4, 2009, 12:51:10 AM3/4/09
to
"Siegfried Heintze" <sieg...@heintze.com> wrote in message
news:eCmGIwGn...@TK2MSFTNGP02.phx.gbl...

> Thank you! The previous post said something about drawing a triangle first so I have a surface to
> draw on? Does that make any sense?


Yes,
If you want to be able to rotate things, you have to create polygons and polygons are made up of
triangles.
If you put two triangles together to form a rectangle, you can stick a bitmap on it and from there
you can translate and rotate it however you want.
However, if you are only interested in 2d, you can get away with drawing directly to the surface.

I have tried to layer several surfaces with transparencies without success and I don't think it's
possible.
But this can be done by creating polygons the same size as your window, putting textures on them
that have alpha (transparency or translucency), and overlapping them.
At least this works with bitmaps.
I haven't tried drawing to a texture on a polygon but I don't think there would be a problem there.

There are some here that are much better versed in DX than me, so I'm sure they will correct me if
I'm wrong.

Regards
Ron Francis
www.RonaldFrancis.com

Siegfried Heintze

unread,
Mar 6, 2009, 7:34:34 PM3/6/09
to
Thanks so much for all your help.

You say the DirectX SDK has some samples.
(1) I don't remember if I have the DirectX SDK installed on this computer.
Is there a pointer in the registry or in the environment variables somewhere
that indicates the SDK directory?
(2) I've ran all, or nearly all, the C++ examples in the SDK. They all have
thousands of lines of code. Is there one in particular that would be a good
jumping off place for getting started with ColorFill or D3DXCreateLine?

I just found my DirectX SDK and did a recursive search for D3DXCreateLine
and ColorFil in all the .h, .cpp and .cs files and was dissapointed that I
could not find a single match (I later looked in the managed directory and
could not find a match there either). I also have the DirectX book from
Microsoft press and cannot find an example in there either!

Could you do a similar search on your SDK? Maybe my SDK is old.

I just looked in c:\Program Files\Microsoft DirectX SDK (December
2006)\Samples\Managed\Direct3D\Simple2D\Simple2D.cs and found that it draws
sprites! darn! not what I want!

(3) I would love to have a minimal program that called D3DXCreateLine or
ColorFil. I have google searched with no luck as well. Can you recommend
one?

Thanks!
Siegfried

Ron Francis

unread,
Mar 8, 2009, 4:09:38 AM3/8/09
to
"Siegfried Heintze" <sieg...@heintze.com> wrote in message
news:OgcaOyrn...@TK2MSFTNGP06.phx.gbl...

I haven't searched for simple files that use those functions, but it certainly doesn't surprise me
that there aren't any because it is mainly geared to creating 3d stuff.
If you install tutorial 1: CreateDevice, then you should be able to insert this function somewhere
to draw a line.
The function is embedded into a large program so I can only snip this bit out for you.

void DrawRectangle(RECT p,D3DCOLOR colour){
//Should be called inbetween BeginScene() and EndScene()
int num=5;
HRESULT hres;
D3DXVECTOR2 *v=new D3DXVECTOR2[num];

v[0].x=(FLOAT)p.left;
v[0].y=(FLOAT)p.top;
v[1].x=(FLOAT)p.right;
v[1].y=(FLOAT)p.top;
v[2].x=(FLOAT)p.right;
v[2].y=(FLOAT)p.bottom;
v[3].x=(FLOAT)p.left;
v[3].y=(FLOAT)p.bottom;
v[4].x=(FLOAT)p.left;
v[4].y=(FLOAT)p.top;

LPD3DXLINE pLine;
hres=D3DXCreateLine(g_pd3dDevice,&pLine);
hres=pLine->SetAntialias(0);
hres=pLine->Begin();
hres=pLine->Draw( v, num, colour );
hres=pLine->End();
pLine->Release();
delete []v;
}

The 'new' is unnecessary and was included for possible expansion into drawing polygons and there is
no error checking, but the function should work.
g_pd3dDevice is a global LPDIRECT3DDEVICE9 pointer.
I don't used the managed stuff.

Hope that helps.

Ron.

Chuck Walbourn [MSFT]

unread,
Mar 10, 2009, 2:51:34 PM3/10/09
to
Note that the new Direct2D API (in the latest DirectX SDK as a Technical
Preview) is a Windows Vista & Windows 7 API that draws a more rich selection
of 2D primitives and works well with a Direct3D device. You might want to
take a look if you want more than the simple scanline algorithms in D3DX9.

--
-Chuck Walbourn
SDE, XNA Developer Connection

This posting is provided "AS IS" with no warrenties, and confers no rights.

Siegfried Heintze

unread,
Apr 22, 2009, 2:32:41 AM4/22/09
to

I'm studying the vertices tutorial (c:\Program Files\Microsoft DirectX SDK
(December 2006)\Samples\C++\Direct3D\Tutorials\Tut02_Vertices\Vertices.cpp).
I want to modify it to display some text and I'm looking at the Text3D and
SimpleSample for guidance. I want modify the vertices.cpp example to display
some text at each triangle vertex.

I've created a font and a sprite by stealing code from the c:\Program

Files\Microsoft DirectX SDK (December

2006)\Samples\C++\Direct3D\SimpleSample\SimpleSample.cpp.

I've drawn a few extra line segments too. This seems to be working!

I've inserted the call to DrawTextW and it is not displaying any text that I
can see. Do I have a bad coordinates, color or something else? It looks like
DrawText wants 2D coordinates and DrawPrimative wants 3D coordinates. I'm
probably not drawing in the right rectangle. Or maybe my font size is too
small. I used a font size of 15 as per the SimpleSample.cpp example. What
is the two dimensional coordinate system I'm using?

I create the font and the sprite in the function InitVB. I checked the
HRESULT and it is S_OK in both cases.

Thanks!
Siegfried


VOID Render()
{
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255),
1.0f, 0 );

// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Draw the triangles in the vertex buffer. This is broken into a
few
// steps. We are passing the vertices down a "stream", so first we
need
// to specify the source of that stream, which is our vertex buffer.
Then
// we need to let D3D know what vertex shader to use. Full, custom
vertex
// shaders are an advanced topic, but in most cases the vertex
shader is
// just the FVF, so that D3D knows what type of vertices we are
dealing
// with. Finally, we call DrawPrimitive() which does the actual
rendering
// of our geometry (in this case, just one triangle).
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
g_pd3dDevice->DrawPrimitive( D3DPT_LINELIST , 3, 1 );
g_pd3dDevice->DrawPrimitive( D3DPT_LINELIST , 4, 1 );
g_pd3dDevice->DrawPrimitive( D3DPT_LINELIST , 5, 1 );


RECT rc = {5, // left
5, // top
100, // right
20}; // bottom

g_pFont->DrawTextW(g_pTextSprite, L"Hello", -1, &rc, DT_NOCLIP,
D3DXCOLOR(1.0f,1.0f,1.0f,1));

// End the scene
g_pd3dDevice->EndScene();
}


Siegfried Heintze

unread,
Apr 22, 2009, 12:50:53 PM4/22/09
to
I was just looking at the next in the tutorial: c:\Program Files\Microsoft
DirectX SDK (December
2006)\Samples\C++\Direct3D\Tutorials\Tut03_Matrices\Matrices.cpp and trying
to understand how they set up the world coordinates. I think I want my text
to rotate with the triangle vertices. I guess I would need to specify the 3D
plane I want the text to appear in and the up vector in that plane.How would
I do this? Is there an example?

Thanks,
Siegfried


0 new messages