Jump to content
  • Advertisement
Sign in to follow this  
crackers

Help with DirectX (c#)

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

Hi everybody, I'm just starting learning c# and DirectX but had a couple of problems. The first one is with creating the device with Direct3D, I get an error with the 3rd and 5th parameter when calling the Device constructor. The second one is with DirectInput, in this one I found a way around but I was wondering why it didnt worked the way it was in the tutorial, the error pops in the initialize method for the keyboard. Sorry if these problems had been brought before, I searched but couldn't find any topic with these problems, I also wasn't sure If this goes into begginers or DirectX, please move it if I posted it in the wrong place. Direct3D:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;


namespace WindowsApplication1 //A window showing a blue background
{
    public partial class Form1 : Form
    {
        Device Dx_Device = null;
        
        public Form1()
        {
            InitializeComponent();
            this.ClientSize= new Size(640, 480);
            this.Text= "Ventana";
        }
        //HERE
        public bool InitializeD3d() {
            try {
                
                PresentParameters pps = new PresentParameters();
                pps.IsWindowed = true;
                pps.SwapEffect = SwapEffect.Discard;


                //THIS IS WHERE I GET THE ERROR
                //It says that the 3rd and 5th arguments ain't from the type needed
                Dx_Device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pps);
                return true;
            }catch (DirectXException e){
                MessageBox.Show(e.ToString(),"error");
                return false;
        }
        }
        private void Render() {
            if (Dx_Device == null) {
                return;
            }
            Dx_Device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
            Dx_Device.BeginScene();
            Dx_Device.EndScene();
            Dx_Device.Present();

        }
        static void main() {
            Form1 form = new Form1();

            if (form.InitializeD3d() == false)
            {
                MessageBox.Show("No esta inicializado", "Error");
                return;
            }
            form.Show();
            while (form.Created)
            {
                form.Render();
                Application.DoEvents();
            }
        }
        
        
    }
}


Direct Input:
/// <summary>
		/// Initializes the keyboard device and sets necessary parameters.
		/// </summary>
		/// <param name="Owner">The control for which the input state should be captured.</param>
		public void Initialize(Control Owner)
		{
			// Query available keyboards (THIS IS WHERE I GET THE ERROR)


                        // It says that it can't find InputList, in other
                        //tutorials I found that they never use anything like this,
                        //so I was wondering if there was anything good
                        //for searching all the available keyboards

			InputList<DeviceInstance> instances = Manager.GetDevices(DeviceClass.Keyboard, 
				EnumDevicesFlags.AttachedOnly);

			if (instances.Count == 0)
			{
				throw new Exception("No keyboard found!");
			}

			// Create a new device with the keyboard guid
			keyboard = new Device(instances[0].Instance);
			
			// Set data format to keyboard data
			keyboard.SetDataFormat(DeviceDataFormat.Keyboard);

			// Set the cooperative level to background non-exclusive
			keyboard.SetCooperativeLevel(Owner.Handle, CooperativeLevelFlags.Background | 
				CooperativeLevelFlags.NonExclusive);

			// Try to access keyboard
			try
			{
				keyboard.Acquire();
			}
			catch (InputLostException)
			{
				bLost = true;
			}
		}



One Last thing, in the last tutorial I kept getting an error that said that a TimeBombException was unhandled, saying that that version of directX was expired, but I never got that error when I typed the tutorial myself, I was wondering why did that happened. Thanks in advance Crackers PS: Excuse My English, it isn't my first language.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by crackers
One Last thing, in the last tutorial I kept getting an error that said that a TimeBombException was unhandled, saying that that version of directX was expired, but I never got that error when I typed the tutorial myself, I was wondering why did that happened.


The tutorial was probably built against the Managed DirectX 2.0 beta, which expired last October.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!