+ Gaming World Forums > Creativity > Coding
+ Direct3D and C# - Displaying a 2D image
GWRadio
Username: Password: Duration:
 
Topic: Direct3D and C# - Displaying a 2D image  (Read 1350 times)
Print
the bloddy ghost #1 October 19, 2009, 01:25:17 pm
*******
Group: Premium member
Posts: 5536
Joined: March 25, 2003
 
How would I go about displaying a 2D picture in C# using Direct3D? I'm trying to figure this out, but I haven't been able to. All the tutorials I could find about Direct3D and C# haven't been very helpful.
__________________
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
   
Tomatoes and Radiowire pm
Remove These Ads And More
A one time payment of $15 removes ads, and gets you premium membership features. Learn more!
JohnnyCasil #2 October 19, 2009, 01:58:09 pm

*****
Group: Premium member
Posts: 2134
Joined: January 05, 2005
 
Unless there is some reason you have to use Direct3D in C#, I would say your first step is to not use that.  C#'s Direct3D bindings have been deprecated and are no longer updated.  If I were you, I would look into using XNA.  In XNA it is incredibly simple to render a 2D picture to the screen by using the SpriteBatch class.

If you cannot use XNA, you need to look at the Sprite class.
Sprite
   
Send E-Mail pm
Mince Wobley #3 October 19, 2009, 04:12:58 pm

I'm a walking time bomb killing everyone
*******
Group: Member
Posts: 4532
Joined: November 05, 2006
 
Back in my day there was a d3d extension called d3dx which allowed you to draw images with ID3DXSprite

Just do what he said
__________________
Play Raimond Ex (if you haven't already)


I'll not TAKE ANYTHING you write like this seriously because it looks dumb
   
pm
the bloddy ghost #4 October 19, 2009, 07:41:23 pm
*******
Group: Premium member
Posts: 5536
Joined: March 25, 2003
 
Yeah XNA looks like a much better alternative. Thank you.
__________________
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
   
Tomatoes and Radiowire pm
the bloddy ghost #5 October 19, 2009, 11:43:50 pm
*******
Group: Premium member
Posts: 5536
Joined: March 25, 2003
 
Okay, I'm having another problem with this.

I want to have a class that draws tiles to the screen during its Render function. The classes name is Room.

        public void Render() {
            sbatch.Begin();
            sbatch.Draw(wall, new Vector2(20, 20), Color.White);
            sbatch.End();
        }
something like that.

How can I get this to work in the main gameloop? I haven't been able to figure out a solution to this. What do I need to make sure I have in order to draw from an outside class?
__________________
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
   
Tomatoes and Radiowire pm
JohnnyCasil #6 October 20, 2009, 05:24:31 pm

*****
Group: Premium member
Posts: 2134
Joined: January 05, 2005
 
You need to show more of what you done, the snippet you provided really means nothing without any context.

In XNA, you have your class that derives from Game.  This class has a Draw method where all your rendering should occur.  The simplest thing is to make your Room class's Render method take an argument of SpriteBatch and then call that Render method in the game's Draw method passing in the Game's sprite batch.
   
Send E-Mail pm
the bloddy ghost #7 October 22, 2009, 01:39:20 am
*******
Group: Premium member
Posts: 5536
Joined: March 25, 2003
 
Okay, so I figured out the video problem and am pretty close to getting done with a simple map editor. The problem I am having now is saving data. How do I go about writing and reading a binary file? I tried reading a tutorial but I don't think it explained the reading portion too well. The StorageContainerMethod, which is what I initially wanted to use, apparently only applies to the XBOX 360.
__________________
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
   
Tomatoes and Radiowire pm
JohnnyCasil #8 October 22, 2009, 10:09:37 pm

*****
Group: Premium member
Posts: 2134
Joined: January 05, 2005
 
Well, it depends on what you want to do.  If you are just makin a map editor, chances are you don't need to worry about StorageContainers because you aren't ever going to deploy a stand alone map editor to the 360.  In that case, you can use any of the .Net classes that deal with writing files.  Keep in mind though that StorageContainer is not 360 only.  StorageContainers are what you want to use for your game to save your data if you want it to behave the same on Windows and the 360.

However, XNA uses the content pipeline to load its data.  This means you need to write a content pipeline extension to handle your data format.  There are plenty of guides out there to get you started, but be warned this can get complex pretty quickly.
   
Send E-Mail pm
Mince Wobley #9 October 22, 2009, 10:39:08 pm

I'm a walking time bomb killing everyone
*******
Group: Member
Posts: 4532
Joined: November 05, 2006
 
Just a dumb question, how do you serialize in XNA? Is there an easy/fast way?
__________________
Play Raimond Ex (if you haven't already)


I'll not TAKE ANYTHING you write like this seriously because it looks dumb
   
pm
JohnnyCasil #10 October 22, 2009, 11:29:09 pm

*****
Group: Premium member
Posts: 2134
Joined: January 05, 2005
 
There are no ways that are both easy and fast.  XNA comes with a IntermediateSerializer which will serialize into an XML content file.  That is a very easy method.  However, it is very SLOW.  Like I said above, you always have access to the .Net framework on Windows and the Compact Framework on the 360, so you can use any of the classes on those.  It really depends on what you want to do.  I personally use a combination of XML content files and binaries files.
   
Send E-Mail pm
the bloddy ghost #11 October 25, 2009, 04:22:10 pm
*******
Group: Premium member
Posts: 5536
Joined: March 25, 2003
 
Okay, so I have a basic entity class that has two functions, Update and Render(). I know that there is a way to override them from other classes that inherit the properties of the Entity class. For example, I want to have a MonsterEntity: Entity that does monster related stuff in its Update() section, and I want to have a HeroEntity: Entity be controlled by the keyboard in its Update() section. I then want to be able to have an Entity Manager be able to Update and Render all of them from a list. So what is the proper way to go about this?
__________________
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
   
Tomatoes and Radiowire pm
JohnnyCasil #12 October 25, 2009, 05:30:57 pm

*****
Group: Premium member
Posts: 2134
Joined: January 05, 2005
 
What specifically are you having trouble with?  There is really no "proper" way to handle entities in a game, that is why almost every game handles them in a different way.  Without you posting specifically what is giving you issues there is no way for us to tell you the proper way to handle it in your game.

Without knowing what your specific needs are, I'll give you my general advice.  I would ditch the whole entity inheritance tree.  For simple games you may be fine, but for anything slightly complex you will run into the typical problems associated with entity inheritance trees.  You should favor composition over inheritance anyways.  Entities are really just composed of different properties and behaviors.

This isn't my favorite article on the subject, but it is still a good introductory one: Evolve your heirachy
   
Send E-Mail pm
the bloddy ghost #13 November 06, 2009, 11:58:12 am
*******
Group: Premium member
Posts: 5536
Joined: March 25, 2003
 
That article helped me out a lot.

I had another question though, how would I make a text input prompt in XNA using the keyboard?
__________________
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
   
Tomatoes and Radiowire pm
MagicBob #14 November 22, 2009, 06:04:08 pm

The cat does not see the cliff.
**
Group: Member
Posts: 137
Joined: November 05, 2005
 
That article helped me out a lot.

I had another question though, how would I make a text input prompt in XNA using the keyboard?

XNA doesn't actually have anything built in that can get keyboard input so you'll have to make it yourself. Unfortunately, since KeyboardState.GetPressedKeys only returns the keys which were down during the time it was updated, you may need to need use another API like P/Invoke or WinForms to get more accurate input.  These links should help:
http://www.gamedev.net/community/forums/topic.asp?topic_id=457783 (GameDev discussion on this.)
http://forums.xna.com/forums/p/10136/56014.aspx (An example using mostly WinForms, and one P/Invoke call to TranslateMessage. Leidegre explains the problem with input pretty well.)
http://forums.xna.com/forums/p/7440/155133.aspx (An example using only XNA. Look for the last post by Binary Darkness.)

Alternately, I believe you can use the Guide class to pop up a 360-like on-screen keyboard in your game. (http://forums.xna.com/forums/t/18272.aspx)
   
Send E-Mail pm
harrisandreson #15 June 01, 2010, 05:17:09 am
*
Group: Member
Posts: 8
Joined: April 02, 2010
 
hello to all Yeah, essentially... I have to admit I haven't tried it, but you can't get PIX to generate an overdraw of the image, can you? deep pixel analysis yes, but not shader complexity and so on..?image hosting
The idea came from this thread. It'd be pretty awesome if you could somehow display the number of managed hosting pixel shader arithmetic or texture instruction count per-pixel. Could make for a great performance debugging tool - the brighter the colours the more fill-rate related work you're doing etc... linux hosting
Then again, hacking that in via hooking stands as much chance of breaking things as it does working frontpage hosting
Oh, and the obvious advantage is that it'd be overlayed - giving immediate feedback rather than the capture full stream then analyse the data.
   
Send E-Mail pm
 

« Previous Thread | Return to Forum | Next Thread »
Currently active: 0 members and 1 guests are viewing this topic
0 Members
Jump to:  

Gaming World Forums | Powered by SMF 1.0.6.
© 2001-2005, Modification by leafo & ramirez. All Rights Reserved.

Page created in 0.251 seconds with 22 queries.