Advertisement

How load a 3d model with sharpdx

Started by July 22, 2014 11:24 PM
8 comments, last by Pedro Alves 10 years, 6 months ago

i can´t load a 3d model with sharpdx 2.6.2

this is my code


  static void Main()
    {
        if (!SharpDevice.IsDirectX11Supported())
        {
            System.Windows.Forms.MessageBox.Show("DirectX11 Not Supported");
            return;
        }

        //render form
        RenderForm form = new RenderForm();
        form.Text = "Tutorial 17: Query";
        //frame rate counter
        SharpFPS fpsCounter = new SharpFPS();


        using (SharpDevice device = new SharpDevice(form))
        {
            //load font
            SharpBatch font = new SharpBatch(device, "textfont.dds");

            //load model from wavefront obj file
            SharpMesh earth = SharpMesh.CreateFromObj(device, "../../../Models/planets/earth.obj");
            SharpMesh moon = SharpMesh.CreateFromObj(device, "../../../Models/planets/moon.obj");

            //init shader
            SharpShader shader = new SharpShader(device, "../../HLSL.txt",
                new SharpShaderDescription() { VertexShaderFunction = "VS", PixelShaderFunction = "PS" },
                new InputElement[] {  
                        new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                        new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
                        new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0)
                    });

            //init constant buffer
            Buffer11 buffer = shader.CreateBuffer<Data>();

            Query pipelineQuery = new Query(device.Device, new QueryDescription() { Flags = QueryFlags.None, Type = QueryType.PipelineStatistics });

            QueryDataPipelineStatistics stats = new QueryDataPipelineStatistics();


            //init frame counter
            fpsCounter.Reset();

            int lastX = 0;
            float currentAngle = 200;
            form.MouseMove += (sender, e) =>
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    currentAngle += (lastX - e.X);
                }
                lastX = e.X;
            };

            //main loop
            RenderLoop.Run(form, () =>
            {
                //Resizing
                if (device.MustResize)
                {
                    device.Resize();
                    font.Resize();
                }

                //apply states
                device.UpdateAllStates();

                //clear color
                device.Clear(Color.CornflowerBlue);

                //apply shader
                shader.Apply();


                //apply constant buffer to shader
                device.DeviceContext.VertexShader.SetConstantBuffer(0, buffer);
                device.DeviceContext.PixelShader.SetConstantBuffer(0, buffer);

                //set transformation matrix
                float ratio = (float)form.ClientRectangle.Width / (float)form.ClientRectangle.Height;
                Matrix projection = Matrix.PerspectiveFovLH(3.14F / 3.0F, ratio, 1F, 1000.0F);
                Matrix view = Matrix.LookAtLH(new Vector3(0, 0, -250), new Vector3(), Vector3.UnitY);
                Matrix world = Matrix.Translation(0, 0, 200) * Matrix.RotationY(MathUtil.DegreesToRadians(currentAngle));

                //light direction
                Vector3 lightDirection = new Vector3(0.5f, 0, -1);
                lightDirection.Normalize();


                Data sceneInformation = new Data()
                {
                    world = world,
                    worldViewProjection = world * view * projection,
                    lightDirection = new Vector4(lightDirection, 1)
                };

                //write data inside constant buffer
                device.UpdateData<Data>(buffer, sceneInformation);

                //draw mesh
                moon.Begin();
                for (int i = 0; i < moon.SubSets.Count; i++)
                {
                    device.DeviceContext.PixelShader.SetShaderResource(0, moon.SubSets[i].DiffuseMap);
                    moon.Draw(i);
                }

                //begin analizing
                device.DeviceContext.Begin(pipelineQuery);

                world = Matrix.RotationY(Environment.TickCount / 2000.0F);
                sceneInformation = new Data()
                {
                    world = world,
                    worldViewProjection = world * view * projection,
                    lightDirection = new Vector4(lightDirection, 1)
                };

                //write data inside constant buffer
                device.UpdateData<Data>(buffer, sceneInformation);

                //draw mesh
                earth.Begin();
                for (int i = 0; i < earth.SubSets.Count; i++)
                {
                    device.DeviceContext.PixelShader.SetShaderResource(0, earth.SubSets[i].DiffuseMap);
                    earth.Draw(i);
                }
                //end analizing
                device.DeviceContext.End(pipelineQuery);

                //get result
                while (!device.DeviceContext.GetData<QueryDataPipelineStatistics>(pipelineQuery, AsynchronousFlags.None, out stats))
                {
                }

                //begin drawing text
                font.Begin();

                //draw string
                fpsCounter.Update();
                font.DrawString("Earth Stats : FPS: " + fpsCounter.FPS, 0, 0, Color.White);

                //print earth stats
                font.DrawString("Earth Stats : Rotate Moon To Cover Earth ", 0, 30, Color.White);
                font.DrawString(string.Format("Primitive Count: {0}", stats.IAPrimitiveCount), 0, 60, Color.White);
                font.DrawString(string.Format("Vertex Count Count: {0}", stats.IAVerticeCount), 0, 90, Color.White);
                font.DrawString(string.Format("Vertex Shader Execution: {0}", stats.VSInvocationCount), 0, 120, Color.White);
                font.DrawString(string.Format("Pixel Shader Execution: {0}", stats.PSInvocationCount), 0, 150, Color.White);

                //flush text to view
                font.End();
                //present
                device.Present();




            });

            //release resource
            font.Dispose();
            earth.Dispose();
            moon.Dispose();
            buffer.Dispose();
            pipelineQuery.Dispose();
        }
    }

Error 1 The type 'SharpDX.Windows.RenderForm' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 526 9 Central
Error 2 The best overloaded method match for 'SharpHelper.SharpDevice.SharpDevice(SharpDX.Windows.RenderForm, bool)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 526 37 Central
Error 3 Argument 1: cannot convert from 'SharpDX.Windows.RenderForm [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Windows.RenderForm' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 526 53 Central
Error 4 The type 'SharpDX.Direct3D11.InputElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX.Direct3D11, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 536 13 Central
Error 5 The best overloaded method match for 'SharpHelper.SharpShader.SharpShader(SharpHelper.SharpDevice, string, SharpHelper.SharpShaderDescription, SharpDX.Direct3D11.InputElement[])' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 536 34 Central
Error 6 Argument 4: cannot convert from 'SharpDX.Direct3D11.InputElement[] [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.Direct3D11.dll]' to 'SharpDX.Direct3D11.InputElement[]' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 538 17 Central
Error 7 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 545 51 Central
Error 8 The type 'SharpDX.Direct3D11.Device' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX.Direct3D11, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 547 13 Central
Error 9 The best overloaded method match for 'SharpDX.Direct3D11.Query.Query(SharpDX.Direct3D11.Device, SharpDX.Direct3D11.QueryDescription)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 547 35 Central
Error 10 Argument 1: cannot convert from 'SharpDX.Direct3D11.Device' to 'SharpDX.Direct3D11.Device [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.Direct3D11.dll]' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 547 45 Central
Error 11 The best overloaded method match for 'SharpHelper.SharpDevice.Clear(SharpDX.Color4)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 580 17 Central
Error 12 The type 'SharpDX.Color4' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 580 17 Central
Error 13 Argument 1: cannot convert from 'SharpDX.Color' to 'SharpDX.Color4' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 580 30 Central
Error 14 The type 'SharpDX.Direct3D11.DeviceContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX.Direct3D11, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 587 17 Central
Error 15 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'VertexShader' and no extension method 'VertexShader' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 587 38 Central
Error 16 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'PixelShader' and no extension method 'PixelShader' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 588 38 Central
Error 17 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 601 17 Central
Error 18 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 601 45 Central
Error 19 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 609 35 Central
Error 20 The type 'SharpDX.Direct3D11.ShaderResourceView' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX.Direct3D11, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 615 21 Central
Error 21 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'PixelShader' and no extension method 'PixelShader' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 615 42 Central
Error 22 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'Begin' and no extension method 'Begin' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 620 38 Central
Error 23 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 623 40 Central
Error 24 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 631 35 Central
Error 25 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'PixelShader' and no extension method 'PixelShader' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 637 42 Central
Error 26 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'End' and no extension method 'End' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 641 38 Central
Error 27 'SharpDX.Direct3D11.DeviceContext' does not contain a definition for 'GetData' and no extension method 'GetData' accepting a first argument of type 'SharpDX.Direct3D11.DeviceContext' could be found (are you missing a using directive or an assembly reference?) C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 644 46 Central
Error 28 The best overloaded method match for 'SharpHelper.SharpBatch.DrawString(string, int, int, SharpDX.Color)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 653 17 Central
Error 29 The type 'SharpDX.Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'SharpDX, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null'. C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 653 17 Central
Error 30 Argument 4: cannot convert from 'SharpDX.Color [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Color' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 653 79 Central
Error 31 The best overloaded method match for 'SharpHelper.SharpBatch.DrawString(string, int, int, SharpDX.Color)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 656 17 Central
Error 32 Argument 4: cannot convert from 'SharpDX.Color [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Color' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 656 85 Central
Error 33 The best overloaded method match for 'SharpHelper.SharpBatch.DrawString(string, int, int, SharpDX.Color)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 657 17 Central
Error 34 Argument 4: cannot convert from 'SharpDX.Color [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Color' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 657 103 Central
Error 35 The best overloaded method match for 'SharpHelper.SharpBatch.DrawString(string, int, int, SharpDX.Color)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 658 17 Central
Error 36 Argument 4: cannot convert from 'SharpDX.Color [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Color' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 658 104 Central
Error 37 The best overloaded method match for 'SharpHelper.SharpBatch.DrawString(string, int, int, SharpDX.Color)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 659 17 Central
Error 38 Argument 4: cannot convert from 'SharpDX.Color [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Color' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 659 113 Central
Error 39 The best overloaded method match for 'SharpHelper.SharpBatch.DrawString(string, int, int, SharpDX.Color)' has some invalid arguments C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 660 17 Central
Error 40 Argument 4: cannot convert from 'SharpDX.Color [c:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\packages\SharpDX.2.6.2\Bin\DirectX11-Signed-net40\SharpDX.dll]' to 'SharpDX.Color' C:\Users\Pedro\Dropbox\GAMES\NeoforceControls-SharpDX-master\Central\Code\Layout.cs 660 112 Central

Hello

I'm sorry, but did you actually read the errors? Several of them state that you need to add references to SharpDx libraries. Here's a link to the docs.

http://msdn.microsoft.com/en-us/library/7314433t(v=vs.90).aspx

Advertisement

i know the problem i using the references for version 2.6.2 and i have the other class is using 2.6.0

i try pass to references it is 2.6.0 to 2.6.2 and i have the same error

Hello

Are you trying to use SharpDx with another library that is using an older version of SharpDx? In that case, can't you upgrade that other library or downgrade your installation? I don't really think that's the problem though, it should give you another error.

What do you mean by "pass to references"? Have you added all related references to your project? Have you used C#/.NET before?

yes

only with simple commande line and windows forms

in xna i can make to change the GameState

its possibel make with sharpdx

Hello

You mean you have created console applications before, or do you mean you are trying to compile this project from commandline using something like csc.exe?

Again, have you added SharpDx.dll to your project references? As in using the "Project -> Add Reference..." menu or by right-clicking your project in the solution explorer. That's what the error message says you need to do.

Why do you think the problem is related to the version of the library?

Advertisement

yes i add the references

i make some small create command line applications

i change my code and i have this error

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in SharpDX.D3DCompiler.dll

Additional information: Could not open the shader or effect file.


  private static void Main()
        {
            var form = new RenderForm("SharpDX - MiniTri Direct3D 11 Sample");

            // SwapChain description
            var desc = new SwapChainDescription()
                           {
                               BufferCount = 1,
                               ModeDescription=
                                   new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                                       new Rational(60, 1), Format.R8G8B8A8_UNorm),
                               IsWindowed = true,
                               OutputHandle = form.Handle,
                               SampleDescription = new SampleDescription(1, 0),
                               SwapEffect = SwapEffect.Discard,
                               Usage = Usage.RenderTargetOutput
                           };

            // Create Device and SwapChain
            Device device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
            var context = device.ImmediateContext;

            // Ignore all windows events
            var factory = swapChain.GetParent<Factory>();
            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            // New RenderTargetView from the backbuffer
            var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
            var renderView = new RenderTargetView(device, backBuffer);

            // Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniTr.fx", "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None);
            var vertexShader = new VertexShader(device, vertexShaderByteCode);

            var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniTr.fx", "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None);
            var pixelShader = new PixelShader(device, pixelShaderByteCode);

            // Layout from VertexShader input signature
            var layout = new InputLayout(
                device,
                ShaderSignature.GetInputSignature(vertexShaderByteCode),
                new[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
                    });

            // Instantiate Vertex buiffer from vertex data
            var vertices = Buffer.Create(device, BindFlags.VertexBuffer, new[]
                                  {
                                      new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                                      new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
                                  });

            // Prepare All the stages
            context.InputAssembler.InputLayout = layout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new SharpDX.Direct3D11.VertexBufferBinding(vertices, 32, 0));
            context.VertexShader.Set(vertexShader);
            context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
            context.PixelShader.Set(pixelShader);
            context.OutputMerger.SetTargets(renderView);

            // Main loop
            RenderLoop.Run(form, () =>
                                      {
                                          context.ClearRenderTargetView(renderView, Color.Black);
                                          context.Draw(3, 0);
                                          swapChain.Present(0, PresentFlags.None);
                                      });

            // Release all resources
            vertexShaderByteCode.Dispose();
            vertexShader.Dispose();
            pixelShaderByteCode.Dispose();
            pixelShader.Dispose();
            vertices.Dispose();
            layout.Dispose();
            renderView.Dispose();
            backBuffer.Dispose();
            context.ClearState();
            context.Flush();
            device.Dispose();
            context.Dispose();
            swapChain.Dispose();
            factory.Dispose();
        }

Hello

That error is becuase ShaderBytecode.CompileFromFile can't find "MiniTr.fx".

you might need to move it into the working directory.

thanks i find the problem

its possibel change game state with sharpdx

in xna its possibel

i can´t load the model with no open a new form i want open in class world

this is my code


using TomShane.Neoforce.Controls;
using SharpDX.Toolkit.Graphics;
using SharpDX.Toolkit;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Windows;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
using MapFlags = SharpDX.Direct3D11.MapFlags;
using System.Text;
using System.Security.Cryptography;
using System.Security;
using System.Net.Sockets;
using System.IO;
using TomShane.Neoforce.Central.Code;
using System.Net;
using System.Windows.Forms;
using System.Diagnostics;
using System;

namespace TomShane.Neoforce.Central.Code
{
    public sealed partial class World : Window
    {
         string texto;
       
         TomShane.Neoforce.Controls.TabControl tbc;
        public World(Manager manager, string text)
            : base(manager)
        {
           //Main();
            texto = text;
            System.Console.Write(texto);
            InitConsole(texto);
           
        }

       
        private static void Main()
        {
            var form = new RenderForm("SharpDX - MiniTri Direct3D 11 Sample");

            // SwapChain description
            var desc = new SwapChainDescription()
                           {
                               BufferCount = 1,
                               ModeDescription= 
                                   new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                                       new Rational(60, 1), Format.R8G8B8A8_UNorm),
                               IsWindowed = true,
                               OutputHandle = form.Handle,
                               SampleDescription = new SampleDescription(1, 0),
                               SwapEffect = SwapEffect.Discard,
                               Usage = Usage.RenderTargetOutput
                           };

            // Create Device and SwapChain
            Device device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
            var context = device.ImmediateContext;

            // Ignore all windows events
            var factory = swapChain.GetParent<Factory>();
            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            // New RenderTargetView from the backbuffer
            var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
            var renderView = new RenderTargetView(device, backBuffer);

            // Compile Vertex and Pixel shaders
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None);
            var vertexShader = new VertexShader(device, vertexShaderByteCode);

            var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None);
            var pixelShader = new PixelShader(device, pixelShaderByteCode);

            // Layout from VertexShader input signature
            var layout = new InputLayout(
                device,
                ShaderSignature.GetInputSignature(vertexShaderByteCode),
                new[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
                    });

            // Instantiate Vertex buiffer from vertex data
            var vertices = Buffer.Create(device, BindFlags.VertexBuffer, new[]
                                  {
                                      new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                                      new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
                                  });

            // Prepare All the stages
            context.InputAssembler.InputLayout = layout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new SharpDX.Direct3D11.VertexBufferBinding(vertices, 32, 0));
            context.VertexShader.Set(vertexShader);
            context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
            context.PixelShader.Set(pixelShader);
            context.OutputMerger.SetTargets(renderView);

            // Main loop
            RenderLoop.Run(form, () =>
                                      {
                                          context.ClearRenderTargetView(renderView, Color.Black);
                                          context.Draw(3, 0);
                                          swapChain.Present(0, PresentFlags.None);
                                      });

            // Release all resources
            vertexShaderByteCode.Dispose();
            vertexShader.Dispose();
            pixelShaderByteCode.Dispose();
            pixelShader.Dispose();
            vertices.Dispose();
            layout.Dispose();
            renderView.Dispose();
            backBuffer.Dispose();
            context.ClearState();
            context.Flush();
            device.Dispose();
            context.Dispose();
            swapChain.Dispose();
            factory.Dispose();
        }
        
        #region Console
        ////////////////////////////////////////////////////////////////////////////
        private void InitConsole(string texto)
        {
            tbc = new TomShane.Neoforce.Controls.TabControl(Manager);
            TomShane.Neoforce.Controls.Console con1 = new TomShane.Neoforce.Controls.Console(Manager);
            TomShane.Neoforce.Controls.Console con2 = new TomShane.Neoforce.Controls.Console(Manager);

            // Setup of TabControl, which will be holding both consoles
            tbc.Init();
            tbc.AddPage("Global");
            tbc.AddPage("Guild");
            tbc.AddPage("PARTY");
            tbc.AddPage("TRADE");

            tbc.Alpha = 220;
            tbc.Left = 0;
            tbc.Height = 220;
            tbc.Width = 450;
            tbc.Top = Manager.TargetHeight - tbc.Height - 32;

            tbc.Movable = true;
            tbc.Resizable = true;
            tbc.MinimumHeight = 96;
            tbc.MinimumWidth = 160;

            tbc.TabPages[0].Add(con1);
            tbc.TabPages[1].Add(con2);

            con1.Init();
            con1.Sender = texto;
            con2.Init();
            con2.Sender = texto;

            con2.Width = con1.Width = tbc.TabPages[0].ClientWidth;
            con2.Height = con1.Height = tbc.TabPages[0].ClientHeight;
            con2.Anchor = con1.Anchor = Anchors.All;

            con1.Channels.Add(new ConsoleChannel(0, "General", SharpDX.Color.Orange));
            con1.Channels.Add(new ConsoleChannel(1, "Private", SharpDX.Color.White));
            con1.Channels.Add(new ConsoleChannel(2, "System", SharpDX.Color.Yellow));
            con1.Channels.Add(new ConsoleChannel(3, "Guild", SharpDX.Color.Green));
            con1.Channels.Add(new ConsoleChannel(4, "Trade", SharpDX.Color.Red));
            // We want to share channels and message buffer in both consoles
            con2.Channels = con1.Channels;
            con2.MessageBuffer = con1.MessageBuffer;

            // In the second console we display only "Private" messages
            con2.ChannelFilter.Add(3);

            // Select default channels for each tab
            con1.SelectedChannel = 0;
            con2.SelectedChannel = 3;

            // Do we want to add timestamp or channel name at the start of every message?
            con1.MessageFormat = ConsoleMessageFormats.All;
            con2.MessageFormat = ConsoleMessageFormats.All;

            // Handler for altering incoming message
            con1.MessageSent += new ConsoleMessageEventHandler(con1_MessageSent);

            // We send initial welcome message to System channel
            con1.MessageBuffer.Add(new ConsoleMessage("System", "WELCOME TO THE SERVER! " + texto, 2));

            Manager.Add(tbc);
        }
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        void con1_MessageSent(object sender, ConsoleMessageEventArgs e)
        {
            if (e.Message.Channel == 0)
            {
                //e.Message.Text = "(!) " + e.Message.Text;
            }
        }
        ////////////////////////////////////////////////////////////////////////////

        #endregion

    }
}

Hello

topic can be close problem as been solve it

this how i solve the problem


 public class Gamer : Game
    {
        private Manager NeoManager;
     
        private Window window;
        private GraphicsDeviceManager graphicsDeviceManager;
        private IScreen correntscreen;
        private List<IScreen> listscreen;
        private SpriteBatch spriteBatch;
        private SpriteFont arial16BMFont;

        private PointerManager pointer;

        private Model model;

        private List<Model> models;

        private BoundingSphere modelBounds;
        private Matrix world;
        private Matrix view;
        private Matrix projection;
      

        /// <summary>
        /// Initializes a new instance of the <see cref="MiniCubeGame" /> class.
        /// </summary>
        public Gamer()
        {
            // Creates a graphics manager. This is mandatory.
            graphicsDeviceManager = new GraphicsDeviceManager(this);
            graphicsDeviceManager.PreferredGraphicsProfile = new FeatureLevel[] { FeatureLevel.Level_9_1, };
  
            pointer = new PointerManager(this);
            // Setup the relative directory to the executable directory
            // for loading contents with the ContentManager
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
          
          
           
        }

        protected override void LoadContent()
        {
            arial16BMFont = Content.Load<SpriteFont>("Arial16");

            // Load the model (by default the model is loaded with a BasicEffect. Use ModelContentReaderOptions to change the behavior at loading time.
            models = new List<Model>();
            foreach (var modelName in new[] { "Dude", "Duck", "Car", "Happy", "Knot", "Skull", "Sphere", "Teapot","helmet" })
            {
                model = Content.Load<Model>(modelName);

                // Enable default lighting  on model.
                BasicEffect.EnableDefaultLighting(model, true);

                models.Add(model);
            }
            model = models[0];

            // Instantiate a SpriteBatch
            spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice));
    
         
            base.LoadContent();
       
        
           }

        protected override void Initialize()
        {
        
           
            Window.Title = "Firstgame";
       
            base.Initialize();
           
        }

        protected override void Update(GameTime gameTime)
        {
       
            base.Update(gameTime);
            var pointerState = pointer.GetState();
            if (pointerState.Points.Count > 0 && pointerState.Points[0].EventType == PointerEventType.Released)
            {
                // Go to next model when pressing key space
                model = models[(models.IndexOf(model) + 1) % models.Count];
            }

            // Calculate the bounds of this model
            modelBounds = model.CalculateBounds();

            // Calculates the world and the view based on the model size
            const float MaxModelSize = 10.0f;
            var scaling = MaxModelSize / modelBounds.Radius;
            view = Matrix.LookAtRH(new Vector3(0, 0, MaxModelSize * 2.5f), new Vector3(0, 0, 0), Vector3.UnitY);
            projection = Matrix.PerspectiveFovRH(0.9f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, MaxModelSize * 10.0f);
            world = Matrix.Translation(-modelBounds.Center.X, -modelBounds.Center.Y, -modelBounds.Center.Z) * Matrix.Scaling(scaling) * Matrix.RotationY((float)gameTime.TotalGameTime.TotalSeconds);
           
        }

        protected override void Draw(GameTime gameTime)
        {

     
           GraphicsDevice.Clear(Color.CornflowerBlue);
           model.Draw(GraphicsDevice, world, view, projection);

           // Render the text
          spriteBatch.Begin();
           spriteBatch.DrawString(arial16BMFont, "Press the pointer to switch models...\r\nCurrent Model: " + model.Name, new Vector2(16, 16), Color.White);
           spriteBatch.End();
       
         
            base.Draw(gameTime);
          
        }
     
    }
}

Hello

This topic is closed to new replies.

Advertisement