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
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.
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
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
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
SDE, XNA Developer Connection
This posting is provided "AS IS" with no warrenties, and confers no rights.
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();
}
Thanks,
Siegfried