public override void Initialize() { if (!IsInitialized) { ShaderRepository.SetupD3D10_SM40(_shaderRepositoryDir); var gfactory = Service.Require <Graphics.GraphicDeviceFactory>(); var pFactory = Service.Get <Physics.PhysicManager>(); var iFactory = Service.Get <Input.InputManager>(); Engine.Initialize(new InputContext(_mainForm.Handle), new GraphicDeviceDesc { Adapter = 0, DriverType = GraphicDeviceType.Hardware, Context = new WindowContext(_canvas.Handle) { BackBufferWidth = _canvas.Width, BackBufferHeight = _canvas.Height, BackBufferFormat = Format.R8G8B8A8_UNORM_SRGB, DepthStencilFormat = Format.D24_UNORM_S8_UINT, FullScreen = false, Sampling = new Multisampling(1, 0), Presentation = PresentionInterval.Default } }); _canvas.Resize += canvas_Resize; Application.Idle += Application_Idle; base.Initialize(); } }
public static void Init(Window window, Canvas3D mainCanvas) { //Initialize Graphics API Service.Set <GraphicDeviceFactory>(new IgneelD3D10.GraphicManager10()); //Initialize Input API Service.Set <Igneel.Input.InputManager>(new IgneelDirectInput.DInputManager()); //Initialize shader respository ShaderRepository.SetupD3D10_SM40(_shaderRepositoryDir); var gfactory = Service.Require <GraphicDeviceFactory>(); var iFactory = Service.Get <Igneel.Input.InputManager>(); //Helper to get the HWND Handle var interopHelper = new WindowInteropHelper(window); //The canvas size var size = mainCanvas.RenderSize; EngineState.Shading.FillMode = FillMode.Wireframe; //Initialize the Canvas. The Canvas3D is used to render to the screen in a WPF context //this is achived by creating a GraphicPresenter mainCanvas.Init(); //Initialize the Engine and creating the IGraphicContext by setting the BackBuffer and DepthStencil descriptions Engine.Initialize(new InputContext(interopHelper.Handle), new GraphicDeviceDesc { Adapter = 0, DriverType = GraphicDeviceType.Hardware, Context = new WindowContext(mainCanvas.Handle) { BackBufferWidth = (int)size.Width, BackBufferHeight = (int)size.Height, BackBufferFormat = Format.R8G8B8A8_UNORM_SRGB, DepthStencilFormat = Format.D24_UNORM_S8_UINT, FullScreen = false, Sampling = new Multisampling(1, 0), Presentation = PresentionInterval.Default } }); //Set the Engine presenter to the Canvas3D presenter //this instruct the Engine to render the content using the Canvas3D GraphicPresenter Engine.Presenter = mainCanvas.CreateDafultPresenter(); //Set default Lighting and Shading properties EngineState.Lighting.HemisphericalAmbient = true; EngineState.Lighting.Reflection.Enable = true; EngineState.Lighting.TransparencyEnable = true; EngineState.Shading.BumpMappingEnable = true; //Initialize the Hight Level rendering System //This will register the renders fo each components for each supported shading techniques InitializeRendering(); //InitializeServices(); }
public static void Init(MainWindow window, Canvas3D mainCanvas) { Service.Set <GraphicDeviceFactory>(new IgneelD3D10.GraphicManager10()); // Service.Set<PhysicManager>(new Igneel.PhysX.PXPhysicManager()); Service.Set <Igneel.Input.InputManager>(new IgneelDirectInput.DInputManager()); ShaderRepository.SetupD3D10_SM40(_shaderRepositoryDir); var gfactory = Service.Require <GraphicDeviceFactory>(); var pFactory = Service.Get <PhysicManager>(); var iFactory = Service.Get <Igneel.Input.InputManager>(); var interopHelper = new WindowInteropHelper(window); var size = mainCanvas.RenderSize; EngineState.Shadow.ShadowMapping.Size = 3; mainCanvas.Init(); Engine.Initialize(new InputContext(interopHelper.Handle), new GraphicDeviceDesc { Adapter = 0, DriverType = GraphicDeviceType.Hardware, Context = new WindowContext(mainCanvas.Handle) { BackBufferWidth = (int)size.Width, BackBufferHeight = (int)size.Height, BackBufferFormat = Format.R8G8B8A8_UNORM_SRGB, DepthStencilFormat = Format.D24_UNORM_S8_UINT, FullScreen = false, Sampling = new Multisampling(1, 0), Presentation = PresentionInterval.Default } }); Engine.Presenter = mainCanvas.CreateDafultPresenter(); EngineState.Lighting.HemisphericalAmbient = true; EngineState.Lighting.Reflection.Enable = true; EngineState.Lighting.TransparencyEnable = true; EngineState.Shading.BumpMappingEnable = true; InitializeRendering(); InitializeServices(); }
public override void Initialize() { if (!IsInitialized) { ShaderRepository.SetupD3D10_SM40(_shaderRepositoryDir); var gfactory = Service.Require <Graphics.GraphicDeviceFactory>(); var pFactory = Service.Get <Physics.PhysicManager>(); var iFactory = Service.Get <Input.InputManager>(); var interopHelper = new WindowInteropHelper(_window); int width = double.IsNaN(_canvas.Width) ? 100:(int)_canvas.Width; int height = double.IsNaN(_canvas.Height) ? 100 : (int)_canvas.Height; Engine.Initialize(new InputContext(interopHelper.Handle), new GraphicDeviceDesc { Adapter = 0, DriverType = GraphicDeviceType.Hardware, Context = new WindowContext(_canvas.Handle) { BackBufferWidth = width, BackBufferHeight = height, BackBufferFormat = Format.R8G8B8A8_UNORM_SRGB, DepthStencilFormat = Format.D24_UNORM_S8_UINT, FullScreen = false, Sampling = new Multisampling(1, 0), Presentation = PresentionInterval.Default } }); _canvas.SizeChanged += canvas_Resize; //DispatcherFrame frame = new DispatcherFrame(true); //Dispatcher.CurrentDispatcher.BeginInvoke(new DispatcherOperationCallback(DoFrame), DispatcherPriority.ApplicationIdle, frame); CompositionTarget.Rendering += CompositionTarget_Rendering; //window.Dispatcher.Hooks.DispatcherInactive += Hooks_DispatcherInactive; //window.Dispatcher.Hooks.OperationPosted += Hooks_OperationPosted; base.Initialize(); } }
private void CreateDevice() { //Tell the API were the folder containing the shader's code are ,and the ShaderModel ShaderRepository.SetupD3D10_SM40("Shaders"); //Instantiate GraphicDeviceFactory in this case we are using Direct3D10 so an instance of GraphicManager10 is required var devFactory = new IgneelD3D10.GraphicManager10(); //Create de GraphicDevice passsing a GraphicDeviceDesc containing device configuration and //and the rendering environment. In this case we use the WindowContext because this is a WindowsForms application device = devFactory.CreateDevice(new GraphicDeviceDesc(new WindowContext(Handle) { BackBufferWidth = Width, BackBufferHeight = Height, BackBufferFormat = Format.R8G8B8A8_UNORM_SRGB, DepthStencilFormat = Format.D24_UNORM_S8_UINT, FullScreen = false, Sampling = new Multisampling(1, 0), Presentation = PresentionInterval.Default } )); //Creates a ShaderProgram passsing the files containing the shader's code for the VertexShader and PixelShader stages shaderProgram = device.CreateProgram <TriangleVertex>("VertexShaderVS", "PixelShaderPS"); //Retrieve a type safe mapping for setting the uniforms variables input = shaderProgram.Map <ProgramMapping>(); //Set pipeline states blendState = device.CreateBlendState(new BlendDesc(blendEnable: false, srcBlend: Blend.SourceAlpha, destBlend: Blend.InverseSourceAlpha)); depthStenciState = device.CreateDepthStencilState(new DepthStencilStateDesc(depthFunc: Comparison.Less)); cullingState = device.CreateRasterizerState(new RasterizerDesc(cull: CullMode.Back)); device.Blend = blendState; device.Rasterizer = cullingState; device.DepthTest = depthStenciState; }
private void Init() { //Setup shader model version and default compiling options, //also set the relative directory where the shaders are located ShaderRepository.SetupD3D10_SM40("Shaders"); //Create an instance of the GraphicDeviceFactory. //The GraphicDeviceFactory abstract class is used to creates GraphicDevices without worrying about the native implementation. //This sample use a Direc3D10 native implementation, therefore an instance of a GraphicManager10 is created GraphicDeviceFactory devFactory = new IgneelD3D10.GraphicManager10(); //A GraphicDevice is created using a WindowContext containing rendering and display settings. device = devFactory.CreateDevice(new WindowContext(Handle) { BackBufferWidth = Width, BackBufferHeight = Height, BackBufferFormat = Format.R8G8B8A8_UNORM, DepthStencilFormat = Format.D24_UNORM_S8_UINT, FullScreen = false, Sampling = new Multisampling(1, 0), Presentation = PresentionInterval.Default }); //Create a ShaderProgram using the input layout definition provided by the SphereVertex struct //and the code for the vertex and pixel shaders located in the VertexShaderVS and PixelShaderPS files. //As a convention the last 2 characters in the filename specify the type of shader to load. shaderProgram = device.CreateProgram <SphereVertex>("VertexShaderVS", "PixelShaderPS"); //Get a typed mapping using the ProgramMapping interface for the ShaderProgram uniform variables and textures input = shaderProgram.Map <ProgramMapping>(); //The application blending state allowing transparency blend device.Blend = device.CreateBlendState(new BlendDesc( blendEnable: true, srcBlend: Blend.SourceAlpha, destBlend: Blend.InverseSourceAlpha)); //The application depth testing state device.DepthTest = device.CreateDepthStencilState(new DepthStencilStateDesc( depthFunc: Comparison.Less)); //The application rasterizer state device.Rasterizer = device.CreateRasterizerState(new RasterizerDesc( cull: CullMode.Back, fill: FillMode.Solid)); //Default texture sampling settings diffuseSampler = device.CreateSamplerState(new SamplerDesc( addressU: TextureAddressMode.Wrap, addressV: TextureAddressMode.Wrap, filter: Filter.MinPointMagMipLinear)); //Load the textures diffuseTexture = device.CreateTexture2DFromFile("Textures/Earth_Diffuse.dds"); nightTexture = device.CreateTexture2DFromFile("Textures/Earth_Night.dds"); normalMapTexture = device.CreateTexture2DFromFile("Textures/Earth_NormalMap.dds"); reflectionMask = device.CreateTexture2DFromFile("Textures/Earth_ReflectionMask.dds"); //Create transformation matrices world = Matrix.Identity; view = Matrix.LookAt(cameraPosition, new Vector3(0, 0, 1), Vector3.UnitY); projection = Matrix.PerspectiveFovLh((float)Width / (float)Height, Igneel.Numerics.PIover6, 1, 1000); CreateSphere(); }