C++ 使用Directx10进行渲染
在运行期间,我希望初始化期间在程序中成功创建和绘制的所有对象在每次调用GraphicsClass::Render()函数时都会更改其位置。但什么也没发生:所有的数字(我的例子中的点)都静止不动,没有任何运动 我知道Directx10中常用的方法是使用世界、视图和投影矩阵。但在这里我直接更改了缓冲区,然后将其发送到ID3D10Device对象进行绘制,因为我需要绘制许多具有不同轨迹的对象,每个对象都由一个点表示 我怀疑错误可能在方法ColorShaderClass::SetShaderParameters中。因此,我只附加了与程序中的渲染直接相关的代码 图形类hC++ 使用Directx10进行渲染,c++,3d,directx,directx-11,directx-10,C++,3d,Directx,Directx 11,Directx 10,在运行期间,我希望初始化期间在程序中成功创建和绘制的所有对象在每次调用GraphicsClass::Render()函数时都会更改其位置。但什么也没发生:所有的数字(我的例子中的点)都静止不动,没有任何运动 我知道Directx10中常用的方法是使用世界、视图和投影矩阵。但在这里我直接更改了缓冲区,然后将其发送到ID3D10Device对象进行绘制,因为我需要绘制许多具有不同轨迹的对象,每个对象都由一个点表示 我怀疑错误可能在方法ColorShaderClass::SetShaderParame
class GraphicsClass
{
public:
GraphicsClass();
GraphicsClass(const GraphicsClass&);
~GraphicsClass();
bool Initialize(int, int, HWND);
void Shutdown();
bool Frame(double time);
private:
bool Render(double time);
private:
D3DClass * m_Direct3D;
CameraClass* m_Camera;
ModelClass* m_Model;
ColorShaderClass* m_ColorShader;
//amount of bodies
int m_bodies;
};
class ModelClass
{
private:
struct ModelVertex {
XMFLOAT4 Pos;
};
public:
ModelClass(int); //pass number of bodies
ModelClass(const ModelClass&);
~ModelClass();
bool Initialize(ID3D10Device*);
void Shutdown();
void Render(ID3D10Device*);
int GetIndexCount();
float * GetPositions();
private:
bool InitializeBuffers(ID3D10Device*);
void ShutdownBuffers();
void RenderBuffers(ID3D10Device*);
private:
ID3D10Buffer *m_vertexBuffer, *m_indexBuffer;
int m_vertexCount, m_indexCount;
float * m_positions;
float * m_velocities;
NBodySystemGPU * m_bodySystem;
int m_bodies;
};
class ColorShaderClass
{
private:
struct ColorVertex {
XMFLOAT4 Pos;
};
public:
ColorShaderClass(int); //pass number of bodies
ColorShaderClass(const ColorShaderClass&);
~ColorShaderClass();
bool Initialize(ID3D10Device*, HWND);
void Shutdown();
bool Render(ID3D10Device*, int,float *);
private:
bool InitializeShader(ID3D10Device*, HWND, WCHAR*, WCHAR*);
void ShutdownShader();
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
bool SetShaderParameters(ID3D10Device*,float *);
void RenderShader(ID3D10Device*, int);
private:
ID3D10VertexShader* m_vertexShader;
ID3D10PixelShader* m_pixelShader;
ID3D10InputLayout* m_layout;
ID3D10Buffer* m_matrixBuffer;
//Body system
int m_bodies;
};
图形类cpp
bool GraphicsClass::Render()
{
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.5f, 0.5f, 0.5f, 1.0f);
bool result;
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_Direct3D->GetDevice());
// Render the model using the color shader.
result = m_ColorShader->Render(m_Direct3D->GetDevice(), m_Model->GetIndexCount(),m_Model->GetPositions());
if (!result)
{
return false;
}
// Present the rendered scene to the screen.
m_Direct3D->EndScene();
return true;
}
void ModelClass::Render(ID3D10Device* device)
{
//update bodies' positions
bool result;
//m_bodySystem->update(0.00001f, m_positions, m_velocities, result);
for (int i = 0; i < m_bodies; ++i) {
m_positions[i] += 0.5;
}
InitializeBuffers(device);
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(device);
return;
}
void ModelClass::RenderBuffers(ID3D10Device* device)
{
unsigned int stride;
unsigned int offset;
// Set vertex buffer stride and offset.
stride = sizeof(ModelVertex);
offset = 0;
// Set the vertex buffer to active in the input assembler so it can be rendered.
device->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
// Set the index buffer to active in the input assembler so it can be rendered.
device->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
return;
}
bool ModelClass::InitializeBuffers(ID3D10Device* device)
{
unsigned long* indices;
D3D10_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
D3D10_SUBRESOURCE_DATA vertexData, indexData;
HRESULT result;
// Create the index array.
indices = new unsigned long[m_bodies];
if(!indices)
{
return false;
}
// Load the vertex array with data.
for (int i = 0; i < m_bodies; ++i) {
indices[i] = i;
}
// Set up the description of the vertex buffer.
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
vertexBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
vertexBufferDesc.ByteWidth = sizeof(ModelVertex) * m_bodies;
vertexBufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
vertexBufferDesc.MiscFlags = 0;
// Give the subresource structure a pointer to the vertex data.
ZeroMemory(&vertexData, sizeof(vertexData));
vertexData.pSysMem = m_positions;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;
// Now finally create the vertex buffer.
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if(FAILED(result))
{
return false;
}
// Set up the description of the index buffer.
ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));
indexBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_bodies;
indexBufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
indexBufferDesc.MiscFlags = 0;
// Give the subresource structure a pointer to the index data.
indexData.pSysMem = indices;
// Create the index buffer.
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if(FAILED(result))
{
return false;
}
// Release the arrays now that the vertex and index buffers have been created and loaded.
delete [] indices;
indices = 0;
return true;
}
bool ColorShaderClass::Render(ID3D10Device* device, int indexCount, float * positions)
{
bool result;
// Set the shader parameters that it will use for rendering.
result = SetShaderParameters(device,positions);
if (!result)
{
return false;
}
// Now render the prepared buffers with the shader.
RenderShader(device, indexCount);
return true;
}
bool ColorShaderClass::SetShaderParameters(ID3D10Device* device, float * positions)
{
HRESULT result;
void* mappedResource;
unsigned int bufferNumber;
// Lock the constant buffer so it can be written to.
result = m_matrixBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result))
{
return false;
}
// Get a pointer to the data in the constant buffer.
memcpy(mappedResource, positions, 4 * m_bodies * sizeof(float));
// Unlock the constant buffer.
m_matrixBuffer->Unmap();
// Set the position of the constant buffer in the vertex shader.
bufferNumber = 0;
// Finally set the constant buffer in the vertex shader with the updated values.
device->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);
return true;
}
void ColorShaderClass::RenderShader(ID3D10Device* device, int indexCount)
{
// Set the vertex input layout.
device->IASetInputLayout(m_layout);
// Set the vertex and pixel shaders that will be used to render the objects.
device->VSSetShader(m_vertexShader);
device->PSSetShader(m_pixelShader);
// Render the objects.
device->DrawIndexed(indexCount, 0, 0);
return;
}
modelclsss.h
class GraphicsClass
{
public:
GraphicsClass();
GraphicsClass(const GraphicsClass&);
~GraphicsClass();
bool Initialize(int, int, HWND);
void Shutdown();
bool Frame(double time);
private:
bool Render(double time);
private:
D3DClass * m_Direct3D;
CameraClass* m_Camera;
ModelClass* m_Model;
ColorShaderClass* m_ColorShader;
//amount of bodies
int m_bodies;
};
class ModelClass
{
private:
struct ModelVertex {
XMFLOAT4 Pos;
};
public:
ModelClass(int); //pass number of bodies
ModelClass(const ModelClass&);
~ModelClass();
bool Initialize(ID3D10Device*);
void Shutdown();
void Render(ID3D10Device*);
int GetIndexCount();
float * GetPositions();
private:
bool InitializeBuffers(ID3D10Device*);
void ShutdownBuffers();
void RenderBuffers(ID3D10Device*);
private:
ID3D10Buffer *m_vertexBuffer, *m_indexBuffer;
int m_vertexCount, m_indexCount;
float * m_positions;
float * m_velocities;
NBodySystemGPU * m_bodySystem;
int m_bodies;
};
class ColorShaderClass
{
private:
struct ColorVertex {
XMFLOAT4 Pos;
};
public:
ColorShaderClass(int); //pass number of bodies
ColorShaderClass(const ColorShaderClass&);
~ColorShaderClass();
bool Initialize(ID3D10Device*, HWND);
void Shutdown();
bool Render(ID3D10Device*, int,float *);
private:
bool InitializeShader(ID3D10Device*, HWND, WCHAR*, WCHAR*);
void ShutdownShader();
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
bool SetShaderParameters(ID3D10Device*,float *);
void RenderShader(ID3D10Device*, int);
private:
ID3D10VertexShader* m_vertexShader;
ID3D10PixelShader* m_pixelShader;
ID3D10InputLayout* m_layout;
ID3D10Buffer* m_matrixBuffer;
//Body system
int m_bodies;
};
modelclass.cpp
bool GraphicsClass::Render()
{
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.5f, 0.5f, 0.5f, 1.0f);
bool result;
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_Direct3D->GetDevice());
// Render the model using the color shader.
result = m_ColorShader->Render(m_Direct3D->GetDevice(), m_Model->GetIndexCount(),m_Model->GetPositions());
if (!result)
{
return false;
}
// Present the rendered scene to the screen.
m_Direct3D->EndScene();
return true;
}
void ModelClass::Render(ID3D10Device* device)
{
//update bodies' positions
bool result;
//m_bodySystem->update(0.00001f, m_positions, m_velocities, result);
for (int i = 0; i < m_bodies; ++i) {
m_positions[i] += 0.5;
}
InitializeBuffers(device);
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(device);
return;
}
void ModelClass::RenderBuffers(ID3D10Device* device)
{
unsigned int stride;
unsigned int offset;
// Set vertex buffer stride and offset.
stride = sizeof(ModelVertex);
offset = 0;
// Set the vertex buffer to active in the input assembler so it can be rendered.
device->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
// Set the index buffer to active in the input assembler so it can be rendered.
device->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
return;
}
bool ModelClass::InitializeBuffers(ID3D10Device* device)
{
unsigned long* indices;
D3D10_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
D3D10_SUBRESOURCE_DATA vertexData, indexData;
HRESULT result;
// Create the index array.
indices = new unsigned long[m_bodies];
if(!indices)
{
return false;
}
// Load the vertex array with data.
for (int i = 0; i < m_bodies; ++i) {
indices[i] = i;
}
// Set up the description of the vertex buffer.
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
vertexBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
vertexBufferDesc.ByteWidth = sizeof(ModelVertex) * m_bodies;
vertexBufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
vertexBufferDesc.MiscFlags = 0;
// Give the subresource structure a pointer to the vertex data.
ZeroMemory(&vertexData, sizeof(vertexData));
vertexData.pSysMem = m_positions;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;
// Now finally create the vertex buffer.
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if(FAILED(result))
{
return false;
}
// Set up the description of the index buffer.
ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));
indexBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_bodies;
indexBufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
indexBufferDesc.MiscFlags = 0;
// Give the subresource structure a pointer to the index data.
indexData.pSysMem = indices;
// Create the index buffer.
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if(FAILED(result))
{
return false;
}
// Release the arrays now that the vertex and index buffers have been created and loaded.
delete [] indices;
indices = 0;
return true;
}
bool ColorShaderClass::Render(ID3D10Device* device, int indexCount, float * positions)
{
bool result;
// Set the shader parameters that it will use for rendering.
result = SetShaderParameters(device,positions);
if (!result)
{
return false;
}
// Now render the prepared buffers with the shader.
RenderShader(device, indexCount);
return true;
}
bool ColorShaderClass::SetShaderParameters(ID3D10Device* device, float * positions)
{
HRESULT result;
void* mappedResource;
unsigned int bufferNumber;
// Lock the constant buffer so it can be written to.
result = m_matrixBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result))
{
return false;
}
// Get a pointer to the data in the constant buffer.
memcpy(mappedResource, positions, 4 * m_bodies * sizeof(float));
// Unlock the constant buffer.
m_matrixBuffer->Unmap();
// Set the position of the constant buffer in the vertex shader.
bufferNumber = 0;
// Finally set the constant buffer in the vertex shader with the updated values.
device->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);
return true;
}
void ColorShaderClass::RenderShader(ID3D10Device* device, int indexCount)
{
// Set the vertex input layout.
device->IASetInputLayout(m_layout);
// Set the vertex and pixel shaders that will be used to render the objects.
device->VSSetShader(m_vertexShader);
device->PSSetShader(m_pixelShader);
// Render the objects.
device->DrawIndexed(indexCount, 0, 0);
return;
}
colorshaders.cpp
bool GraphicsClass::Render()
{
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.5f, 0.5f, 0.5f, 1.0f);
bool result;
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_Direct3D->GetDevice());
// Render the model using the color shader.
result = m_ColorShader->Render(m_Direct3D->GetDevice(), m_Model->GetIndexCount(),m_Model->GetPositions());
if (!result)
{
return false;
}
// Present the rendered scene to the screen.
m_Direct3D->EndScene();
return true;
}
void ModelClass::Render(ID3D10Device* device)
{
//update bodies' positions
bool result;
//m_bodySystem->update(0.00001f, m_positions, m_velocities, result);
for (int i = 0; i < m_bodies; ++i) {
m_positions[i] += 0.5;
}
InitializeBuffers(device);
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(device);
return;
}
void ModelClass::RenderBuffers(ID3D10Device* device)
{
unsigned int stride;
unsigned int offset;
// Set vertex buffer stride and offset.
stride = sizeof(ModelVertex);
offset = 0;
// Set the vertex buffer to active in the input assembler so it can be rendered.
device->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
// Set the index buffer to active in the input assembler so it can be rendered.
device->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
return;
}
bool ModelClass::InitializeBuffers(ID3D10Device* device)
{
unsigned long* indices;
D3D10_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
D3D10_SUBRESOURCE_DATA vertexData, indexData;
HRESULT result;
// Create the index array.
indices = new unsigned long[m_bodies];
if(!indices)
{
return false;
}
// Load the vertex array with data.
for (int i = 0; i < m_bodies; ++i) {
indices[i] = i;
}
// Set up the description of the vertex buffer.
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
vertexBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
vertexBufferDesc.ByteWidth = sizeof(ModelVertex) * m_bodies;
vertexBufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
vertexBufferDesc.MiscFlags = 0;
// Give the subresource structure a pointer to the vertex data.
ZeroMemory(&vertexData, sizeof(vertexData));
vertexData.pSysMem = m_positions;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;
// Now finally create the vertex buffer.
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if(FAILED(result))
{
return false;
}
// Set up the description of the index buffer.
ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));
indexBufferDesc.Usage = D3D10_USAGE_DYNAMIC;
indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_bodies;
indexBufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
indexBufferDesc.MiscFlags = 0;
// Give the subresource structure a pointer to the index data.
indexData.pSysMem = indices;
// Create the index buffer.
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if(FAILED(result))
{
return false;
}
// Release the arrays now that the vertex and index buffers have been created and loaded.
delete [] indices;
indices = 0;
return true;
}
bool ColorShaderClass::Render(ID3D10Device* device, int indexCount, float * positions)
{
bool result;
// Set the shader parameters that it will use for rendering.
result = SetShaderParameters(device,positions);
if (!result)
{
return false;
}
// Now render the prepared buffers with the shader.
RenderShader(device, indexCount);
return true;
}
bool ColorShaderClass::SetShaderParameters(ID3D10Device* device, float * positions)
{
HRESULT result;
void* mappedResource;
unsigned int bufferNumber;
// Lock the constant buffer so it can be written to.
result = m_matrixBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result))
{
return false;
}
// Get a pointer to the data in the constant buffer.
memcpy(mappedResource, positions, 4 * m_bodies * sizeof(float));
// Unlock the constant buffer.
m_matrixBuffer->Unmap();
// Set the position of the constant buffer in the vertex shader.
bufferNumber = 0;
// Finally set the constant buffer in the vertex shader with the updated values.
device->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);
return true;
}
void ColorShaderClass::RenderShader(ID3D10Device* device, int indexCount)
{
// Set the vertex input layout.
device->IASetInputLayout(m_layout);
// Set the vertex and pixel shaders that will be used to render the objects.
device->VSSetShader(m_vertexShader);
device->PSSetShader(m_pixelShader);
// Render the objects.
device->DrawIndexed(indexCount, 0, 0);
return;
}
color.ps
// Pixel Shader
float4 PS( float4 Pos : SV_POSITION ) : SV_Target
{
return float4( 1.0f, 1.0f, 1.0f, 1.0f ); // White, with Alpha = 1
}
// GLOBALS
cbuffer MatrixBuffer {
float4 updatedPosition;
};
float4 VS( float4 Pos : POSITION ) : SV_POSITION
{
return Pos;
}
color.vs
// Pixel Shader
float4 PS( float4 Pos : SV_POSITION ) : SV_Target
{
return float4( 1.0f, 1.0f, 1.0f, 1.0f ); // White, with Alpha = 1
}
// GLOBALS
cbuffer MatrixBuffer {
float4 updatedPosition;
};
float4 VS( float4 Pos : POSITION ) : SV_POSITION
{
return Pos;
}
更新
float*m_位置中存储的值时代码>
您正在更改CPU端的值。它不是存储在gpu上的实际值,即您在创建m_vertexBuffer
为此,需要调用渲染函数Initialize(ID3D10Device*,HWND)代码>再次
应该有一行代码,如下所示:
vertexData.pSysMem = vertices;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;
// Now create the vertex buffer.
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
这里是你的m_位置+你的颜色,我怀疑
不建议这样做,但应该这样做
如果要进一步查看,需要使用D3D11\u USAGE\u DYNAMIC
标志创建此缓冲区,并使用更新值
D3D11_MAPPED_SUBRESOURCE resource;
d3dDeviceContext->Map( vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource );
memcpy( resource.pData, sourceData, vertexDataSize );
d3dDeviceContext->Unmap( vertexBuffer, 0 );
看看:
我希望你能找到与你相关的东西。
Razterizer非常棒看起来您的Graphics::Render类两次调用BeginScene。我不知道这是否是你的问题的根源,但这似乎是你想要解决的问题。谢谢。当然,第一个电话是不必要的。问题仍然存在。根本没有理由使用Direct3D 10。您应该使用Direct3D 11,它有更好的、更多的功能,并且有更多的社区支持。另见。Direct3D 10的端口是直接向前的。请参阅,初始化是以相同的方式完成的。问题实际上可能出在m_verexBuffer更新中。现在,我将尝试找到在Directx10中映射()和取消映射()的方法,并与大家分享结果。我想指出的是,当顶点偏移0.5时,这些新值不是gpu上的值。在再次调用RenderBuffers()调用InitializerBuffer之前,您可以尝试在ModelClass::Render()中重新创建缓冲区。我已经用ModelClass::InitialiseBuffer函数体修改了问题区域中的代码。我在ModelClass::Render()中添加了InitialiseBuffer(设备)调用,并将m_vertexBuffer的创建方式更改为dynamic。这没用。我的错误在哪里?对不起,我没有发现是着色器发送了新的位置,它应该从一开始就工作了。我们能看看你的像素着色器吗?当然,我已经把它附加到问题上了。