Cannot draw primitives with SharpDX on Windows 10 Universal App (but still able to clear the background)

Sorry because of my bad English. I am trying to write a very simple DirectX 11 on Windows 10 app with SharpDX, which draws a triangle at the middle of the windows. The problem is the triangle is not displayed while I can still change the background color (using ClearRenderTargetView). I verified that the render function is called periodically and my triangle is front-face (clockwise). What I have tried:

  • Disable back-face culling
  • Set static width and height
  • Try other primitives (line, triangle strip)
  • Change vertex shader input from float3 to float4 and vice-versa

I found that this post has very similar symptoms but still not work!

I have posted my code on GitHub at: https://github.com/minhcly/UWP3DTest

Here is my initialization code (where I think the problem resides):

    D3D11.Device2 device;     D3D11.DeviceContext deviceContext;     DXGI.SwapChain2 swapChain;     D3D11.Texture2D backBufferTexture;     D3D11.RenderTargetView backBufferView;      private void InitializeD3D()     {         using (D3D11.Device defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.Debug))             this.device = defaultDevice.QueryInterface<D3D11.Device2>();         this.deviceContext = this.device.ImmediateContext2;          DXGI.SwapChainDescription1 swapChainDescription = new DXGI.SwapChainDescription1()         {             AlphaMode = DXGI.AlphaMode.Ignore,             BufferCount = 2,             Format = DXGI.Format.R8G8B8A8_UNorm,             Height = (int)(this.swapChainPanel.RenderSize.Height),             Width = (int)(this.swapChainPanel.RenderSize.Width),             SampleDescription = new DXGI.SampleDescription(1, 0),             Scaling = SharpDX.DXGI.Scaling.Stretch,             Stereo = false,             SwapEffect = DXGI.SwapEffect.FlipSequential,             Usage = DXGI.Usage.RenderTargetOutput         };          using (DXGI.Device3 dxgiDevice3 = this.device.QueryInterface<DXGI.Device3>())         using (DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent<DXGI.Factory3>())         {             DXGI.SwapChain1 swapChain1 = new DXGI.SwapChain1(dxgiFactory3, this.device, ref swapChainDescription);             this.swapChain = swapChain1.QueryInterface<DXGI.SwapChain2>();         }          using (DXGI.ISwapChainPanelNative nativeObject = ComObject.As<DXGI.ISwapChainPanelNative>(this.swapChainPanel))             nativeObject.SwapChain = this.swapChain;          this.backBufferTexture = this.swapChain.GetBackBuffer<D3D11.Texture2D>(0);         this.backBufferView = new D3D11.RenderTargetView(this.device, this.backBufferTexture);         this.deviceContext.OutputMerger.SetRenderTargets(this.backBufferView);          deviceContext.Rasterizer.State = new D3D11.RasterizerState(device, new D3D11.RasterizerStateDescription()         {             CullMode = D3D11.CullMode.None,             FillMode = D3D11.FillMode.Solid,             IsMultisampleEnabled = true         });         deviceContext.Rasterizer.SetViewport(0, 0, (int)swapChainPanel.Width, (int)swapChainPanel.Height);          CompositionTarget.Rendering += CompositionTarget_Rendering;         Application.Current.Suspending += Current_Suspending;          isDXInitialized = true;     } 

InitScene() function:

    D3D11.Buffer triangleVertBuffer;     D3D11.VertexShader vs;     D3D11.PixelShader ps;     D3D11.InputLayout vertLayout;     RawVector3[] verts;      private void InitScene()     {         D3D11.InputElement[] inputElements = new D3D11.InputElement[]         {             new D3D11.InputElement("POSITION", 0, DXGI.Format.R32G32B32_Float, 0)         };          using (CompilationResult vsResult = ShaderBytecode.CompileFromFile("vs.hlsl", "main", "vs_4_0"))         {             vs = new D3D11.VertexShader(device, vsResult.Bytecode.Data);             vertLayout = new D3D11.InputLayout(device, vsResult.Bytecode, inputElements);         }          using (CompilationResult psResult = ShaderBytecode.CompileFromFile("ps.hlsl", "main", "ps_4_0"))             ps = new D3D11.PixelShader(device, psResult.Bytecode.Data);          deviceContext.VertexShader.Set(vs);         deviceContext.PixelShader.Set(ps);          verts = new RawVector3[] {             new RawVector3( 0.0f, 0.5f, 0.5f ),             new RawVector3( 0.5f, -0.5f, 0.5f ),             new RawVector3( -0.5f, -0.5f, 0.5f )         };         triangleVertBuffer = D3D11.Buffer.Create(device, D3D11.BindFlags.VertexBuffer, verts);          deviceContext.InputAssembler.InputLayout = vertLayout;         deviceContext.InputAssembler.PrimitiveTopology = D3D.PrimitiveTopology.TriangleList;     } 

Render function:

    private void RenderScene()     {         this.deviceContext.ClearRenderTargetView(this.backBufferView, new RawColor4(red, green, blue, 0));          deviceContext.InputAssembler.SetVertexBuffers(0,             new D3D11.VertexBufferBinding(triangleVertBuffer, Utilities.SizeOf<RawVector3>(), 0));         deviceContext.Draw(verts.Length, 0);          this.swapChain.Present(0, DXGI.PresentFlags.None);     } 

Thank you for your help.

Replay

Category: c# Time: 2016-07-28 Views: 0

Related post

  • playing background audio using sharpDx in windows universal app 8.1? 2016-01-28

    How to play background audio using sharpDX in windows universal app 8.1,actually we are doing one music application, in that we are playing multiple songs simultaneously for that, when we minimize that application the playing songs should run on the

  • synchronize threads across processes in windows universal apps 2016-01-14

    Why is the System.Security.AccessControl namespace not available for Windows Universal apps? I'm trying to use a named EventWaitHandle (or, a named Semaphore) that is global to the OS instance, but to do this seems to require the constructor that use

  • Debugging a Windows Universal App without deploying 2016-01-18

    I'm creating a Windows Universal App but when I run it and try to debug it, none of my changes seem to take unless I deploy first, then run/debug. It's somewhat tedious to have to do this, am I missing a setup in my environment? -shnar --------------

  • Create a payment via the Windows Store in Windows Universal Apps 2016-01-14

    Is possible to create a payment via Windows Store when purchased content is a HTML content downloaded from cloud in Windows Universal Apps? I was only able to find, that Window Store provides: Time trial In-app purchases (this is close, but with in-a

  • Windows Universal App Webview get POST data 2016-01-18

    I am trying to retrieve the POST data from a WebView in my Windows Universal App. To do this I am trying to inject a piece of JavaScript into the page (I do not own the website), which I can later use to retrieve the entered data. I have the followin

  • Realizing Master Detail pattern in windows universal app 2016-01-19

    I am stuck (StuckExchange). I need to do windows universal app. it should have some pages and one top bar and one side menu, same for all pages. As I understand I should use SplitView and master/details pattern (or am I wrong, and it is better way to

  • streaming images in windows universal apps c# 2016-02-13

    The classes i used in c# to stream videos over the net in c# are not accepted in windows universal apps. So please can someone tell me how to create bitmap convert it to byte[] send it over socket and convert it back to bit map. First of all c# in un

  • storagefile encryption in windows universal app [on hold] 2016-07-13

    Windows Universal App: How can I encrypt and decrypt a StorageFile with my own password and my own salt with AES?

  • Make soft keyboard pop up in Javascript/HTML Windows Universal App 2015-11-21

    I've written a couple apps using HTML and Javascript for Windows 10's new Universal App Platform, and I've hit a serious bug: when they're run on a touch-enabled device in tablet mode, touching a text input element doesn't cause the soft keyboard to

  • Windows universal app Rest API Raspberry Pi 2016-01-20

    I have Windows Core running on a Raspberry PI. How do I create a rest API in a Windows universal app to run on it? I want to be able send remote commands to the Raspberry PI from a mobile device. I did several search and couldn't find much informatio

  • How to find Windows Universal app windows from C# 2016-02-08

    I want to write my own program that lets me select one Window of ALL open windows and set the state of this window to TOP, so that this selected window will always show on top! The problem... since Windows 8 there are APPs and actually the process co

  • How to deploy windows Development app to client for testing over the air 2016-02-01

    How anyone can deploy windows Development app to client for testing over the air (i.e client can download app through specific URL or similar to it) like we do for iOS through test flight ,diawi.com?

  • Draw Primitives with Unity 2D 2014-10-28

    I would like to be able to draw primitives in unity 2d to define my game objects. I have tried the following example: using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Material mat; private Vector3 startV

  • Cannot send email with SMTP in Windows Forms 2016-01-30

    So, I am working on windows Forms and trying so send email with smtp. Here is a Code: MailMessage mail = new MailMessage(from, to, subject, text); SmtpClient client = new SmtpClient("smtp.gmail.com"); client.Port = 465; client.EnableSsl = true;

  • Draw line with scrollable canvas window 2016-02-02

    I am new one for canvas.I want to know how to draw a line with scrollable canvas window.my expectation is canvas window fit the screen and if line went to out side of the view port then the canvas window is scrollable until to view the end of the lin

  • Cannot draw graph with many nodes in LaTeX 2013-10-08

    Here is the LaTeX code generated by a package \documentclass[11pt]{article} \usepackage{auto-pst-pdf,pstricks,pst-node,pst-tree,geometry} \usepackage{lscape} \pagestyle{empty} \newcommand{\Tbox}[1]{\Tr{\psframebox{#1}}} \begin{document} \begin{landsc

  • Windows universal app keyboard moves content out of screen 2016-01-25

    i have the same problem like Windows 10 Universal app: Keep Keyboard after Button clicked and content adjustment after keyboard flyin in the second question. I have an app with grids and some content but all in grids. so when i test the app in an emu

  • Formatted drive with Wubi installation, Windows boot manager menu still shows option 2013-09-28

    This question already has an answer here: How do I remove the extra Ubuntu option on the Windows Boot Manager menu? 2 answers I had Ubuntu 12.04 installed with Wubi on a partition of my main HDD and decided I would do a proper installation of it. In

  • Updating Users with Notifications in Windows Phone Apps 2015-12-04

    There are different ways an app can interact with a user. Windows Phone has a unique way of giving the latest information, even when the app is not running, through tiles and badges. This saves battery and is a user friendly experience. Whether a new

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 3.538 (s). 13 q(s)