Creating game on fle game engine - DirectX 9c Draw Line - This can be helpful
The purpose of this lesson is simple - to show how use directx 9c for drawn line.
It is sometimes necessary. For example in the Scene Editor in this way is drawn a grid, serving for accurate positioning of game objects in the scene.

The documentation for directx 9c is
ID3DXLine interface, and its methods to be used to draw lines.
However, there is no a full example of how to apply it all together.
We fill this gap, and at the end of the lesson, you can download the finished result.
All you need - is to have a basic source code to create a simple application directx 9c (it you too will be able to download), as well as a few dozen lines of code that will be required to perform a line drawing with directx 9c.
The bottom line is this:
Module start.h inside CD3DGameApp class declares the following fields and methods:
//draw line
ID3DXLine* m_pLine;
void CreateLine(IDirect3DDevice9* pd3dDevice);
void LineOnLostDevice();
void LineOnResetDevice();
void FillPixel(int x, int y, int w, int h, DWORD color);
void FreeLine();
void DrawPoint(float x, float y, DWORD color);
void DrawLine(float x, float y, float x2, float y2, float width, DWORD color);
Module start.cpp implement them.
CD3DGameApp::CD3DGameApp()
{
//...
m_pLine = NULL;
void CD3DGameApp::CreateDeviceObjects(IDirect3DDevice9* pd3dDevice)
{
CreateLine(pd3dDevice);
}
HRESULT CD3DGameApp::RestoreDisplayObjects(IDirect3DDevice9* pd3dDevice)
{
//...
LineOnResetDevice();
}
HRESULT CD3DGameApp::DestroyDisplayObjects()
{
//...
FreeLine();
}
HRESULT CD3DGameApp::InvalidateDisplayObjects()
{
//...
LineOnLostDevice();
}
//draw line
void CD3DGameApp::CreateLine(IDirect3DDevice9* pd3dDevice)
{
D3DXCreateLine(pd3dDevice, &m_pLine);
}
void CD3DGameApp::LineOnLostDevice()
{
if ( m_pLine != NULL )
{
m_pLine->OnLostDevice();
}
}
void CD3DGameApp::LineOnResetDevice()
{
if ( m_pLine != NULL )
{
m_pLine->OnResetDevice();
}
}
void CD3DGameApp::FillPixel(int x, int y, int w, int h, DWORD color)
{
D3DXVECTOR2 vLine[2];
if ( m_pLine != NULL )
{
m_pLine->SetWidth( (float)w );
m_pLine->SetAntialias( false );
m_pLine->SetGLLines( true );
vLine[0].x = (float)(x + w/2);
vLine[0].y = (float)y;
vLine[1].x = (float)(x + w/2);
vLine[1].y = (float)(y + h);
m_pLine->Begin();
m_pLine->Draw( vLine, 2, color );
m_pLine->End();
}
}
void CD3DGameApp::FreeLine()
{
SAFE_RELEASE( m_pLine );
}
void CD3DGameApp::DrawPoint(float x, float y, DWORD color)
{
FillPixel((int)x, (int)y, 1, 1, color);
}
void CD3DGameApp::DrawLine(float x, float y, float x2, float y2, float width, DWORD color)
{
D3DXVECTOR2 vLine[2];
if ( m_pLine != NULL )
{
m_pLine->SetWidth( width );
m_pLine->SetAntialias( false );
m_pLine->SetGLLines( true );
vLine[0].x = x;
vLine[0].y = y;
vLine[1].x = x2;
vLine[1].y = y2;
m_pLine->Begin();
m_pLine->Draw( vLine, 2, color );
m_pLine->End();
}
}
void CD3DGameApp::DrawGameView()
{
//draw line
DrawPoint(30.0f, 30.0f, 0xFFFF0000);
DrawLine(10.0f, 50.0f, 300.0f, 50.0f, 1.0f, 0xFFFFFF00);
DrawLine(80.0f, 210.0f, 400.0f, 120.0f, 2.0f, 0xFF00FF00);
DrawLine(500.0f, 310.0f, 200.0f, 80.0f, 1.0f, 0xFFFFC017);
}
That's all ! So we learned to draw points and lines of any color and position. The color code can be used and the alpha - the first pair of numbers, it will set the translucency of the depicted primitives. 0xFFFFC017 - FF - alpha value i. e. 255.
Line Object - m_pLine passes all the same stages as any other directx 9c Object: creating CreateLine, LineOnResetDevice reset, invalidation LineOnLostDevice, Freeline freeing, and of course drawing DrawLine. If you want to animate a line, then you will still need to implement the method of animation, such as AnimLine, called from the method CD3DGameApp::FrameMove of your application.
Download Example Draw Line with full source code (524 Kb).
To build the project normally, you will need an DX SDK Aug 2008 and MSVS 2005 development environment
Read more about the project settings refer to the attached inside the self-extracting archive file readme.txt
to content
:
0

0

|
|
|
|
,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
,
|
|
|
|
|
|
|
|
|
|
|
|
|
, , 2020 - ,
|
|
|
|
|
|
|
|
|
|
, , , .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(3), (1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(3), (1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
,
|
 anova
|
 A Knots Story |
 sabotage |
|
|
|
|
|
|
|
,
|
|
|
|
|
|
|
,
|
|
|
|
|
|
|
, ,
|
|
|
|
|
|
|
, ,
|
|
|
|
|
|
|
, , cms,
|
|
|
|
|
|
|
,
|
|
|
|
|
|
|
, , ria xxl , fly snow 3d , . -
|
|
|
|
|
|
fle game engine -
|
|
|
|
|
|
- / megainformatic cms express files -
|
|
|
|
|
|
Flash, Flash - .
|
|
|
|
|
|
(multi lang), , . - (megainformatic cms social), megainformatic cms groupon, keywords gen + , .
megainformatic.ru/webjob/ -
- |
|
|
megainformatic.ru/webjob/
megainformatic.ru/webjob/ -
- |
|
|
|
|
|
,
megainformatic cms admin -
|
|
|
|
|
|
350 . |
5800 . |
3000 . |
500 . |
|
|
|
|
|
|
|
|
|
|
|
|
megainformatic cms free - Photoshop
,
Adobe Photoshop. ,
- GIMP, Corel Photo Paint .
|
|
|
|
|
|
2d 3d, , !
. ,
,
!!! ( , ! ). |
|
|
|
|
|
|
|
|
|
|
|
,
: -
350 . |
510 . |
fle game engine |
|
- , ,
, .
- - :
- |
|
|
|
|
|
|
|
|
|
|
|
, 3ds max, photoshop, c++,
directx, delphi php.
,
.
. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Photoshop free,
delphi directx - , !,
mp3 - ,
megainformatic cms express -
php + my sql. |
|
|
|
|
|
|
|
|
|
|
|
,
, delphi directx 8.1 (
3d ), 3d studio max, -
Fruity Loops Studio |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|