DirecTX像素仅显示为(0.0F,0.0F)
在一些YouTube教程之后,我正在学习DirectX11和Winapi。我试图在(0.0F,0.0F)的显示屏上显示一些像素,并且可以正常工作,但是如果我更改坐标(例如,为(-0.5F,0.0F)) - 不。当我尝试显示多个像素时,它仅显示(0.0F,0.0F)的像素。
这是渲染方法:
void Graphics::RenderFrame()
{
float bgcolor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
this->deviceContext->ClearRenderTargetView(this->renderTargetView.Get(), bgcolor);
this->deviceContext->IASetInputLayout(this->vertexshader.GetInputLayout());
this->deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
this->deviceContext->VSSetShader(vertexshader.GetShader(), NULL, 0);
this->deviceContext->PSSetShader(pixelshader.GetShader(), NULL, 0);
UINT stride = sizeof(Vertex);
UINT offset = 0;
this->deviceContext->IASetVertexBuffers(0, 1, vertexBuffer.GetAddressOf(), &stride, &offset);
this->deviceContext->Draw(2,0);
this->swapchain->Present(1, NULL);
}
顶点结构:
Vertex v[] =
{
Vertex(0.0f, 0.0f),
Vertex(-0.5f, 0.0f),
};
顶点标头:
struct Vertex
{
Vertex()
{
}
Vertex(float x, float y)
: pos(x, y)
{
}
DirectX::XMFLOAT2 pos;
};
顶点着色器:
float4 main(float2 inPos : POSITION) : SV_POSITION
{
return float4(inPos, 0, 1);
}
像素着色器:
float4 main() : SV_TARGET
{
return float4(1.0f, 1.0f, 1.0f, 1.0f);
}
I'm learning a DirectX11 and WinAPI following some Youtube tutorial. I trying to show some pixel on a display at (0.0f, 0.0f) and it works, but if I change coordinate (for example to (-0.5f, 0.0f)) - it doesn't. And when I try to show more than one pixel it shows me pixel at (0.0f, 0.0f) only.
Here's the render method:
void Graphics::RenderFrame()
{
float bgcolor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
this->deviceContext->ClearRenderTargetView(this->renderTargetView.Get(), bgcolor);
this->deviceContext->IASetInputLayout(this->vertexshader.GetInputLayout());
this->deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
this->deviceContext->VSSetShader(vertexshader.GetShader(), NULL, 0);
this->deviceContext->PSSetShader(pixelshader.GetShader(), NULL, 0);
UINT stride = sizeof(Vertex);
UINT offset = 0;
this->deviceContext->IASetVertexBuffers(0, 1, vertexBuffer.GetAddressOf(), &stride, &offset);
this->deviceContext->Draw(2,0);
this->swapchain->Present(1, NULL);
}
Vertex structure:
Vertex v[] =
{
Vertex(0.0f, 0.0f),
Vertex(-0.5f, 0.0f),
};
Vertex header:
struct Vertex
{
Vertex()
{
}
Vertex(float x, float y)
: pos(x, y)
{
}
DirectX::XMFLOAT2 pos;
};
Vertex shader:
float4 main(float2 inPos : POSITION) : SV_POSITION
{
return float4(inPos, 0, 1);
}
Pixel shader:
float4 main() : SV_TARGET
{
return float4(1.0f, 1.0f, 1.0f, 1.0f);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从测试过程中,我没有从您提供的代码中看到任何问题。我第一次测试数据与您相同,但是由于像素太小,我找不到特定位置,所以我将Pixels Point稍微近一点,我可以清楚地看到它们已成功地绘制了窗口。
我建议您的坐标更加接近,并且最好使用
d3d11_primisity_topology_pointlist
。这是我的测试图片。您可以看到输出的三个像素。以下是我的测试代码,希望它对您有所帮助。
https://gist.github.com/msmshazan/dfd5362004be37ff5e016b6a42be5083
From the process of my test, I didn't see any problem from the code you provided. The first time I tested the data was the same as you, but because the pixels were too small, I couldn't find the specific location, so I put the pixels Point a little closer and I can clearly see that they are successfully drawn in the window.
I suggest your coordinates to be closer, and better to use
D3D11_PRIMITIVE_TOPOLOGY_POINTLIST
. here is my test pic. You can see three pixels of the output.The following is my test code, hope it will help you.
https://gist.github.com/msmshazan/dfd5362004be37ff5e016b6a42be5083