Click here to Skip to main content
15,908,274 members
Home / Discussions / Graphics
   

Graphics

 
AnswerRe: HELPP please. Pin
Tim Craig24-Jul-08 14:46
Tim Craig24-Jul-08 14:46 
GeneralRe: HELPP please. Pin
chasoknight24-Jul-08 15:00
chasoknight24-Jul-08 15:00 
GeneralRe: HELPP please. Pin
Tim Craig24-Jul-08 15:31
Tim Craig24-Jul-08 15:31 
AnswerRe: HELPP please. Pin
Mark Salsbery25-Jul-08 6:59
Mark Salsbery25-Jul-08 6:59 
AnswerRe: HELPP please. Pin
Paul Conrad26-Jul-08 18:06
professionalPaul Conrad26-Jul-08 18:06 
QuestionRay Tracing question Pin
Member 433828023-Jul-08 11:14
Member 433828023-Jul-08 11:14 
QuestionWorking with 2D in DirectX using C# (Newest version as of 07/22/2008) ??? Pin
Thrash50522-Jul-08 16:00
Thrash50522-Jul-08 16:00 
AnswerRe: Working with 2D in DirectX using C# (Newest version as of 07/22/2008) ??? Pin
Thrash50523-Jul-08 20:26
Thrash50523-Jul-08 20:26 
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 {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [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 {
    // *********************************************************************************************
    // ***** 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

        // *****************************************************************************************
        // GameForm - Constructors
        // *****************************************************************************************
        #region GameForm - Constructors
        public GameForm( ) {
            InitializeComponent( );
            InitializeGraphics( );
        }
        #endregion

        // *****************************************************************************************
        // GameForm - Methods
        // *****************************************************************************************
        #region GameForm - Methods
        private void InitializeGraphics( ) {
            PresentParameters presentParameters = new PresentParameters( );
            Format currentFormat = Manager.Adapters[ 0 ].CurrentDisplayMode.Format;

            presentParameters.SwapEffect = SwapEffect.Discard;

            if( Manager.CheckDeviceType( 0, DeviceType.Hardware, currentFormat, currentFormat,
                false ) ) {
                presentParameters.Windowed = true;
                presentParameters.BackBufferFormat = currentFormat;
                presentParameters.BackBufferCount = 1;
                presentParameters.BackBufferWidth = ScreenWidth;
                presentParameters.BackBufferHeight = ScreenHeight;
            } else {
                presentParameters.Windowed = true;
            }
            GraphicsDevice = new Device( 0, DeviceType.Hardware, this,
                CreateFlags.SoftwareVertexProcessing, presentParameters );

            SpriteManager = new Sprite( GraphicsDevice );
            gs = new GraphicsSprite( new Vector3( 0f, 0f, 1f ),
                TextureLoader.FromFile( GraphicsDevice, @"C:\music_player.png" ) );
        }

        public void RenderGraphics( ) {
            _spriteManager.Begin( SpriteFlags.AlphaBlend );
            gs.Draw( SpriteManager );
            _spriteManager.End( );
        }

        // *****************************************************************************************
        // GameForm - Event Handlers
        // *****************************************************************************************
        private void GameForm_KeyUp( object sender, KeyEventArgs e ) {
            if( e.KeyCode == Keys.Escape )
                this.Close( );
        }
        #endregion
    }
    #endregion
}


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

// *************************************************************************************************
// ***** Using Directives
// *************************************************************************************************
#region Using Directives
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion

namespace _2D_DirectX9_Test {
    // *********************************************************************************************
    // ***** GraphicsSprite Class
    // *********************************************************************************************
    #region GraphicsSprite Class
    public class GraphicsSprite {
        // *****************************************************************************************
        // GraphicsSprite - Attributes
        // *****************************************************************************************
        #region GraphicsSprite - Attributes
        private Vector3 _center;
        private Vector3 _position;
        private Rectangle _sourceRectangle;
        private Texture _texture;
        #endregion

        // *****************************************************************************************
        // GraphicsSprite - Properties
        // *****************************************************************************************
        #region GraphicsSprite - Properties
        public Vector3 Center {
            get { return _center; }
            set { _center = value; }
        }
        public Vector3 Position {
            get { return _position; }
            set { _position = value; }
        }
        public Rectangle SourceRectangle {
            get { return _sourceRectangle; }
            set { _sourceRectangle = value; }
        }
        public Texture Texture {
            get { return _texture; }
            set { _texture = value; }
        }
        #endregion

        // *****************************************************************************************
        // GraphicsSprite - Constrcutors
        // *****************************************************************************************
        #region GraphicsSprite - Constructors
        public GraphicsSprite( Vector3 position ) {
            Center = new Vector3( 0, 0, 0 );
            Position = position;
        }
        public GraphicsSprite( Vector3 center, Vector3 position ) {
            Center = center;
            Position = position;
        }
        public GraphicsSprite( Vector3 center, Vector3 position, Texture texture ) {
            SurfaceDescription surfaceDescription;
            Center = center;
            Position = position;
            Texture = texture;
            surfaceDescription = Texture.GetSurfaceLevel( 0 ).Description;
            SourceRectangle = new Rectangle( 0, 0, surfaceDescription.Width,
                surfaceDescription.Height );
        }
        public GraphicsSprite( Vector3 position, Texture texture ) {
            SurfaceDescription surfaceDescription;
            Center = new Vector3( 0, 0, 0 );
            Position = position;
            Texture = texture;
            surfaceDescription = Texture.GetSurfaceLevel( 0 ).Description;
            SourceRectangle = new Rectangle( 0, 0, surfaceDescription.Width,
                surfaceDescription.Height );
        }
        #endregion

        // *****************************************************************************************
        // GraphicsSprite - Methods
        // *****************************************************************************************
        #region GraphicsSprite - Methods
        public void Draw( Sprite spriteManager ) {
            spriteManager.Draw( Texture, SourceRectangle, Center, Position, Color.White );
        }
        #endregion
    #endregion
    }
}


Thanks again to anyone who can help me.
GeneralRe: Working with 2D in DirectX using C# (Newest version as of 07/22/2008) ??? Pin
Thrash50525-Sep-08 11:56
Thrash50525-Sep-08 11:56 
QuestionBitmap from a Graphics object ? Pin
david davies21-Jul-08 2:06
david davies21-Jul-08 2:06 
AnswerRe: Bitmap from a Graphics object ? Pin
Luc Pattyn21-Jul-08 3:00
sitebuilderLuc Pattyn21-Jul-08 3:00 
QuestionDirectX installation. Pin
Ranger4919-Jul-08 17:22
Ranger4919-Jul-08 17:22 
AnswerRe: DirectX installation. Pin
Ranger4919-Jul-08 22:56
Ranger4919-Jul-08 22:56 
GeneralGraphics Help Plz -Urgent! [modified] Pin
Brady Kelly17-Jul-08 22:58
Brady Kelly17-Jul-08 22:58 
GeneralRe: Graphics Help Plz -Urgent! Pin
Graham Bradshaw17-Jul-08 23:02
Graham Bradshaw17-Jul-08 23:02 
GeneralRe: Graphics Help Plz -Urgent! Pin
Brady Kelly17-Jul-08 23:17
Brady Kelly17-Jul-08 23:17 
GeneralRe: Graphics Help Plz -Urgent! Pin
Simon P Stevens17-Jul-08 23:26
Simon P Stevens17-Jul-08 23:26 
GeneralRe: Graphics Help Plz -Urgent! Pin
peterchen17-Jul-08 23:40
peterchen17-Jul-08 23:40 
GeneralRe: Graphics Help Plz -Urgent! Pin
TommyTomToms18-Jul-08 0:07
TommyTomToms18-Jul-08 0:07 
QuestionMap Projection Pin
aadilali17-Jul-08 19:18
aadilali17-Jul-08 19:18 
AnswerRe: Map Projection Pin
El Corazon18-Jul-08 9:17
El Corazon18-Jul-08 9:17 
GeneralRe: Map Projection Pin
aadilali19-Jul-08 0:58
aadilali19-Jul-08 0:58 
GeneralRe: Map Projection Pin
El Corazon19-Jul-08 5:53
El Corazon19-Jul-08 5:53 
Questiondrawing a 3d circle in Directx Pin
Md. Ali Naser Khan16-Jul-08 21:21
Md. Ali Naser Khan16-Jul-08 21:21 
AnswerRe: drawing a 3d circle in Directx Pin
Shog917-Jul-08 12:44
sitebuilderShog917-Jul-08 12:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.