Jump to content
  • Advertisement
Sign in to follow this  

An error creating a SlimDX Device ( Direct3D9

This topic is 2800 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

I have a need to create a 2d texture-rendering control for visual studio to work on windows XP/7.
For this job I picked SlimDX/Direct3D9 with sprites.

The code for the control:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SlimDX;
using SlimDX.Direct3D9;
using SlimDX.Windows;
using Device = SlimDX.Direct3D9.Device;
using Resource = SlimDX.Direct3D9.Resource;
using Sprite = SlimDX.Direct3D9.Sprite;
namespace SlimDXClass
public partial class SlimDXControl : Panel
Device device;
Texture texture;
Sprite sprite;
SlimDX.Vector3 center;
public SlimDXControl( Form mainForm )
device = new Device(new Direct3D(), 0, DeviceType.Hardware, mainForm.Handle, CreateFlags.None, new PresentParameters() {
BackBufferWidth = 1024, BackBufferHeight = 768
texture = Texture.FromFile(device,"C:\\badass\\texture.png");
SurfaceDescription surfaceDescription = texture.GetLevelDescription(0);
center = new SlimDX.Vector3(surfaceDescription.Width, surfaceDescription.Height, 0) * 0.5f;
sprite = new Sprite(device);
// Start rendering process
MessagePump.Run(mainForm, RenderFrame);
// clean up all resources
// anything we missed will show up in the debug output
private void RenderFrame()
// clear the render target to a soothing blue
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.5f, 0.5f, 1.0f),1.0f,0);
SlimDX.Color4 color = new SlimDX.Color4(Color.White);
sprite.Draw(texture, center, new Vector3(0, 0, 0), color);

Whenever the Device creation code is reached , I get some cryptic DirectX error ...

What did I do wrong ? is that the right way to embed a directX based control ?

Share this post

Link to post
Share on other sites
Never mind the previous question I solved it ( I should have given the handle to the control - this - and not to the parent form )

Another problem though : nothing is being draws.
I checked and the render loop is being initiated - what else do I need to do for the render results to appear on-screen?

SlimDXControl ctrl = new SlimDXControl(this);
ctrl.Location = new Point(0,0);
ctrl.Size = new Size(600,600);

Doesn't draw a thing .. Blank window
Doesn't work

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!