我对C/C++有一些了解,但只使用控制台.我想开始编程一些图形界面,但我没有最小的想法从哪里开始.
我听说过GUI应用程序和DirectX应用程序.我想知道哪个是开始编程的最佳选择?
哪些库也可以使用,如果可能的话还有一些教程.
我正在尝试将文本渲染到屏幕上,但仍然会得到垃圾符号,我无法弄清楚我的方法有什么不同.
这段代码可以在我的主程序中使用:
char vectorText[80];
sprintf(vectorText, "vector%i = [%f, %f, %f]", 1, vector[0]->x, vector[0]->y, vector[0]->z);
char* newText = vectorText;
Text* finalText = NULL;
finalText = new Text(22, 0, 400, false, newText, 0.0f, 0.0f, 1024.0f, 200.0f);
scene.AddText(finalText);
Run Code Online (Sandbox Code Playgroud)
但是,只要我将它放在一个函数中,它就会开始吐出垃圾.我知道它是char vectorText []因为当我绕过它然后我得到文本.
char vectorText[80] = "This prints garbage";
//sprintf(vectorText, "vector%i = [%f, %f, %f]", 1, vector[0]->x, vector[0]->y, vector[0]->z);
//char* newText = vectorText;
Text* finalText = NULL;
finalText = new Text(22, 0, 400, false, vectorText, 0.0f, 0.0f, 1024.0f, 200.0f);
scene.AddText(finalText);
Run Code Online (Sandbox Code Playgroud)
底部有效,但很明显它不会给我我需要的东西.
//char vectorText[80];
//sprintf(vectorText, "vector%i …Run Code Online (Sandbox Code Playgroud) 我用这个代码:
MainLoop() {
for (int i = 0; i < length; i++) {
XMVector3Rotate(rays[i], orientation);
}
}
Run Code Online (Sandbox Code Playgroud)
我有fps 1900000,但当我用这个:
MainLoop() {
for (int i = 0; i < length; i++) {
calculatedRays[i] = XMVector3Rotate(rays[i], orientation);
}
}
Run Code Online (Sandbox Code Playgroud)
我有fps = 200.为什么?
我正在使用DirectX在visual studio中工作,今天我遇到了一些奇怪的编译器错误(对我来说没有任何意义)......
这些是我得到的错误:
错误C2143:语法错误:缺少';' 在'.'之前 错误C2059:语法错误:')'
我已经仔细检查了我的代码并且没有发现任何错别字/错误(我可能错了......)
我希望有人可以告诉我错误通常意味着什么以及在哪里看...
我会在下面放一些代码,指出发生错误的行(如果你想检查的话)
额外信息:m_ImTexture2D是一个成员结构.Vertex.PosTex是结构中的结构
GameManager.cpp:
(231): error C2143: syntax error : missing ';' before '.'
(231): error C2143: syntax error : missing ';' before '.'
(232): error C2143: syntax error : missing ';' before '{'
(233): error C2143: syntax error : missing ';' before '}'
(233): error C2143: syntax error : missing ';' before ','
(234): error C2143: syntax error : missing ';' before '{'
(234): error C2143: syntax error : missing ';' before …Run Code Online (Sandbox Code Playgroud) c++ compiler-construction directx compiler-errors visual-studio-2010
我正在使用DirectX在C++中制作游戏.我有一个基本的AI绘制.我希望AI在一个正方形中移动,例如:
这是我到目前为止所拥有的; 这使得AI在Z轴上向上移动25,然后在Z轴上向下移动25次.
if (ghost_moves_forward == true)
{
ghost_Z -= ghost_movement;
}
else if (ghost_moves_forward == false)
{
ghost_Z += ghost_movement;
}
if (ghost_Z >= 25)
{
ghost_moves_forward = true;
}
if (ghost_Z <= -25)
{
ghost_moves_forward = false;
}
Run Code Online (Sandbox Code Playgroud)
先感谢您.
编辑:
float ghost_X = 0; //make the AI move along the x axis
float ghost_Z = 0; // makes the AI move along the Z axis
int ghost_movement = 1; // speed the AI moves …Run Code Online (Sandbox Code Playgroud) 当我运行我的3D场景时,它只渲染第一帧然后在它和黑屏之间翻转,导致大量闪烁.我认为这是我的交换链没有正确设置,但我真的不知道.
这是我的代码来设置它.它几乎是从微软的例子中复制而来的.
DXGI_SWAP_CHAIN_DESC1 sd = {0};
sd.Width = 0;
sd.Height = 0;
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.Stereo = false;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 2;
sd.Scaling = DXGI_SCALING_NONE;
sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
sd.Flags = 0;
CoreWindow^ window = reinterpret_cast<CoreWindow^>(mSystem->GetIWindow());
hr = pIDXGIFactory->CreateSwapChainForCoreWindow(mD3DDevice, reinterpret_cast<IUnknown*>(window), &sd, NULL, &mSwapChain);
EA_ASSERT(SUCCEEDED( hr ));
Run Code Online (Sandbox Code Playgroud)
而目前的代码:
DXGI_PRESENT_PARAMETERS presentParameters = {0};
HRESULT hr = mSwapChain->Present1(0, 0, &presentParameters);
Run Code Online (Sandbox Code Playgroud)
在我看来相当直接,所以我不明白为什么它不起作用.
场景一直在运行.更新功能每帧都运行一次.
另外,如果我在PIX中检查渲染,一切都很好.我得到了我期望渲染的东西.它只是没有出现在屏幕上.
有任何想法吗?谢谢!
我想在3d世界中实现盒子选择.基本上,单击,按住鼠标,然后取消鼠标,获取一个框,然后选择框.首先,我想弄清楚如何获得3d中点击的坐标.
我有raypicking,那是没有得到正确的坐标(得到起源和方向).无论屏幕的X/Y是什么(尽管方向不同),它都会保持返回相同的原点.
我也尝试过:
D3DXVECTOR3 ori = D3DXVECTOR3(sx, sy, 0.0f);
D3DXVECTOR3 out;
D3DXVec3Unproject(&out, &ori, &viewPort, &projectionMat, &viewMat, &worldMat);
Run Code Online (Sandbox Code Playgroud)
它得到了同样的东西,无论坐标是什么,坐标都非常接近(并且是错误的).这几乎就像是回归眼睛,而不是真实的世界坐标.
如何使用directx 9c将2D屏幕坐标转换为3d?
Visual Studios忽略了我想要播放的文件.使用此代码,它返回false,因为它不加载文件.
result = LoadWaveFile("../Engine/data/sound01.wav", &m_secondaryBuffer1);
if (!result)
{
return false;
}
Run Code Online (Sandbox Code Playgroud) 编写DIY内存管理器最令人满意的部分是构造它,这样你就可以忘记[删除](例如,通过将所有内容捆绑到单独分配/解除分配的缓冲区中).
DirectX处理对象创建的方式意味着你不能简单地将void内存转换为你想要制作的类型(可以吗?)而你必须依赖COM(+记住每个析构函数中的[Release]本地内存).有没有办法颠覆这个并说服DirectX使用我的指针?
代替:
ID3D12Thing* thng = DirectX::CreateThing();
...
thng->Release();
thng = nullptr;
Run Code Online (Sandbox Code Playgroud)
我想要:
ID3D12Thing* thng = DirectX::CreateThingAt(Allocator->AlignedAlloc(sizeof(ID3D12Thing));
...
[memory emptied during shutdown]
Run Code Online (Sandbox Code Playgroud) directx ×10
c++ ×8
3d ×1
c ×1
com ×1
directsound ×1
directx-11 ×1
graphics ×1
performance ×1
raytracing ×1
winapi ×1
windows ×1
windows-8 ×1