FAQ Database Discussion Community


DirectX11 How to CreateTexture2D from unsigned char * data

c++,graphics,directx,directx-11,texture-mapping
I have a function GetCamImage that returns the image from camera as: unsigned char* p = GetCamImage(...); I need to create ID3D11Texture2D from this data. How can I do it in DirectX 11? Thanks...

Projection Matrix only goes from 0 to 1

c++,opengl,matrix,directx
I am working on my Projection Matrix in c++. If I use a Orthogonal Matrix, the Axis range goes from 0 to my screen size. Now if I use my Perspective Matrix, the Axis range goes from 0 to 1. This is not good if I want to position my...

DirectX libs in x64 program

64bit,directx
I'm trying to compile a program as 64 bits, it works perfectly with a simple console program but if I use my directX program it says me: error LNK1181: cannot open input file 'd3dx9.lib'. When I compile my directX program as 32 bits it works but in x64 it doesn't....

How to use a huge array in HLSL (error X4505)

arrays,directx,shader,hlsl
When I try to compile I get the error: X4505: sum of temp register and indexable temp registers exceeds limit of 4096. However my shader does work in FX Composer. The reason it crashes is probably because I use a very large array since I'm using marching cubes. const static...

Porting Directional Light from OpenGL to DirectX11

opengl,directx,glsl,hlsl
I am porting my GLSL Directional Light Shader from OpenGL to DirectX11. My LightDirection is (1,0,0) (from left to right in the pictures) The Shader in GLSL looks like this: #version 330 core uniform sampler2D DiffuseMap; uniform sampler2D NormalMap; uniform sampler2D PositionMap; uniform sampler2D DepthMap; uniform vec3 LightDirection; uniform vec3...

DirectX 9 not rendering after adding transforms

c++,3d,directx,direct3d,directx-9
so far I got a cube rendered without any transforms (thus it was rendered in an orthographic perspective), and I am working on the previous code to get it into a perspective view, with all the matrices involved. I changed the Flexible Vertex Format so as not to have RHW...

Constant buffer is empty when passed HLSL C++

c++,directx,shader,hlsl
So I moved from this problem: Previous problem to this one :). I made 2 constant buffers in C++ which I'm passing to my HLSL Shader but when I debug and look into the buffers they are just filled with zeros except the last 3 numbers (which are -572662307). I...

Sharpdx - Depthstencil not working when using MRT (Multiple Render Targets)

c#,directx,rendering,directx-11,sharpdx
been trying to change a renderer I wrote from SlimDX to SharpDX and ran into a problem. I want to render to multiple render targets (in this case color and object ID for picking) This is the initialization of the rendertargets (all with same dimension and multisample setting) //Swapchain, Device,...

Invisible geometry in DX11

xna,alignment,directx,directx-11,xna-math-library
After struggling for many hours to understand and compensate for Microsoft's deprecation of D3DX in Windows 8, I've run into a problem that I can't shake off. The first time I started my program, it became immortal because of an access violation. After having restarted my computer and recompiling and...

Shader - Simple SSS lighting issue

opengl,directx,glsl,shader,hlsl
I am trying to create a simple subsurface scattering effect using a shader but I am facing a small issue. Look at those screenshots. The three images represents three lighting states (above surface, really close to surface, subsurface) with various lighting colors (red and blue) and always the same subsurface...

Relationship between AFX_WM_DRAW2D and WM_PAINT in MFC Application

c++,graphics,mfc,directx,direct2d
What is the relationship between the two messages in the subject? When exactly the AFX_WM_DRAW2D is passed to application queue. I am asking because I have encountered the strangest recursive call of AFX_WM_DRAW2D handler. Whenever I am trying to paint something inside the AFX_WM_DRAW2Din compatibe render target the handler is...

Does a float3 in a constant buffer secretly add padding?

c#,directx,padding,hlsl,sharpdx
I have a cbuffer in my shader.fx file, like so: cbuffer lights : register (b1) { float4 Light1Color; float3 Light1Direction; float4 Light2Color; float3 Light2Direction; float4 Light3Color; float3 Light3Direction; } I had some issues filling this cbuffer from my code, it ended up being an array of the following struct: struct...

Detect if GPU supports Pixel Shader 2.0 at runtime (Firemonkey)

delphi,directx,firemonkey,delphi-xe7
This question comes from my previous question here: Delphi XE7 Abstract Error on StyleLookup with Effect (FireMonkey) Basically, I have several styled controls with effects applied. The effects work on most systems so I don't want to take them out of my styles all together for the select few customers...

What does *.hlsl files do, what the relationship between this file and *.fx file?

directx,directx-11
I am reading an example of DirectX project, I saw *.fx and *.hlsl files. I know fx is effect file which is read by DirectX, but what's purpose of hlsl file? Are this files useful?...

Aliased rasterization: why sampling pixel at center?

opengl,graphics,directx,rendering
Both OpenGL and Direct3D use pixel's center as a sample point during rasterization (without antialiasing). For example here is the quote from D3D11 rasterization rules: Any pixel center which falls inside a triangle is drawn I tried to find out what is the reason to use (0.5, 0.5) instead of,...

Geometry shader output filling Z-Buffer with closest value possible? (DirectX)

c++,directx,shader,hlsl
I need lines of a certain thickness in my CAD viewer and found out that I should use a geometry shader to accomplish this. I then went ahead and found demo code of a geometry shader that creates lines at a given thickness. Here: https://github.com/paulhoux/Cinder-Samples/blob/master/GeometryShader/assets/shaders/lines1.geom Discussion about it here: https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader...

Using D3D11CreateDeviceAndSwapChain?

c++,directx
I am currently writing a DirectX 11 game engine in C++ based off a tutorial, but I ran into a problem. Here is where the error is: result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext); result = HRESULT, featureLevel = D3D_FEATURE_LEVEL, swapChainDesc = DXGI_SWAP_CHAIN_DESC,...

OMSetRenderTargets renders only first provided target

c++,directx
I'm trying to render to multiple ID3D11RenderTargetView simultaneously. But it seems that only the first target is being rendered: ID3D11RenderTargetView* targets [ 2 ] = { _backbuffer , _renderToTextureRTV }; _devcon->OMSetRenderTargets( 2, targets, nullptr ); Depending on which parameter I specify first in my targets array, will be rendered. The...

3D plane/map: model versus native code?

opengl,3d,directx,gaming,3d-modelling
I'm curious as to how games are written. For those who have a better understanding of how the latest-title, real-world games are written... Are 3d planes(?)/maps/grounds of a level created in 3D programs then just imported & loaded into the code IDE, or are they ever generated completely via the...

Draw a sphere on a billboard with world normal from a pointlist

3d,directx,shader,hlsl
I am drawing spheres on billboards by passing center world positions via a StructuredBuffer and use the geometry shader to build a billboard facing the camera. The sphere is drawn correctly and I can figure out the UVs. Now I would like to light it but I cannot figure how...

Texture for UnorderedAccessView

c#,directx,sharpdx
I would need to create an UnorderedAccessView for use as output of a compute shader: var target = new Texture2D(device, new Texture2DDescription() { Width = bitmap.PixelWidth, Height = bitmap.PixelHeight, ArraySize = 1, MipLevels = 1, Format = Format.R8G8B8A8_UNorm, SampleDescription = new SampleDescription() { Count = 1, Quality = 0 },...

Drawing a textured quad looks distorted

c++,directx,directx-9
I am following along on the book called Introduction To 3D Game Programming With Directx 9.0 and I've copied and pasted the following example out of the book: struct Vertex { float _x, _y, _z; float _nx, _ny, _nz; float _u, _v; // texture coordinates static const DWORD FVF; };...

Back face culling for linestrips

opengl,directx,shader,linear-algebra
I have circle in 3D space (red on image) with normals (white) This circle is being drawn as linestrip. Problem is: i need to draw only those pixels whose normals directed into camera (angle between normal and camera vector is < 90) using discard in fragment shader code. Like backface...

unity3d, multiple render targets - different behavior in Direct3D/OpenGl

opengl,unity3d,directx,shader,cg
I'm writing shader for unity3d. The shader uses multiple render targets to render post processing effect. However, I've run into interesting issue. When Unity3d runs in direct3d mode, by default all standard shaders write data only into first color buffer (i.e. with index 0). I.e. if I attach 3 color...

Is DirectX 12 development now available to the public?

c++,directx,directx-12
With Windows Technical Preview build 10074, D3D12.dll, d3d12SDKLayers.dll and d3d12warp.dll are included in %WINDIR%\System32. With Visual Studio 2015 RC with Tools for Windows 10 (aka Windows Kits 10 - 10069), d3d12.lib, d3d12.h etc. are included. Although there seems to be no press release from Microsoft about its availability, the inclusion...

Shader's function parameters performance

opengl,directx,glsl,shader,hlsl
I'm trying to understand how passing parameters is implemented in shader languages. I've read several articles and documentation, but still I have some doubts. In particular I'm trying to understand the differences with a C++ function call, with a particular emphasis on performances. There are slightly differences between HSLS,Cg and...

Per Pixel Collision for two LPDIRECT3DTEXTURE9?

c++,directx
I have searched and haven't found anything related to C++ code and DX LPDIRECT3DTEXTURE9, all i can find is per pixel collisions for other engines, i need something native , now i have a bounding box collisions which works as expected, but as you know when the collision happens between...

Broken Picking Coordinates Directx11

math,mfc,directx,directx-11
I have for a fair while now been trying to implement a click-based model insertion into my game editor but have run into numerous problems. The most recent is an offset in the placement of the model. So far I have got this code together: D3DXVECTOR3 vPickRayDir; D3DXVECTOR3 vPickRayOrig; float...

Non coherent Vertex Buffer with X file

c++,directx,vertex-buffer,vertices
I'm trying to understand how to manipulate a mesh from a .X file. I started by testing out with a pyramid (5 vertices). I load the .X with the classic D3DX function D3DXLoadMeshFromX( path.c_str(), D3DXMESH_DYNAMIC, pDevice->GetDeviced3d(), NULL, &pMaterialBuffer, NULL, &m_numMaterials, &m_pMesh); Everything looks fine in the renderer.But I notice that...

HLSL Particle system will not display

c++,directx,directx-11,hlsl,particle-system
I have been trying to add a particle system to my Directx11 graphics demo, and so i have been using the 'Introduction to 3d Game Programming with directx 11' book. Because of this am attempting to use a HLSL StreamOut technique to update the particle system and a separate technique...

Calculating 3D Coordinate

c++,math,directx,directx-11,reverseprojection
I have recently been trying to calculate a 3D point out of a mouse position. So far I have this: const D3DXMATRIX* pmatProj = g_Camera.GetProjMatrix(); POINT ptCursor; GetCursorPos( &ptCursor ); ScreenToClient( DXUTGetHWND(), &ptCursor ); // Compute the vector of the pick ray in screen space D3DXVECTOR3 v; v.x = (...

How To Calculate a 3D Point from 2D Coordinates?

math,3d,directx,directx-11,reverseprojection
I have recently run into a predicament involving DirectX11 and the calculation of a 3D coordinate. I wish to convert a mouse coordinate to this 3D coordinate. I wish to have it act similar to Maya or Unity when inserting a polygon model (default cube, etc.) or a mesh object...

Updating float4 declaration from dx9 to dx11

directx,shader
There's a shader which was given which I'm trying to update to be compatible with the newest Unity 5 (presumably dx11). I don't understand how float4 basic instantiation from dx9 was working. Can someone help me understand the following syntax and then provide an equivalent dx11 syntax? I understand that...

CheckMultisampleQualityLevels(…) says the card does not support MSAA (which is not true for e.g. my GeForce GTX 780)?

c++,directx,directx-11,msaa
I use CheckMultisampleQualityLevels(...) to establish the MSAA support on my hardware. I do it in that order: D3D11CreateDevice(...) gives me device device->CheckMultisampleQualityLevels(...) Pass results to DXGI_SWAP_CHAIN_DESC.SampleDesc CreateSwapChain(...) with given DXGI_SWAP_CHAIN_DESC The problem is, CheckMultisampleQualityLevels(...) always gives me 0 for pNumQualityLevels. And I'm sure that my graphic card supports some MSAA...

Visual debugging for Direct3D/OpenGL/unity3d applications on windows 7

debugging,opengl,unity3d,directx,shader
I need to visually debug scene rendering (step-by-step frame rendering) in unity3d (version 5) on Windows 7 64bit. "Visually debug" means that I need to walk through rendering process step-by-step and see what unity does to framebuffer at each step. Which tools are currently available for that? Few years ago...

Linker error compiling DX10 program in Visual Studio 2015

visual-studio,visual-c++,linker,directx
I am trying to compile old program which works with DirectX 10. Full list of libraries used: #pragma comment(lib, "d3d10.lib") #pragma comment(lib, "d3dx10.lib") #pragma comment(lib, "dxgi.lib") #pragma comment(lib, "dxerr.lib") #pragma comment( lib, "dxguid.lib" ) Linker error: dxerr.lib(dxerrw.obj) : error LNK2019: unresolved external symbol _vsnwprintf referenced in function "long __cdecl StringVPrintfWorkerW(unsigned...

GPU loads are not uniform with 2 graphic cards

video,directx
My PC(in Win7) sets up with 2 video graphic cards which both are GTX750, and each card connects to 2 monitors. In other words, there are 2 cards and 4 monitors on my PC. Now I run a program that is to render video uniformly to 4 windows with DirectX9...

Directional per-face lighting using Geometry Shader?

directx,hlsl,normals,geometry-shader
Because of limitations I have to calculate vertex normals inside my geometry shader. Because of this limitation the normals are per-face instead of interpolated between faces on the vertex, meaning per-pixel directional lighting is just a waste. Because the normals are only known from the Geometry Shader onward, I can't...

directx 11 c++ application in vs 2012 — full screen crashes after running for a while

windows,directx
Win7 Directx 11 with VS 2012 -- When I let my app run in full screen on my development computer, eventually, the program exits full screen back to windowed, all by itself, and pops up a dialog telling me windows resources are running low. The dialog tells me something about...

DirectX - Pixel Shader 3.0 doesn't work

c#,directx,shader
I’ve been working on a 3D project for quite some time now, to display model files from a engine. I wrote it in C# and using the Managed DirectX wrapper (I know it is old and deprecated, but I have my own reasons to use it). I needed to write...

DirectX 11 Minimum Texture Size

directx,directx-11,render-to-texture
I'm working on a volume rendering program using DirectX 11. I render both to a window ( HWND ) and to a texture ( ID3D11Texture2D ). While the rendering for the HWND always looks correct, my ID3D11Texture2D looks corrupt for render sizes smaller than 64x64: I wonder whether there is...

Shader - Performance and functions

opengl,directx,glsl,shader,hlsl
I am creating vertex and fragment shaders and I would like to know if using functions inside my shader, for better readability, could have an impact on performance and optimisation.

How can i find what cause a null exception ? I mean what line or where in the code the exception throw?

c#,.net,winforms,directx,direct3d
I'm running my program and after some time it's working it's throwing this exception: I'm using directx in my program and also direct3d in the top of the form i did: using Microsoft.DirectX.Direct3D; using Microsoft.DirectX; And i'm using in my program with Direct3D.Sprite and Device and Texture PresentParameters and DisplayMode...

Is there a way to convert a quaternion to angles?

c++,matrix,directx,quaternions,directxmath
I have a (world) matrix, and it applies translation, rotation and scale into an 3D object. It is created with the function XMMatrixTransformation (DirectXMath) and the parameter RotationQuaternion is made by a call to XMQuaternionRotationRollPitchYaw. Then it is stored in a file along with other data. Then I need to...

Quaternion based camera

opengl,graphics,3d,directx,quaternions
I try to implement an FPS camera based on quaternion math. I store a rotation quaternion variable called _quat and multiply it by another quaternion when needed. Here's some code: void Camera::SetOrientation(float rightAngle, float upAngle)//in degrees { glm::quat q = glm::angleAxis(glm::radians(-upAngle), glm::vec3(1,0,0)); q*= glm::angleAxis(glm::radians(rightAngle), glm::vec3(0,1,0)); _quat = q; } void...

how can i start directx game development using c++ [closed]

c++,directx
i know about fundamental programming concepts, OOP concepts, Data structure concepts of c++ but how can i start game development please suggest me tutorials or book which is easy to understand because from one week i'm searching about c++ directx development

DirectX moving my GUIBox

c++,math,directx,directx-9
I'm creating a overlay for a friend of mine, I wanted to implement so I can move my box dynamically when I'm holding left mouse button. This is my current method: if (mouse.isClicked() && (cursor.x >= mainGUIBox.x) && (cursor.x < (mainGUIBox.x+mainGUIBox.w)) && (cursor.y >= mainGUIBox.y) && (cursor.y < (mainGUIBox.y+40))) {...

Perspective projection seems wrong, closer parts of a model appear smaller and vice versa

directx,directx-11,perspectivecamera,projection-matrix,assimp
I'm trying out D3D11 and struggling to render a model correctly. Here's my problem; while my world and view transformations seem right, my perspective transformation seems to be wrong. When I first rendered a model, something felt wrong, so I tried rotating the model to see what it was. Then...

Meaning of WinMain function call parameters?

c++,directx
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow) In this line, are these statements about the call parameters correct? HINSTANCE is a class and hInstance and hPrevInstance are objects, PSTR is a class and pScmdline is an object and int is a class and iCmdshow is an...

RAII for resources that can be invalidated

c++,resources,directx,raii
I'm a hobbyist C++ and DirectX programmer, so most of the knowledge I have is from old game development books in which the code designs are just to get something up and running as a demonstration, leaving me with a lot of design considerations for even the simplest of programs....

How to read in FBX 2014 indices properly for DirectX?

c++,directx,mesh,indices,fbx
I've been having this very annoying problem for the past weekend. I have to be able to to read in a triangulated 2014 FBX file that contains a mesh exported from Maya and read in it's vertices and indices to be passed to the renderer (DirectX) for the DrawIndexed call....

D3D11 Post Shader Results in Dark Image

c++,directx,direct3d,hlsl,direct3d11
I'm trying to implement post shaders (pixel shaders) as a test. I have a texture to which all stuff is rendered, and the post shader simply copies this texture to the back buffer. If this texture is larger than the back buffer, the post shading process results in dimming: However,...

DirectWrite align text center

c++,text,directx,direct2d,directwrite
I am trying to align center the text I have to draw. I use ID2D1RenderTarget::DrawTextLayout method. The problemn is that if I set the text horizontal alignment to DWRITE_TEXT_ALIGNMENT_LEADING (the default value) the text is drawn proberly, but if I change this value to DWRITE_TEXT_ALIGNMENT_CENTER the text is shifted right....

Why can't I find the DirectX template?

c++,visual-c++,visual-studio-2013,directx
I'm currently using Visual Studio 2013 Express for Windows desktop, but I can't really find the DirectX template, FILE -> New project -> Visual C++ , but there's neither a DirectX template nor a Windows app folder-sector. I've searched this in Google but no one seem to have posted about...

Multiple render targets given the same Direct2D factory

c++,canvas,directx,rendering,direct2d
I have to draw a lot of shapes by using Direct2D. I use a factory to create a render target I use to draw. Above these shapes I need to add others shapes without changing the previous (freehand drawing), but if I use the same render target I have to...

D3D11 D3DX11CreateEffectFromMemory returns E_NOITERFACE

c++,directx
I'm reading the book Introduction to DirectX 11 Programming by Frank Luna and I'm having a problem with Effects11. void BoxApp::BuildFX() { DWORD shaderFlags = 0; #if defined( DEBUG ) || defined( _DEBUG ) shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compiledShader = 0; ID3D10Blob* compilationMsgs = 0; HRESULT...

In D3D9, how to find the normal vector of a specific triangle in a mesh?

directx,mesh,normals
I load a mesh and use D3DXIntersect function to find out which triangle of that mesh I'm about to hit, next I need to know the normal vector of that triangle so I can align myself accordingly. D3DXIntersect lets me know the distance, the face index of the triangle and...

Capture screen using DirectX

c++,winapi,directx
I know how to use GDI to capture screen, however it is very slow (it barely captures 10 fps) I have read that DirectX offers the best speed. But before I start learning DirectX I wanted to test a sample to see if it is really that fast. I have...

performance on mantle, dx and ogl

opengl,graphics,3d,directx,mantle
So recently with all the commotion on the new API for 3d graphics which supposedly accelerate graphics by a huge amount I am wondering why this hasn't been done before. What is so different between the old way and the new way? I would like to know how it is...

DirectX 9 vertex colors ingored when lighting is enabled?

c++,directx,directx-9,lighting
Well, the question says it. When I have light disabled (pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);) I get the colors as expected, when I set it to true, I get pure black, even if I set the ambient light, but that's fixed when also setting a material. But the vertex colors are then ignored...

how to hide struct member in a dll or library

c++,c,dll,directx
i am creating a library for game development, it uses directx 2d, however i want that some variables (ID2D1Factory, ID2D1HwndRenderTarget and others) be invisible to the end user. for example, the SDL library even using the directdraw (i guess), the directdraw classes are invisible for the end user of the...

Direct3D multiple vertex buffers, non interleaved elements

c++,directx,direct3d,vertex,vertex-buffer
I'm trying to create 2 vertex buffers, one that only stores positions and another that only stores colors. This is just an exercise from Frank Luna's book to become familiar with vertex description, layouts and buffer options. The problem is that I feel like I have made all the relevant...

Array^ in Win32

c++,directx,windows-8,winapi
I have a DirectX 11.1 program which is written for Metro style and I want to convert it to Win32 application. I have used a lot of WinRT libraries and most of them are founded for HWND. but I still have an issue: on Metro Style app, for using HLSL...

Not finding DirectX namespace anymore [closed]

c++,windows,directx
Visual Studio Professional 2013 Windows 7 x32, x64 processor I am using DirectX 11 and seem to be having a weird problem. I have always been able to access the DirectX namespace in my application. This is no longer the case. I can make a simple class say // A.h...