• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Endemoniada

      Hi guys, when I do picking followed by ray-plane intersection the results are all wrong. I am pretty sure my ray-plane intersection is correct so I'll just show the picking part. Please take a look:
       
      // get projection_matrix DirectX::XMFLOAT4X4 mat; DirectX::XMStoreFloat4x4(&mat, projection_matrix); float2 v; v.x = (((2.0f * (float)mouse_x) / (float)screen_width) - 1.0f) / mat._11; v.y = -(((2.0f * (float)mouse_y) / (float)screen_height) - 1.0f) / mat._22; // get inverse of view_matrix DirectX::XMMATRIX inv_view = DirectX::XMMatrixInverse(nullptr, view_matrix); DirectX::XMStoreFloat4x4(&mat, inv_view); // create ray origin (camera position) float3 ray_origin; ray_origin.x = mat._41; ray_origin.y = mat._42; ray_origin.z = mat._43; // create ray direction float3 ray_dir; ray_dir.x = v.x * mat._11 + v.y * mat._21 + mat._31; ray_dir.y = v.x * mat._12 + v.y * mat._22 + mat._32; ray_dir.z = v.x * mat._13 + v.y * mat._23 + mat._33;  
      That should give me a ray origin and direction in world space but when I do the ray-plane intersection the results are all wrong.
      If I click on the bottom half of the screen ray_dir.z becomes negative (more so as I click lower). I don't understand how that can be, shouldn't it always be pointing down the z-axis ?
      I had this working in the past but I can't find my old code
      Please help. Thank you.
    • By turanszkij
      Hi,
      I finally managed to get the DX11 emulating Vulkan device working but everything is flipped vertically now because Vulkan has a different clipping space. What are the best practices out there to keep these implementation consistent? I tried using a vertically flipped viewport, and while it works on Nvidia 1050, the Vulkan debug layer is throwing error messages that this is not supported in the spec so it might not work on others. There is also the possibility to flip the clip scpace position Y coordinate before writing out with vertex shader, but that requires changing and recompiling every shader. I could also bake it into the camera projection matrices, though I want to avoid that because then I need to track down for the whole engine where I upload matrices... Any chance of an easy extension or something? If not, I will probably go with changing the vertex shaders.
    • By evelyn4you
      Hello,
      in my game engine i want to implement my own bone weight painting tool, so to say a virtual brush painting tool for a mesh.
      I have already implemented my own "dual quaternion skinning" animation system with "morphs" (=blend shapes)  and "bone driven"  "corrective morphs" (= morph is dependent from a bending or twisting bone)
      But now i have no idea which is the best method to implement a brush painting system.
      Just some proposals
      a.  i would build a kind of additional "vertecie structure", that can help me to find the surrounding (neighbours) vertecie indexes from a given "central vertecie" index
      b.  the structure should also give information about the distance from the neighbour vertecsies to the given "central vertecie" index
      c.  calculate the strength of the adding color to the "central vertecie" an the neighbour vertecies by a formula with linear or quadratic distance fall off
      d.  the central vertecie would be detected as that vertecie that is hit by a orthogonal projection from my cursor (=brush) in world space an the mesh
            but my problem is that there could be several  vertecies that can be hit simultaniously. e.g. i want to paint the inward side of the left leg. the right leg will also be hit.
      I think the given problem is quite typical an there are standard approaches that i dont know.
      Any help or tutorial are welcome
      P.S. I am working with SharpDX, DirectX11
        
    • By Luca Davidian
      Hi, I'm implementing a simple 3D engine based on DirectX11. I'm trying to render a skybox with a cubemap on it and to do so I'm using DDS Texture Loader from DirectXTex library. I use texassemble to generate the cubemap (texture array of 6 textures) into a DDS file that I load at runtime. I generated a cube "dome" and sample the texture using the position vector of the vertex as the sample coordinates (so far so good), but I always get the same face of the cubemap mapped on the sky. As I look around I always get the same face (and it wobbles a bit if I move the camera). My code:   
      //Texture.cpp:         Texture::Texture(const wchar_t *textureFilePath, const std::string &textureType) : mType(textureType)         {             //CreateDDSTextureFromFile(Game::GetInstance()->GetDevice(), Game::GetInstance()->GetDeviceContext(), textureFilePath, &mResource, &mShaderResourceView);             CreateDDSTextureFromFileEx(Game::GetInstance()->GetDevice(), Game::GetInstance()->GetDeviceContext(), textureFilePath, 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, D3D11_RESOURCE_MISC_TEXTURECUBE, false, &mResource, &mShaderResourceView);         }     // SkyBox.cpp:          void SkyBox::Draw()     {         // set cube map         ID3D11ShaderResourceView *resource = mTexture.GetResource();         Game::GetInstance()->GetDeviceContext()->PSSetShaderResources(0, 1, &resource);              // set primitive topology         Game::GetInstance()->GetDeviceContext()->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);              mMesh.Bind();         mMesh.Draw();     }     // Vertex Shader:     cbuffer Transform : register(b0)     {         float4x4 viewProjectionMatrix;     };          float4 main(inout float3 pos : POSITION) : SV_POSITION     {         return mul(float4(pos, 1.0f), viewProjectionMatrix);     }     // Pixel Shader:     SamplerState cubeSampler;     TextureCube cubeMap;          float4 main(in float3 pos : POSITION) : SV_TARGET     {         float4 color = cubeMap.Sample(cubeSampler, pos.xyz);         return color;     } I tried both functions grom DDS loader but I keep getting the same result. All results I found on the web are about the old SDK toolkits, but I'm using the new DirectXTex lib.
    • By B. /
      Hi Guys,
      i want to draw shadows of a direction light but the shadows always disappear, if i translate my mesh (cube) in the world to far of the bounds of my orthographic projection matrix.
      That my code (Based of an XNA sample i recode for my project):
      // Matrix with that will rotate in points the direction of the light Matrix lightRotation = Matrix.LookAtLH(Vector3.Zero, lightDir, Vector3.Up); BoundingFrustum cameraFrustum = new BoundingFrustum(Matrix.Identity); // Get the corners of the frustum Vector3[] frustumCorners = cameraFrustum.GetCorners(); // Transform the positions of the corners into the direction of the light for (int i = 0; i < frustumCorners.Length; i++) frustumCorners[i] = Vector4F.ToVector3(Vector3.Transform(frustumCorners[i], lightRotation)); // Find the smallest box around the points BoundingBox lightBox = BoundingBox.FromPoints(frustumCorners); Vector3 boxSize = lightBox.Maximum - lightBox.Minimum; Vector3 halfBoxSize = boxSize * 0.5f; // The position of the light should be in the center of the back pannel of the box. Vector3 lightPosition = lightBox.Minimum + halfBoxSize; lightPosition.Z = lightBox.Minimum.Z; // We need the position back in world coordinates so we transform // the light position by the inverse of the lights rotation lightPosition = Vector4F.ToVector3(Vector3.Transform(lightPosition, Matrix.Invert(lightRotation))); // Create the view matrix for the light this.view = Matrix.LookAtLH(lightPosition, lightPosition + lightDir, Vector3.Up); // Create the projection matrix for the light // The projection is orthographic since we are using a directional light int amount = 25; this.projection = Matrix.OrthoOffCenterLH(boxSize.X - amount, boxSize.X + amount, boxSize.Y + amount, boxSize.Y - amount, -boxSize.Z - amount, boxSize.Z + amount); I believe the bug is by cameraFrustum to set a Matrix Idetity. I also tried with a Translation Matrix of my Camera Position and also the View Matrix of my Camera, but without success
      Can anyone tell me, how to draw shadows of my direction light always where my camera is current in my scene?
      Greets
      Benjamin
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 SlimDX Directx11 Text Rendering Problem

This topic is 1958 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have been following the tutorials on braynzarsoft.net, but using SlimDX. I am currently stuck on tutorial #14 which is about rendering text on the screen. But you have to go through all this bs of creating a D3D10 device, and using D2D and DirectWrite, just to get text on the screen. Anyway, I have the code in and the compiler is happy with it, except for one detail. The tutorial says that you MUST set the DriverType for the D3D11 device, to DriverType.Unknown. But anytime I set it to that, it is an automatic fail with an invalid arg error from the CreateDeviceWithSwapChain() method. So how is it that I am supposed to set it to DriverType.Unknown if it simply hates that value for that parameter?

If I leave it set to DriverType.Hardware, the program will run and draw a triangle on the screen like it is supposed to, but the text is nowhere to be seen. I have no idea what the problem is.

The tutorial I am following is here:
http://braynzarsoft....php?p=D3D11FONT


Here is the code of my class that handles the text rendering. I made it a separate class because it would clutter up the main gamewindow class since you have to do this rediculous pile of crap just to get text on the screen.

public class TextRenderer_D2D_DW : IDisposable
{
#region Constants
#endregion

#region Member Variables
SlimDX.Windows.RenderForm m_ParentWindow = null;
SlimDX.Direct3D10_1.Device1 m_d3d101_Device = null;
SlimDX.Direct3D11.Device m_d3d11_Device = null;
KeyedMutex m_keyedMutex_d3d11 = null;
KeyedMutex m_keyedMutex_d3d10 = null;
SlimDX.Direct2D.RenderTarget m_d2dRenderTarget = null; // A RenderTarget for D2D to draw on.
SlimDX.Direct2D.SolidColorBrush m_d2dBrush = null; // The Brush D2D will draw with.
//SlimDX.Direct3D11.Texture2D m_backBuffer_d3d11 = null;
SlimDX.Direct3D11.Texture2D m_sharedTexture_d3d11 = null; // The shared texture that we will have D2D/DW render onto, and then have D3D overlay this texture onto our scene.
SlimDX.Direct3D11.Buffer m_d2dVertexBuffer = null; // The vertex buffer for the square to render the text texture onto.
SlimDX.Direct3D11.Buffer m_d2dIndexBuffer = null; // The index buffer for the square to render the text texture onto.
SlimDX.Direct3D11.ShaderResourceView m_textTexture = null; // The ShaderResourceView for the text texture.
BlendState m_BlendState_Transparency = null; // Our transparency blending state.
RasterizerState m_RasterizerState_CWcullmode = null; // for clockwise culling
SamplerState m_TextSamplerState = null; // our SamplerState
SlimDX.DirectWrite.Factory m_DWrite_Factory = null; // A DirectWrite Factory.
SlimDX.DirectWrite.TextFormat m_DWrite_TextFormat = null; // Holds our text format settings, such as font, size, etc.

// These hold references to the passed int ConstantBuffers.
ConstantBuffer_ChangesOnResize m_cbOnResize = null;
ConstantBuffer_ChangesPerFrame m_cbPerFrame = null;
ConstantBuffer_ChangesPerObject m_cbPerObject = null;

int m_nVertexBufferStride = 0; // Stores the stride (number of bytes per vertex) in our vertex buffer.
// Shaders
VertexShader m_vShader = null;
ShaderSignature m_vShaderSignature = null;
PixelShader m_pShader = null;

bool m_bIsInitialized = false; // Indicates whether this object is initialized or not.
bool m_bDisposed = false; // Indicates whether this object has been disposed or not.
#endregion

#region Constructors
public TextRenderer_D2D_DW(SlimDX.Windows.RenderForm form, SlimDX.Direct3D11.Device d3d11_device, ConstantBuffer_ChangesOnResize cbOnResize, ConstantBuffer_ChangesPerFrame cbPerFrame, ConstantBuffer_ChangesPerObject cbPerObject)
{
if (form == null)
throw new Exception("The passed in form parameter is null!");
this.m_ParentWindow = form;
if (d3d11_device == null)
throw new Exception("The passed in Direct3D 11 device is null!");
this.m_d3d11_Device = d3d11_device;
if (cbOnResize == null)
throw new Exception("The first passed in constant buffer object is null!");
this.m_cbOnResize = cbOnResize;
if (cbPerFrame == null)
throw new Exception("The second passed in constant buffer object is null!");
this.m_cbPerFrame = cbPerFrame;
if (cbPerObject == null)
throw new Exception("The third passed in constant buffer object is null!");
this.m_cbPerObject = cbPerObject;
InitD2D_D3D101_DWrite();
InitD2DScreenTexture();
InitShaders();
// Set up our Transparency blending state.
// ----------------------------------------------------------------------------------------

// Create our RenderTargetBlendDescription.
RenderTargetBlendDescription rtbd = new RenderTargetBlendDescription();
rtbd.BlendEnable = true;
rtbd.SourceBlend = BlendOption.SourceColor;
rtbd.DestinationBlend = BlendOption.InverseSourceAlpha;
rtbd.BlendOperation = BlendOperation.Add;
rtbd.SourceBlendAlpha = BlendOption.One;
rtbd.DestinationBlendAlpha = BlendOption.Zero;
rtbd.BlendOperationAlpha = BlendOperation.Add;
rtbd.RenderTargetWriteMask = ColorWriteMaskFlags.All;

// Create our BlendStateDescription.
BlendStateDescription bsd = new BlendStateDescription();
bsd.AlphaToCoverageEnable = false;
bsd.RenderTargets[0] = rtbd;
// Create our BlendState.
m_BlendState_Transparency = BlendState.FromDescription(m_d3d11_Device, bsd);

// Set up a RasterizerState for Clockwise culling mode.
// ----------------------------------------------------------------------------------------
// Create our RasterizerStateDescription
RasterizerStateDescription rsd = new RasterizerStateDescription();
rsd.FillMode = SlimDX.Direct3D11.FillMode.Solid;
rsd.CullMode = CullMode.Back;
// Create the Clockwise cull mode state.
rsd.IsFrontCounterclockwise = false;
m_RasterizerState_CWcullmode = RasterizerState.FromDescription(m_d3d11_Device, rsd);


// Set up a SamplerState that we will use for Rendering our text.
// ----------------------------------------------------------------------------------------
// Create a SamplerDescription
SamplerDescription sd = new SamplerDescription();
sd.Filter = Filter.MinMagMipLinear;
sd.AddressU = TextureAddressMode.Wrap;
sd.AddressV = TextureAddressMode.Wrap;
sd.AddressW = TextureAddressMode.Wrap;
sd.ComparisonFunction = Comparison.Never;
sd.MinimumLod = 0;
sd.MaximumLod = float.MaxValue;
// Create our SamplerState
m_TextSamplerState = SamplerState.FromDescription(m_d3d11_Device, sd);

m_bIsInitialized = true;
}
#endregion

#region Non-Public Methods
// This section is for methods that are declared as private, protected, protected internal, or internal.

private bool InitD2D_D3D101_DWrite()
{
// Create our Direct3D 10.1 Device
m_d3d101_Device = new SlimDX.Direct3D10_1.Device1(m_d3d11_Device.Factory.GetAdapter(0),
SlimDX.Direct3D10.DriverType.Hardware,
SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport | SlimDX.Direct3D10.DeviceCreationFlags.Debug,
SlimDX.Direct3D10_1.FeatureLevel.Level_10_1);

// Create the Shared Texture that Direct3D 10.1 will render on
SlimDX.Direct3D11.Texture2DDescription sharedTexDesc = new Texture2DDescription();
sharedTexDesc.Width = m_ParentWindow.ClientSize.Width;
sharedTexDesc.Height = m_ParentWindow.ClientSize.Height;
sharedTexDesc.Format = Format.B8G8R8A8_UNorm;
sharedTexDesc.MipLevels = 1;
sharedTexDesc.ArraySize = 1;
sharedTexDesc.SampleDescription = new SampleDescription(1, 0);
sharedTexDesc.Usage = ResourceUsage.Default;
sharedTexDesc.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget;
sharedTexDesc.OptionFlags = ResourceOptionFlags.KeyedMutex;
m_sharedTexture_d3d11 = new Texture2D(m_d3d11_Device, sharedTexDesc);

// Get the keyed mutex for the shared texture (for Direct3D 11)
m_keyedMutex_d3d11 = new KeyedMutex(m_sharedTexture_d3d11);
m_keyedMutex_d3d11.Acquire(0, 5);
// Get the resource for the shared texture.
SlimDX.DXGI.Resource r = new SlimDX.DXGI.Resource(m_sharedTexture_d3d11);
// Open the surface for the shared texture in Direct3D 10.1.
SlimDX.Direct3D10.Texture2D sharedTexture10;
sharedTexture10 = m_d3d101_Device.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(r.SharedHandle);
m_keyedMutex_d3d10 = new KeyedMutex(sharedTexture10);

// Create the Direct2D factory
SlimDX.Direct2D.Factory d2dFactory = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.SingleThreaded);
SlimDX.Direct2D.RenderTargetProperties d2d_rtp = new RenderTargetProperties();
d2d_rtp.Type = RenderTargetType.Hardware;
d2d_rtp.PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied);
m_d2dRenderTarget = RenderTarget.FromDXGI(d2dFactory, sharedTexture10.AsSurface(), d2d_rtp);
sharedTexture10.Dispose();
d2dFactory.Dispose();
r.Dispose();
// Create a solid color brush to draw something with.
m_d2dBrush = new SolidColorBrush(m_d2dRenderTarget, new Color4(1.0f, 1.0f, 0.0f, 1.0f));


// DirectWrite
m_DWrite_Factory = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
m_DWrite_TextFormat = m_DWrite_Factory.CreateTextFormat("Arial",
FontWeight.Normal,
FontStyle.Normal,
FontStretch.Normal,
24.0f,
"en-us");
m_DWrite_TextFormat.TextAlignment = TextAlignment.Leading;
m_DWrite_TextFormat.ParagraphAlignment = ParagraphAlignment.Near;
// This is to prevent an annoying warning that pops up if you haven't set the primitive topology.
m_d3d101_Device.InputAssembler.SetPrimitiveTopology(SlimDX.Direct3D10.PrimitiveTopology.PointList);

return true;
}

void InitD2DScreenTexture()
{
VertexList<Vertex3D_T> vList = new VertexList<Vertex3D_T>(m_d3d11_Device);
vList.AddVertex(new Vertex3D_T(-1.0f, -1.0f, 1.0f, 0.0f, 1.0f));
vList.AddVertex(new Vertex3D_T(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f));
vList.AddVertex(new Vertex3D_T( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f));
vList.AddVertex(new Vertex3D_T( 1.0f, -1.0f, 1.0f, 1.0f, 1.0f));
// Create the vertex buffer now that we've defined all the vertex data.
vList.CreateVertexBuffer(out m_d2dVertexBuffer);
m_nVertexBufferStride = vList.VertexSize;

IndexList<UInt16> iList = new IndexList<UInt16>(m_d3d11_Device);
// Front Face
iList.AddIndices(0, 1, 2,
0, 2, 3);

// Create the index buffer now that we've defined all the index data.
iList.CreateIndexBuffer(out m_d2dIndexBuffer);
// Create a ShaderResourceView from the texture D2D will render to,
// So we can use it to texture a square which overlays our scene.
m_textTexture = new ShaderResourceView(m_d3d11_Device, m_sharedTexture_d3d11);
}

void InitShaders()
{
string shaderCode = "";

// The file TextRenderer_D2D_DW is an embedded resource. So we need to access it and put it in a string variable first.
using (Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("Megafont_Framework.Graphics._3D.DX11.TextRenderer_D2D_DW.fx"))
{
using (StreamReader reader = new StreamReader(stream))
{
shaderCode = reader.ReadToEnd();
}
}


// load and compile the vertex shader
string vsCompileError = "TextRenderer_D2D_DW - Vertex Shader Compile Error!!!";
using (var bytecode = ShaderBytecode.Compile(shaderCode, "Text_VS", "vs_4_0", ShaderFlags.Debug, EffectFlags.None, null, null, out vsCompileError))
{
m_vShaderSignature = ShaderSignature.GetInputSignature(bytecode);
m_vShader = new VertexShader(m_d3d11_Device, bytecode);
}

// load and compile the pixel shader
string psCompileError = "TextRenderer_D2D_DW - Pixel Shader Compile Error!!!";
using (var bytecode = ShaderBytecode.Compile(shaderCode, "Text_PS", "ps_4_0", ShaderFlags.Debug, EffectFlags.None, null, null, out psCompileError))
{
m_pShader = new PixelShader(m_d3d11_Device, bytecode);
}
}

#endregion

#region Public Methods
public void RenderString(string text)
{
if (!m_bIsInitialized)
return;

BlendState blendState = null;
RasterizerState rasterizerState = null;
SamplerState samplerState = null;
VertexShader vertexShader = null;
PixelShader pixelShader = null;

// Save the current states so we can reset them when we're done with them.
blendState = m_d3d11_Device.ImmediateContext.OutputMerger.BlendState;
rasterizerState = m_d3d11_Device.ImmediateContext.Rasterizer.State;
samplerState = m_d3d11_Device.ImmediateContext.PixelShader.GetSamplers(0, 1)[0]; // We only take the first SamplerState since its the only one we will change when we render the text texture to the back buffer below.
vertexShader = m_d3d11_Device.ImmediateContext.VertexShader.Get();
pixelShader = m_d3d11_Device.ImmediateContext.PixelShader.Get();

// Release the shared texture from the D3D 11 Device.
m_keyedMutex_d3d11.Release(0);
// Aquire the shared texture with the D3D 10.1 Device.
m_keyedMutex_d3d10.Acquire(0, int.MaxValue);

// Begin drawing Direct2D content.
m_d2dRenderTarget.BeginDraw();

// Clear the D2D Background
m_d2dRenderTarget.Clear(new Color4(1.0f, 0.0f, 0.0f, 0.0f));

// Set the Font Color
Color4 FontColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
// Set the brush color D2D will use to draw with.
m_d2dBrush.Color = FontColor;
// Create the D2D render area
System.Drawing.RectangleF layoutRect = new System.Drawing.RectangleF(0, 0, m_ParentWindow.ClientSize.Width, m_ParentWindow.ClientSize.Height);

// Draw the Text onto the shared texture.
m_d2dRenderTarget.DrawText(text,
m_DWrite_TextFormat,
layoutRect,
m_d2dBrush);
// Finish drawing Direct2D content.
m_d2dRenderTarget.EndDraw();

// Release the shared texture from the Direct3D 10.1 Device.
m_keyedMutex_d3d10.Release(1);
// Aquire the shared texture with the Direct3D 11 Device.
m_keyedMutex_d3d11.Acquire(1, int.MaxValue);

// Use the shader resource representing the Direct2D render target
// to texture a square which is rendered in screen space so it
// overlays on top of our entire scene. We use alpha blending so
// that the entire background of the D2D render target is "invisible",
// And only the stuff we draw with D2D will be visible (the text)

// Set the blending state of the Direct3D 11 device.
m_d3d11_Device.ImmediateContext.OutputMerger.BlendState = m_BlendState_Transparency;


// Set the vertex buffer for the text geometry (a square).
m_d3d11_Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new SlimDX.Direct3D11.VertexBufferBinding(m_d2dVertexBuffer, 20, 0));
// Set the index buffer for the text geometry.
m_d3d11_Device.ImmediateContext.InputAssembler.SetIndexBuffer(m_d2dIndexBuffer, Format.R16_UInt, 0);

// Set the vertex shader to the one this TextRenderer uses.
m_d3d11_Device.ImmediateContext.VertexShader.Set(m_vShader);
// Set the pixel shader to the one this TextRenderer uses.
m_d3d11_Device.ImmediateContext.PixelShader.Set(m_pShader);

// Set the world matrix to the Indentity Matrix.
Matrix tempP = m_cbOnResize.ProjectionMatrix;
Matrix tempV = m_cbPerFrame.ViewMatrix;
Matrix tempW = m_cbPerObject.WorldMatrix;
m_cbOnResize.ProjectionMatrix = Matrix.Identity;
m_cbOnResize.UpdateBuffer();
m_cbPerFrame.ViewMatrix = Matrix.Identity;
m_cbPerFrame.UpdateBuffer();
m_cbPerObject.WorldMatrix = Matrix.Identity;
m_cbPerObject.UpdateBuffer();



// Set the RasterizerState to our Clockwise Cull mode one.
m_d3d11_Device.ImmediateContext.Rasterizer.State = m_RasterizerState_CWcullmode;
// Set the shader resource (our shared text texture).
m_d3d11_Device.ImmediateContext.PixelShader.SetShaderResource(m_textTexture, 0);
// Set the SamplerState.
m_d3d11_Device.ImmediateContext.PixelShader.SetSampler(m_TextSamplerState, 0);


// Draw the text texture overlay on top of our scene.
m_d3d11_Device.ImmediateContext.DrawIndexed(6, 0, 0);
// Reset the vertex shader.
m_d3d11_Device.ImmediateContext.VertexShader.Set(vertexShader);
// Reset the pixel shader.
m_d3d11_Device.ImmediateContext.PixelShader.Set(pixelShader);
// Reset the states of the Direct3D 11 Device now that we are done with them.
// This way we leave the device how we found it for the parent program.
m_d3d11_Device.ImmediateContext.OutputMerger.BlendState = blendState;
m_d3d11_Device.ImmediateContext.Rasterizer.State = rasterizerState;
m_d3d11_Device.ImmediateContext.PixelShader.SetSampler(samplerState, 0);

// Reset the ConstantBuffers as well.
m_cbPerFrame.ViewMatrix = tempV;
m_cbOnResize.ProjectionMatrix = tempP;
m_cbPerObject.WorldMatrix = tempW;
m_cbOnResize.UpdateBuffer();
m_cbPerFrame.UpdateBuffer();
m_cbPerObject.UpdateBuffer();

}
#endregion

#region Operators
#endregion

#region IDisposable Members
// Implement IDisposable.
// Do not make this method virtual.
// A derived class should not be able to override this method.
public void Dispose()
{
Dispose(true);
// Since this Dispose() method already cleaned up the resources used by this object, there's no need for the
// Garbage Collector to call this class's Finalizer, so we tell it not to.
GC.SuppressFinalize(this);
}
protected void Dispose(bool disposing)
{
if (!this.m_bDisposed)
{
/*
* The following text is from MSDN (http://msdn.microsoft.com/en-us/library/fs2xkftw%28VS.80%29.aspx)
*
*
* Dispose(bool disposing) executes in two distinct scenarios:
*
* If disposing equals true, the method has been called directly or indirectly by a user's code and managed and unmanaged resources can be disposed.
* If disposing equals false, the method has been called by the runtime from inside the finalizer and only unmanaged resources can be disposed.
*
* When an object is executing its finalization code, it should not reference other objects, because finalizers do not execute in any particular order.
* If an executing finalizer references another object that has already been finalized, the executing finalizer will fail.
*/
if (disposing)
{
// Unregister events

// get rid of managed resources
m_ParentWindow = null; // We don't release this since it was created by the parent program.
m_d3d11_Device = null; // This was also created by the parent program.
m_d3d101_Device.Dispose();
m_keyedMutex_d3d10.Dispose();
m_keyedMutex_d3d11.Dispose();

m_d2dRenderTarget.Dispose();
m_d2dBrush.Dispose();
m_sharedTexture_d3d11.Dispose();
m_d2dVertexBuffer.Dispose();
m_d2dIndexBuffer.Dispose();
m_textTexture.Dispose();
m_BlendState_Transparency.Dispose();
m_RasterizerState_CWcullmode.Dispose();
m_TextSamplerState.Dispose();
m_DWrite_Factory.Dispose();
m_DWrite_TextFormat.Dispose();
m_pShader.Dispose();
m_vShader.Dispose();
m_vShaderSignature.Dispose();
}
// get rid of unmanaged resources

}
}
#endregion

#region Debug Methods
#if (DEBUG)
// put all debug methods in here...
#endif
#endregion

#region Properties
/// <summary>
/// Returns a boolean value indicating whether or not this object has been disposed.
/// </summary>
public bool IsDisposed
{
get
{
return m_bDisposed;
}
}
/// <summary>
/// Returns a boolean value indicating whether the GameWindow has finished initializing itself yet or not.
/// </summary>
virtual public bool IsInitialized
{
get
{
return m_bIsInitialized;
}
}
#endregion

#region Events
#endregion

#region Event Handlers
#endregion
}


I'm fairly sure the problem is somewhere in this class, but I have no idea what is wrong. I get no evidence that the text renderer class is doing anything at all. It has no effect on the output. And its quite difficult to debug these applications because you either get stupid vague error messages, or other nonsense. I can't use the DirectX Graphics Diagnostics tools in VS2012, because of course they don't support using D2D with DX11. This is quite a nasty big mess Microsoft has made for us...

And here is the shader code being used by the text renderer in case the problem lies there. I've mucked with this a lot too but no luck. I changed the pixel shader to output black no matter what so I could at least see if it is drawing something, but I still get nothing.

cbuffer cbPerResize : register( b0 )
{
matrix Projection;
};
cbuffer cbPerFrame : register( b1 )
{
matrix View;
};
cbuffer cbPerObject : register( b2 )
{
matrix World;
};
//--------------------------------------------------------------------------------------
Texture2D ObjTexture;
SamplerState ObjSamplerState;

struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float2 TexCoord : TEXCOORD;
};

VS_OUTPUT Text_VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD)
{
VS_OUTPUT output = (VS_OUTPUT)0;


matrix identity;
identity[0] = float4(1,0,0,0);
identity[1] = float4(0,1,0,0);
identity[2] = float4(0,0,1,0);
identity[3] = float4(0,0,0,1);

output.Pos = mul(inPos, identity);
/*
output.Pos = mul( inPos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
*/
output.TexCoord = inTexCoord;

return output;
}
float4 Text_PS(VS_OUTPUT input) : SV_TARGET
{
//return ObjTexture.Sample( ObjSamplerState, input.TexCoord );
return float4(0.0f, 0.0f, 0.0f, 0.0f);
}



This is just irritating because I've wasted the whole night trying to get this to work and I'm rather tired of microsoft and their bs. It is utterly rediculous that one has to go through all this crap just to get some lousy text on the screen...

Can anyone help me, I hope? And thank you so much for your time! Edited by Megafont

Share this post


Link to post
Share on other sites
Advertisement
I agree it is beyond ridiculous, the amount of code needed to display text. However, Microsoft are not giving us bullshit, the DX10/11 mutex/mix thingy is just because there was already a working technique, and they may have run out of time to move it all to DX11. They still provide arguably the best rendering code anywhere, so rather than get tired, I would say become more tolerant of the changes and imperfections. They are working on the dx10/11 issue and this is why I'm eagerly waiting for the 11.1 upgrade for Windows 7 (even tho I'm using W8 8-.).

In regards to your problem. I'm looking through my text code now. I have SlimDX text working. Edited by Gavin Williams

Share this post


Link to post
Share on other sites
Well your shader is wrong. The code .. return float4(0.0f, 0.0f, 0.0f, 0.0f); will simply return BLACK. You need to uncomment the code that you've commented out.

Edit : Oh ok, you are just trying to get a black square on the screen.

I'm way too tired. I will need to look at this tomorrow. If need be, I can post up the code that works for me. Edited by Gavin Williams

Share this post


Link to post
Share on other sites
Thanks guys! I'm not giving up, I was annoyed and also tired since I needed to get some sleep. But I will keep messing with it. I just need to figure out where exactly things are going wrong.

I know they probably had some reason for it. I look forward to 11.1 as well. I'm using Windows 7 64bit currently.


EDIT:
I started it up today and it miraculously drew the whole screen black as I would expect. So I don't know why it didn't do that last night. Since I know the texture is rendering on the screen now and covering the full screen, I uncommented the original code in the Pixel Shader. However, there is no text still, which means Direct2D did not render the text onto the texture for some reason. Now I just need to figure out why there is no text in the shared texture. Edited by Megafont

Share this post


Link to post
Share on other sites
What debug messages are you getting ? If it's not rendering you should be getting error message. You can always download PIX if you are really desperate to have a look at the graphics state and resources.

Are you a C++ programmer ? Or perhaps just too strictly following those tutorials. Because setting all your variables to null isn't necessary in C#. It's not a problem but it's not necessary, a simple declaration is sufficient ...

private SlimDX.Direct3D11.Texture2D textureD3D11; Edited by Gavin Williams

Share this post


Link to post
Share on other sites
I'm not seeing any messages in the output panel. There's just no text getting rendered for some reason. I can set the clear color for the shared surface to opaque blue and the entire screen is blue as expected but no text. So I know the shared texture is getting rendered on top of the scene.

I started with C++ and moved into C# later. Setting stuff to null is force of habit I guess lol. Edited by Megafont

Share this post


Link to post
Share on other sites
No problem. I already put the shader back. Here is the shader code as it is now.


cbuffer cbPerResize : register( b0 )
{
matrix Projection;
};
cbuffer cbPerFrame : register( b1 )
{
matrix View;
};
cbuffer cbPerObject : register( b2 )
{
matrix World;
};
//--------------------------------------------------------------------------------------
Texture2D ObjTexture;
SamplerState ObjSamplerState;

struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float2 TexCoord : TEXCOORD;
};

VS_OUTPUT Text_VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD)
{
VS_OUTPUT output = (VS_OUTPUT)0;


matrix identity;
identity[0] = float4(1,0,0,0);
identity[1] = float4(0,1,0,0);
identity[2] = float4(0,0,1,0);
identity[3] = float4(0,0,0,1);


output.TexCoord = inTexCoord;

return output;
}
float4 Text_PS(VS_OUTPUT input) : SV_TARGET
{
return ObjTexture.Sample( ObjSamplerState, input.TexCoord );
}



The shader appears to be working though because I set it to clear the shared texture to opaque blue and it did shade the entire screen opaque blue. But the text is drawn after we clear the buffer obviously, so the text should've been there, but there is only blue. lol The text is set to opaque white in the RenderText function. Once I get it working I'll make the class have a color property instead of setting it every time in that function and make a few other improvements to it. But for now my focus is on getting it working. No sense it potentially adding in new problems before I get the existing one(s) fixed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement