Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. Working with 2D in DirectX using C# (Newest version as of 07/22/2008) ???

Working with 2D in DirectX using C# (Newest version as of 07/22/2008) ???

Scheduled Pinned Locked Moved Graphics
tutorialalgorithmscsharpc++graphics
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thrash505
    wrote on last edited by
    #1

    Okay, here it goes... [My rant] I've been searching for weeks now on how to work with 2D images in DirectX using C#. However, I've been completely unsuccessful in doing so. The help files that come with DirectX are horrible because they are organized by classes and such. Meaning that a person like me who has never worked with DirectX before, will be completely lost. The help files should take you through DirectX in order of complexity, showing you the simplest things first, but they don't. They are more like a reference guide. But, anyways they are no help to DirectX newbies like me. I've looked around on the internet a lot trying to get some information on this topic and then attempting to piece it together. However, I've been completely unsuccessful. 90% of all examples are using out-dated versions of DirectX, meaning they are irrelevant to me. The other 10% are either in C++, which I do not understand. I've seen some rare occurrences of 2D DirectX projects in C#, but they are using older versions of C#, which didn't fully support DirectX and were workarounds (so they've said). When I try to convert them to the newest version of a C# solution they fail to compile. There is a sample that comes with DirectX that supposed to show you how to perform "Simple 2D". However, it actually not very simple and is a rather large project in my world. But, the killer is that it also fails to run on my computer, most likely because they are trying to use some advanced feature when its supposed to be "Simple 2D". I'm pretty sure my computer is capable of displaying some 2D images and then move them around a little. [/My rant] So that's enough of my complaining, I just wanted anyone who reads this thread to know that I did try to figure this out on my own before coming here. Basically what I'm asking for is for someone to either explain to me very simply how to get a basic 2D C# project using DirectX up and running or create one for me so I can pick it apart and try to figure out what's going on. I only want the simplest example. Like displaying some 2D images and maybe moving them around or rotating them. Nothing fancy. Many thanks in advance to anyone who can help me out. :)

    T 1 Reply Last reply
    0
    • T Thrash505

      Okay, here it goes... [My rant] I've been searching for weeks now on how to work with 2D images in DirectX using C#. However, I've been completely unsuccessful in doing so. The help files that come with DirectX are horrible because they are organized by classes and such. Meaning that a person like me who has never worked with DirectX before, will be completely lost. The help files should take you through DirectX in order of complexity, showing you the simplest things first, but they don't. They are more like a reference guide. But, anyways they are no help to DirectX newbies like me. I've looked around on the internet a lot trying to get some information on this topic and then attempting to piece it together. However, I've been completely unsuccessful. 90% of all examples are using out-dated versions of DirectX, meaning they are irrelevant to me. The other 10% are either in C++, which I do not understand. I've seen some rare occurrences of 2D DirectX projects in C#, but they are using older versions of C#, which didn't fully support DirectX and were workarounds (so they've said). When I try to convert them to the newest version of a C# solution they fail to compile. There is a sample that comes with DirectX that supposed to show you how to perform "Simple 2D". However, it actually not very simple and is a rather large project in my world. But, the killer is that it also fails to run on my computer, most likely because they are trying to use some advanced feature when its supposed to be "Simple 2D". I'm pretty sure my computer is capable of displaying some 2D images and then move them around a little. [/My rant] So that's enough of my complaining, I just wanted anyone who reads this thread to know that I did try to figure this out on my own before coming here. Basically what I'm asking for is for someone to either explain to me very simply how to get a basic 2D C# project using DirectX up and running or create one for me so I can pick it apart and try to figure out what's going on. I only want the simplest example. Like displaying some 2D images and maybe moving them around or rotating them. Nothing fancy. Many thanks in advance to anyone who can help me out. :)

      T Offline
      T Offline
      Thrash505
      wrote on last edited by
      #2

      I still need help on this topic, but to make it easier for someone to help me I put together a project myself. However, it should be working, but its not; The image never shows up on the form. Here's the link to the project files: http://www.freewebs.com/thrash505/2D\_DirectX9\_Test.zip Program.cs

      // *************************************************************************************************
      // ***** Project: 2D DirectX9 Test
      // ***** Author: Thrash505
      // ***** Created: 07/24/2008
      // *************************************************************************************************

      // *************************************************************************************************
      // ***** Using Directives
      // *************************************************************************************************
      #region Using Directives
      using System;
      using System.Windows.Forms;
      #endregion

      namespace _2D_DirectX9_Test {
      // *********************************************************************************************
      // ***** Program Class
      // *********************************************************************************************
      #region Program Class
      public static class Program {
      /// /// The main entry point for the application.
      ///
      [STAThread]
      public static void Main( ) {
      GameForm gameForm = new GameForm( );
      gameForm.Show( );
      while( gameForm.Created ) {
      gameForm.RenderGraphics( );
      Application.DoEvents( );
      }
      }
      }
      #endregion
      }

      GameForm.cs

      // *************************************************************************************************
      // ***** Project: 2D DirectX9 Test
      // ***** Author: Thrash505
      // ***** Created: 07/24/2008
      // *************************************************************************************************

      // *************************************************************************************************
      // ***** Using Directives
      // *************************************************************************************************
      #region Using Directives
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Drawing;
      using System.Windows.Forms;
      using Microsoft.DirectX;
      using Microsoft.DirectX.Direct3D;
      #endregion

      namespace _2D_DirectX9_Test {
      // ********************************

      T 1 Reply Last reply
      0
      • T Thrash505

        I still need help on this topic, but to make it easier for someone to help me I put together a project myself. However, it should be working, but its not; The image never shows up on the form. Here's the link to the project files: http://www.freewebs.com/thrash505/2D\_DirectX9\_Test.zip Program.cs

        // *************************************************************************************************
        // ***** Project: 2D DirectX9 Test
        // ***** Author: Thrash505
        // ***** Created: 07/24/2008
        // *************************************************************************************************

        // *************************************************************************************************
        // ***** Using Directives
        // *************************************************************************************************
        #region Using Directives
        using System;
        using System.Windows.Forms;
        #endregion

        namespace _2D_DirectX9_Test {
        // *********************************************************************************************
        // ***** Program Class
        // *********************************************************************************************
        #region Program Class
        public static class Program {
        /// /// The main entry point for the application.
        ///
        [STAThread]
        public static void Main( ) {
        GameForm gameForm = new GameForm( );
        gameForm.Show( );
        while( gameForm.Created ) {
        gameForm.RenderGraphics( );
        Application.DoEvents( );
        }
        }
        }
        #endregion
        }

        GameForm.cs

        // *************************************************************************************************
        // ***** Project: 2D DirectX9 Test
        // ***** Author: Thrash505
        // ***** Created: 07/24/2008
        // *************************************************************************************************

        // *************************************************************************************************
        // ***** Using Directives
        // *************************************************************************************************
        #region Using Directives
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Drawing;
        using System.Windows.Forms;
        using Microsoft.DirectX;
        using Microsoft.DirectX.Direct3D;
        #endregion

        namespace _2D_DirectX9_Test {
        // ********************************

        T Offline
        T Offline
        Thrash505
        wrote on last edited by
        #3

        I've finally figured out why my code wasn't working... I had to set the view transform and turn off lighting. Then I had to put in the BeginScene(), EndScene(), and Present() calls when rendering. Here's the new version of the GameForm.cs file:

        // *************************************************************************************************
        // ***** Project: 2D DirectX9 Test
        // ***** Author: Thrash505
        // ***** Created: 07/24/2008
        // *************************************************************************************************

        // *************************************************************************************************
        // ***** Using Directives
        // *************************************************************************************************
        #region Using Directives
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Drawing;
        using System.Windows.Forms;
        using Microsoft.DirectX;
        using Microsoft.DirectX.Direct3D;
        #endregion

        namespace _2D_DirectX9_Test {
        // *********************************************************************************************
        // ***** GameForm Class
        // *********************************************************************************************
        #region GameForm Class
        public partial class GameForm : Form {
        // *****************************************************************************************
        // GameForm - Attributes
        // *****************************************************************************************
        #region GameForm - Attributes
        private Device _graphicsDevice;
        private Sprite _spriteManager;
        private GraphicsSprite gs;
        #endregion

            // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
            // GameForm - Properties
            // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
            #region GameForm - Properties
            private Device GraphicsDevice {
                get { return \_graphicsDevice; }
                set { \_graphicsDevice = value; }
            }
            private int ScreenWidth {
                get { return 1024; }
            }
            private int ScreenHeight {
                get { return 768; }
            }
            public Sprite SpriteManager {
                get { return \_spriteManager; }
                set { \_spriteManager = value; }
            }
            #endregion
        
            // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups