Jump to content

  • Log In with Google      Sign In   
  • Create Account

Please help me get started


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 28 July 2013 - 09:23 AM

Hi, I'm hoping some of the experts on this site can help me get started by providing me some information and perhaps some detailed guidance.

I need to create a simple (or so I thought) graphics application to move a circle on the screen, and have it bounce off the sides of the screen.

Previously I had done this with VB6 and Directx7. There were ample examples on line to carry this out.

 

Fast forward to 2013 and I'm finding it hard to do this.

 

To start off with I'd like to do this via C# using Visual Studio (2010 express).

It also needs to run on Windows XP - Windows 8, but also be designed to run on the next releases of the Windows OSs.

The movement of the circle (ball) needs to be very smooth. I also need to increase the speed of the ball as well from 1x to 3x.

 

I was hoping I could pull off a simple thing such as this within a Windows Presentation Foundation application, but I found (via various trials using different techniques) that I could not pull off a smooth animation on various systems. For instance I was not able to get the ball moving at a constant frame rate. As well, with CPU spikes this would lead to some choppiness. This would have been ideal because I would not have to directly use DirectX and ideally this would be portable to all windows operating systems.

 

I then started to look at using C# with DirectX. I read up on XNA but it seems like support for this is ending in the near future. As well, it uses directx9. As well, XP only supports up to directx9c, so now I am looking at questions such as, do I work with directx9c for programming this for all Windows operating systems, or do I look at designing a version with directx9 for XP and a version using DirectX11 for the other operating systems. With that in mind I've started to look into SharpDX.

 

Could you guys please help me with the below questions first:

 

Question:

is there anyway to get smooth animations with WPF with regards to what I'm trying to do. I just can't seem to get this to a level where it

is satisfactory.

 

Question:

Should I use XNA, or should I stay away from it. I'm concerned that the work I'd do with it will lead to some troubles in the future.

                

Question:

If I use DirectX, because directx9c is the latest version to work with XP, is it safe to use directx9 and have this run on other windows OSs and various graphics cards, or do I need to also write the program using directx 11 as well. Although I believe direct9 would get me running fine now, I'm wondering what will happen in the years to come.

 

Question:

Do you have experience with SharpDX and is this the way to go if I want to use DirectX with C#.

 

Question:

Will DirectX 9 continue to be actively supported by graphics cards in the next 3-5 years.

 

 

Can I please get your help.

 

Thanks.

 

 

 



Sponsor:

#2 Solid_Spy   Members   -  Reputation: 420

Like
0Likes
Like

Posted 28 July 2013 - 11:23 AM

I would recommend that you look into Directx11 or Opengl 4.0, since those are becomming popular.



#3 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 28 July 2013 - 11:42 AM

Hi Solid spy, did you get a chance to look over some of my questions? How does your comment relate to them?

For instance how do I design this for XP if I use DirectX 11?

 

I'm looking for someone to really help me out here with guidance.



#4 Solid_Spy   Members   -  Reputation: 420

Like
0Likes
Like

Posted 28 July 2013 - 12:00 PM

Hi Solid spy, did you get a chance to look over some of my questions? How does your comment relate to them?

For instance how do I design this for XP if I use DirectX 11?

 

I'm looking for someone to really help me out here with guidance.

 

Directx 11 doesn't work on Windows XP, however not a lot of people will have XP's in the future. I would stay away from xna since it's very outdated, it works, but the knowledge won't help you much.

 

As for wpf? I would avoid it if you want to make multiplatform games since there seems to be no multi-platform support, i would use windows forms.


Edited by Solid_Spy, 02 August 2013 - 11:09 PM.


#5 SimonForsman   Crossbones+   -  Reputation: 6112

Like
1Likes
Like

Posted 28 July 2013 - 12:07 PM

DX9 and XNA will most likely continue to work for a very long time, Microsoft is fairly good at keeping things backwards compatible so you shouldn't be that worried about their lack of official support (it basically just means that Microsoft won't release any more updates for them to fix bugs or add features).

 

Personally i would recommend going with OpenGL though since that lets you use whatever features your GPU supports regardless of what OS you're using. nvidia has OpenGL 4.4 (roughly equivalent to D3D11.2) drivers for Windows XP.


I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#6 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 28 July 2013 - 12:11 PM

Hi, regarding DX9 and XNA, what about the graphics cards supporting directx9?



#7 SimonForsman   Crossbones+   -  Reputation: 6112

Like
0Likes
Like

Posted 28 July 2013 - 12:14 PM

Hi, regarding DX9 and XNA, what about the graphics cards supporting directx9?

 

What about them ? , If the graphics card supports DX9 then it supports DX9.


I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#8 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 28 July 2013 - 12:20 PM

 

Hi, regarding DX9 and XNA, what about the graphics cards supporting directx9?

 

What about them ? , If the graphics card supports DX9 then it supports DX9.

 

Can you do me a favour and answer the questions I posed in my original post. It will help me out. Thanks.



#9 SimonForsman   Crossbones+   -  Reputation: 6112

Like
1Likes
Like

Posted 28 July 2013 - 02:32 PM

 

 

Hi, regarding DX9 and XNA, what about the graphics cards supporting directx9?

 

What about them ? , If the graphics card supports DX9 then it supports DX9.

 

Can you do me a favour and answer the questions I posed in my original post. It will help me out. Thanks.

 

 

1) No idea, WPF isn't really intended for games so it might be tricky.

2) You can use XNA as long as you don't need newer GPU features. (XNA is no longer updated but will continue to work for a very long time, it is the only way for a hobbyist to make games for the xbox360, if you're on XP the only alternative if you want to take full advantage of modern hardware is OpenGL)

3) Yes its safe to use DX9, its basically in the same position as XNA, it works on all current hardware and Windows versions and will most likely work on future windows versions and future hardware as well. (Noone in their right mind will break backwards compatibility with thousands of games).

4) SharpDX is fine if you want to use DirectX with .Net (But if you're only going to use DX9 anyway you might as well stick with XNA, its easier to work with)

5) Yes. (DirectX1.0 is still supported by most GPU drivers so it would be quite strange if DX9 suddenly got dropped completely)


I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#10 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 28 July 2013 - 04:15 PM

Thank you Simon!



#11 Gavin Williams   Members   -  Reputation: 664

Like
2Likes
Like

Posted 28 July 2013 - 10:24 PM

Hi GDR.

 

Can i straighten out one point first, WPF can create smooth and continuous motion, no worries. And if all you are creating is a desktop application with not too complex graphics then WPF is perfect for you needs. I can provide you with a small WPF application that generates circles and allows you to drag and throw them around and does collision detection between the objects, although I didn't bother doing wall detection at the time but that's easy, and there are a couple of buttons in the app that don't work. It will certainly show you how to use a continuous time 'heartbeat' to create smooth motion/animation.

 

It sounds to me as though WPF would be more suitable to your needs.

 

Write an email to gavin_w3@yahoo.com.au with GDR in the subject line and I'll fix you up with the solution. Unfortunately when I checked it, it was updated to VS11 so you'll probably need to manually build it again.

 

I am personally using SharpDX at the moment with DirectX 11.1, I have also used SlimDX and XNA in the past. I would not recommend XNA, nor DirectX 9. Those technologies are in support mode and the newer DirectX versions have more features and are more future proof. There is very little reason to use those older technologies when DX 11 is widely available. You have to ask yourself why you need Direct X 9 support and why you would want to use that rather than a more fully featured and more modern library. Why are you considering XP support ? No one has XP anymore. Even if one or two people can pipe up and say 'I use XP' ... it's irrelevant. Just my 2c.



#12 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 29 July 2013 - 03:04 PM

Hi GDR.

 

Can i straighten out one point first, WPF can create smooth and continuous motion, no worries. And if all you are creating is a desktop application with not too complex graphics then WPF is perfect for you needs. I can provide you with a small WPF application that generates circles and allows you to drag and throw them around and does collision detection between the objects, although I didn't bother doing wall detection at the time but that's easy, and there are a couple of buttons in the app that don't work. It will certainly show you how to use a continuous time 'heartbeat' to create smooth motion/animation.

 

It sounds to me as though WPF would be more suitable to your needs.

 

Write an email to gavin_w3@yahoo.com.au with GDR in the subject line and I'll fix you up with the solution. Unfortunately when I checked it, it was updated to VS11 so you'll probably need to manually build it again.

 

I am personally using SharpDX at the moment with DirectX 11.1, I have also used SlimDX and XNA in the past. I would not recommend XNA, nor DirectX 9. Those technologies are in support mode and the newer DirectX versions have more features and are more future proof. There is very little reason to use those older technologies when DX 11 is widely available. You have to ask yourself why you need Direct X 9 support and why you would want to use that rather than a more fully featured and more modern library. Why are you considering XP support ? No one has XP anymore. Even if one or two people can pipe up and say 'I use XP' ... it's irrelevant. Just my 2c.

Hi Gavin thanks for your input. I'll have to look at the XP requirement again, but if I do need to program this for XP and it would be great to do that, then I would need directx9

and therefore, the question is, do I just use directx9 and use that for Vista, ... Windows 8.

 

But, with regards to WPF this would be very ideal. I've tried and tried and I've had trouble creating a smooth animation that I would get from DirectX. With CPU spikes, to slight frame rate changes, it just didn't work for me. I'll email you. Thanks.



#13 Gavin Williams   Members   -  Reputation: 664

Like
1Likes
Like

Posted 29 July 2013 - 10:33 PM

Hi GDR,

 

I've sent through the solution, I've included a few details in the email, and removed a couple of things from the project that would cause a crash. If you have any question, just put them up here, as I don't check my email that often.

 

In regards to smooth animation and smooth frame-rate. It's almost impossible to get a consistent frame-rate, so the best strategy is to accept that every frame is going to last a different amount of time and write your physics to accommodate different frame times. As you'll see in my solution I use inter-op in the Clock class to access the performance counter. This gives me the highest accuracy reading of elapsed time over the frame. This is not the only way to measure frame-time but it's the way i do it. I then use that time to scale the velocity. So a short frame will result in a shorter movement over the frame while a longer frame will result in greater movement. So over many frames, you're objects do move smoothly.

 

Gavin



#14 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 30 July 2013 - 06:31 AM

Thanks GRD. I'll try it out tonight and let you know.



#15 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 30 July 2013 - 05:52 PM

Hi Gavin, thanks very much for the code you provided. Its really helpful when I can compile something and see it first hand and then go through the code to start getting a better understanding. Thanks for taking the time to provide this for me and tweak it to compile right off the bat without any mods on my end.

 

I can tell you are a really talented programmer. I can see from your profile you are taking software Engineering. I had done that as well. I kind of drifted out

of the practice after graduation, so thanks again for helping me to get a jump start with your help as I'm rusty.

 

Just from a quick glance of the code (I'll spend more time later this week going through it) if I'm correct (forgive my inaccuracies or lack of experience), just to re-iterate what you had said, and what I see in your code, you used CompositionTarget.Rendering to create the loop and then within  "CompostionTarget_Rendering" you call your function

"HeartBeat" to add the logic to provide the smoother motion. As well I did see the use of QueryPerformanceCounter which you mention in your post above.

 

I tried it out on 2 windows 7 systems (a laptop that was previously a Windows XP system, upgraded to a Windows 7) and a native Windows 7 PC. It look good when I tried various speeds when dragging the circle.

 

We had discussed Windows XP and the question regarding why I'm using it. The reason is I've been asked to support it and I want to try my best to follow through with this.

When I ran it on a Windows XP laptop and a desktop I noticed tearing (I believe that's the term for it) with the circle, more predominant at greater speeds. I know from some experience with DirectX (sad to say my level of knowledge was with directx 7 so that shows my age) I could use the Vsync option in full screen . Do you know the back end details (under the hood) for why I see tearing in Windows XP. Have your tried your program on XP or are you able to do a quick test. As well, do you think this is something that can be minimized or solved or something that is the way it is?

 

Thanks again.



#16 Gavin Williams   Members   -  Reputation: 664

Like
0Likes
Like

Posted 31 July 2013 - 09:48 AM

I'm sorry, I haven't used XP for maybe 10 years, I would have thrown it away probably by now. But I would guess that XP is just too old and there maybe subtle compatibility issues. I am not an expert on using .net on old windows though. Make sure you have the most recent service pack on XP. And check what graphics card the computer has, it will need a decent graphics card to render wpf smoothly. I say this because well, if it's XP, maybe there are other things that haven't been updated as well such as graphics. Which could account for the tearing if it's a really old card. Apparently WPF uses direct x for rendering, though it might not perform as you'd expect because wpf is quite a beefy engine, and it does a lot of other stuff.

 

So..

1. Check graphics card - and try a better card if you can, perhaps updating the card will give you the performance you need.

2. Install latest service pack for XP


Edited by Gavin Williams, 31 July 2013 - 09:50 AM.


#17 GDR   Members   -  Reputation: 109

Like
0Likes
Like

Posted 31 July 2013 - 06:38 PM

Thanks Gavin. I'll check things out. Thanks for your help.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS