【发布时间】:2020-06-24 06:26:44
【问题描述】:
我目前正在尝试在 Visual Studio 2017 中使用 C++ 学习 DirectX 11,但遇到了问题。
#include <Windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3d12.h>
#include <d3dcompiler.h>
// include D3D Librararies
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3d12.lib")
#pragma comment (lib, "D3DCompiler.lib")
// Definitions
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
// Global Declarations
IDXGISwapChain *swapchain; // Pointer to Swap Chain Buffer
ID3D11DeviceContext *devcon; // Pointer to managing Device for GPU
ID3D11Device *dev; // Pointer to GPU
ID3D11RenderTargetView *backBuffer; // A pointer to an object that holds info about the render target
ID3D11VertexShader *pVS; // The Vertex shader
ID3D11PixelShader *pPS; // The Pixel Shader
struct VERTEX {
FLOAT X, Y, Z; // Position
D3DCOLORVALUE Color; // Color
};
// float color2[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
VERTEX OurVertex = { 0.0f, 0.5f, 0.0f, D3DCOLORVALUE(1.0f, 0.0f, 0.0f, 1.0f)}; // No suitable constructor exists to convert from "float" to "_D3DCOLORVALUE"
OurVertex 内部存在错误,C++ 似乎无法将 D3DCOLORVALUE() 中的浮点数转换为 D3DCOLORVALUE 项。我尝试查看其他解决方案,但找不到任何解决方案。
有解决办法吗?
【问题讨论】:
-
VERTEX OurVertex = {0.0f, 0.5f, 0.0f, D3DCOLORVALUE{1.0f, 0.0f, 0.0f, 1.0f}};呢? -
谢谢你,成功了。因此,大括号用于 D3DCOLORVALUE。我会记住这一点。
-
检查文档,
_D3DCOLORVALUE是struct,所以你可能需要像D3DCOLORVALUE{1.0f, 0.0f, 0.0f, 1.0f}那样做
标签: c++ visual-studio-2017 directx directx-11 directx-12