Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ DirectX 9';在顶点缓冲区更改数据时绘制线_C++_Directx 9_Vertex Buffer - Fatal编程技术网

C++ DirectX 9';在顶点缓冲区更改数据时绘制线

C++ DirectX 9';在顶点缓冲区更改数据时绘制线,c++,directx-9,vertex-buffer,C++,Directx 9,Vertex Buffer,我试图画一条线,线的起点或终点随时间变化(即每帧都有新的位置),但它不起作用 我使用D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC创建了顶点缓冲区,并将池设置为D3DPOOL_DEFAULT,但在更改顶点时它不会显示任何内容 事实上,只有当缓冲区内的顶点数据不变时,才会显示和绘制该线。有人能告诉我有什么问题吗 以下是我得到的代码: Line.h #include"Mesh.h" class Line : public Mesh { public: Line(

我试图画一条线,线的起点或终点随时间变化(即每帧都有新的位置),但它不起作用

我使用
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC
创建了顶点缓冲区,并将池设置为
D3DPOOL_DEFAULT
,但在更改顶点时它不会显示任何内容

事实上,只有当缓冲区内的顶点数据不变时,才会显示和绘制该线。有人能告诉我有什么问题吗

以下是我得到的代码:

Line.h

#include"Mesh.h"

class Line : public Mesh
{
public:
    Line(D3DCOLOR color, D3DXVECTOR3 startPoint, D3DXVECTOR3 endPoint);
    virtual ~Line();

    void SetPoints(D3DXVECTOR3 startPoint, D3DXVECTOR3 endPoint);

    void Draw();
};
Line.cpp

#include"Line.h"

Line::Line(D3DCOLOR color, D3DXVECTOR3 startPoint, D3DXVECTOR3 endPoint) : Mesh()
{
    vertexCount = 2;
    vertices = new VERTEX[vertexCount];

    VERTEX vertex;
    vertex.position = startPoint;
    vertex.color = color;
    vertices[0] = vertex;

    vertex.position = endPoint;
    vertex.color = color;
    vertices[1] = vertex;

    DirectX::device->CreateVertexBuffer(sizeof(VERTEX) * vertexCount, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexBuffer, NULL);

    VOID* vertexLocking;
    vertexBuffer->Lock(0, 0, (void**)&vertexLocking, 0);
    memcpy(vertexLocking, vertices, sizeof(VERTEX) * vertexCount);
    vertexBuffer->Unlock();
}

Line::~Line()
{

}

void Line::SetPoints(D3DXVECTOR3 startPoint, D3DXVECTOR3 endPoint)
{
    vertices[0].position = startPoint;
    vertices[1].position = endPoint;

    VOID* vertexLocking;
    vertexBuffer->Lock(0, 0, (void**)&vertexLocking, D3DLOCK_DISCARD);
    memcpy(vertexLocking, vertices, sizeof(VERTEX) * vertexCount);
    vertexBuffer->Unlock();

}

void Line::Draw()
{
    UINT passNum = 4;
    DirectX::currentShaderEffect->Begin(&passNum, 0);
    DirectX::currentShaderEffect->BeginPass(4);

    DirectX::device->SetStreamSource(0, vertexBuffer, 0, sizeof(VERTEX));
    DirectX::device->SetVertexDeclaration(DirectX::vertexDec);
    DirectX::device->DrawPrimitive(D3DPT_LINELIST, 0, 1);

    DirectX::currentShaderEffect->EndPass();
    DirectX::currentShaderEffect->End();
}

你是如何改变点的位置的,你能粘贴代码吗?