Accessing Update(GameTime) when implementing Monogame in Winforms - c#

So I've been following this tutorial https://www.youtube.com/watch?v=g-JupOxwB-k on how to implement monogame within winforms. I've been successful by following the tutorial from scratch to finish. Sadly there is only one video in the tutorial series.
I've created a class that inherits from GraphicsDeviceControl in order to draw it on a windows form. Now, this works in the sense that I have implemented the control onto the form. But it only draws the thing once. I need to implement the GameTime in an Update(GameTime) somehow but I have no idea how as this entire crossover between winforms and monogame is difficult enough.
So many tutorials or posts have outdated links or are outdated and no longer applicable. I tried following this guide: https://blogs.msdn.microsoft.com/shawnhar/2010/12/06/when-winforms-met-game-loop/
But I just feel so stupid I can't get it to work. What is Tick? What is TargetElapsedTime.TotalMilliseconds? No code snippet on that page helps me.
TL;DR:
I want an Update(GameTime) and my Draw() to happen once per frame inside the xna control that I've added to the winform. How do I implement this behavior?

Related

How to use SlimDX inside a WPF C# application

i'm totally new to SlimDX and WPF, but i need to create a multiple images in my application and one of them need to be a 3d visualizator of a point render, something like this:
http://img600.imageshack.us/img600/5879/6a00d83452464869e2017ee.gif
I found i can use SlimDX to use DirectX by C# instruction in my application, writing the result in a D3DImage component.
After some tries i made visual studio 2012 to recoignize that D3DImage (for some reason i needed to restart windows to made it work) but i don't know a few things:
How i can initialize a DirectX window inside that D3DImage? I really can't find any example or source code. All the examples i can find (like the 3 litte examples on SlimDX) are out of the WPF context
Where i can find some good documentation about SlimDX? The GameDev community seems some kinda bugged and i can't post anything (maybe because i'm not paying) and i can't find anything anywhere! How i'm supposed to learn that?
Not a single one of the SlimDX examples from the SVN can compile. I always got some reference error with the SlimDX library (empty path) and even re-importing from the correct path doesn't solve it
This is driving my crazy D:
I feel your pain. I haven't be working to much with the D3D stuff in SlimDX for lack of a reason to do so, But I have been playing around with DirectSound and DirectInput, So i'll tell you what i've figured out.
First Bullet:
I'm not sure initializing a D3D Window inside of an image is going to work. If you're using Windows Forms as your base, SlimDX includes a RenderForm or some such thing that subclasses Windows.Forms, and provides a decent amount of functionality. I still haven't figured it out for WPF, even though there's supposed to be a sample for that.
Second Bullet: Documentation is difficult to come by. There's some stuff on the site, and some stuff here, but what's really been helpful is the MSDN Reference for DirectX. SlimDX Mirrors the structures pretty well, and you can find out a lot by reading it. It DOES take a bit of conversion, because the DirectX reference is C++.
Third Bullet: Same problem. Never was able to figure out why.
Hope that helps a bit.

How to make page flip effect in WPF?

All the info i found about page fliping is just source code that i'm having trouble implementing to my code.
this tutorial
kinda explains the logic behind page fliping but the code is for windows form and not WPF.
i dunno how to approach it because as i understood bitmaps are not used the same in WPF.
anyone has a good tutorial or could give me some pointers?
What im trying to do is i have an image that fills entire screen and i want to flip it to to next image ( like a book) that will also take the entire screen.
(Not 2 images on a screen)
Help?
To anybody that suggests using C++ or DirectX, I'm not interesting in learning those skills. Only C# code please.
The WPF bag o'tricks has a page flip sample with code.
The github source
https://github.com/thinkpixellab/bot
Specifically, look at the TransitionPresenter sample in the demo project where there are multiple transitions defined, one being page flipping.

WPF container that allows objects to move around

I worked a litte with WPF but it used copy-paste for XAML and mostly C# coding for the background logic. Now I want to start a project with a friend and use WPF because it will be a GUI intensive one.
Question:
In our app, we want to have a surface on which we can put objects and the user should be able to move the objects around. This should be 2D. By moving, I mean click on an object and drag it around inside the surface. In the end, I think the movement should be only in one direction ( only horizontal), but for the moment it should be possible to move them in any direction. The only restriction that should apply is that they can't remain one on top of the other.
Can you give me any hints on what container should we use for the surface, what base class should we use for the objects moving in the container? Or does WPF have something that works out of the box for this case? General hints how we should start this would be appreciated.
I know that this is a lot for some one that doesn't have so much experience with WPF but I did the same thing when I came from C++ to C# and it worked :).
Canvas is always a good container to move things around.
Have a look at this article on CodeProject:
WPF Diagram Designer: Part 1
It uses a Canvas to display items, and implements code to allow the items to be dragged around the Canvas.
This is a blogpost from version .NET 3.5
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/05/08/test-post-1.aspx
"Dragable" is a common case when discussing the topic of behavior in expression blend.

SlimDX viewports in WPF controls

I am transitioning from WinForms/XNA to WPF/SlimDX because:
a) all of the benefits of WPF over
WinForms (but learning curve = ouch!)
b) I would like to have multiple
SlimDX viewports attached to Panels.
XNA has 1 "game" screen.
c, last and least) DirectX 10 support
All of my previous XNA code is in C#. I am having trouble figuring out how to port this over to SlimDX and WPF on a high level. I have searched like crazy. The closest I have found are:
1) http://www.gamedev.net/community/forums/topic.asp?topic_id=507941
Many articles point to this discussion, however it is incomplete and I can't figure out the XAML, and I get device errors after attaching all of the _slimDXDevice and Window1 events that were left out.
2) http://www.codeproject.com/KB/WPF/D3DImage.aspx
This article assumes the user is porting C++. I am porting XNA code which is very close to MDX code.
If I could get to the point where I have a WPF form with a custom SlimDX driven viewport that was just a blue box, I could go from there. In XNA I rendered many separate RenderTargets and placed them all over the screen, now I want to attach them to controls. But first, just 1 blue box! :D
Any ideas? I feel that this is either simple or that there's some "cookie cutter" code that I'm missing. Greatly appreciated!
You can look at the sample now. It's just been checked in to our repository, so you'll need to use SVN to get it (or wait until we ship the Feb 2010 release):
http://code.google.com/p/slimdx/source/detail?r=1356
D3DImage is the class you want to use. Even though the codeproject tutorial is C++, it is very applicable to SlimDX and WPF.
All you have to do with your SlimDX, is run your code normally, but DO NOT run a Present(...) on your device or swap chain. At the point where you would put a Present(...), do a D3DImage.SetBackBuffer(...) and send your SlimDX surface's ComPointer property to it. Then do D3DImage.AddDirect(...) and you now have D3D composited in WPF.
Also, make sure you create a IDirect3DDevice9Ex or else your performance will be terrible in anything but XP!
I recently was messing around with D3DImage and SlimDX and didn't find it too difficult to get it working (with DirextX9). I have some code at my home pc that I'll post later, but it's pretty similar to the code in the links provided.
I was never able to get it working with a higher version of directx though. Jeremiah has a nice blog post about using a directx9 device as a link between directx 10/11/d2d and the D3DImage, but I couldn't get it working with Slimdx. I didn't put a whole lot of effort into though as directx9 did what I needed it to do and I kind of wanted it to work on XP.

C#/.NET: Creating Dynamic Visuals in C#

NOTE: I am not exactly sure how to title or tag this question, so if you have any ideas, PLEASE help!
I'm currently envisioning a few possible projects that involve dynamically rendering something (whether it is a point, a line, text, or music notes on a staff, for hypothetical example), but, if I were to undertake these projects, I'm not really sure how to approach this design. What I'm curious about is sort of how programs like Word, or Geometer's Sketchpad, or Finale, create a blank "canvas" and render text, geometry, or music on it, respectively - how can this be done in C#, or in .NET, in general?
First of all, what is the best framework/platform to use: WinForms, WPF, something else? I'm open to many options, as I'm just trying to understand the different ways this can be done.
Next, how can I create such a "canvas" (if we go back to that metaphor) using the different frameworks you answered for part 1? And also, how can I render stuff onto it?
I hope my question isn't too confusing or n00bie. I just don't know how to approach such a prospect. Thanks!
UPDATE: I have now posted a follow-up question which is less broad. I have provided an hypothetical example of what I would like to accomplish. However, I will still accept an answer here, even though my question isn't fully answered.
WPF would probably suit your project well. I like the book Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, it covers most of the topics you're asking about.
You'll probably get better answers with a more focused question. The scope of your question is too large to be answered easily or concisely.
WPF makes it easier to refactor designs for such a project by easily moving shape drawing code between just drawing simple shapes and contents of controls. If you need the richness of custom controls, WPF allows a fairly smooth transition.
Most of the graphics can be defined in XAML which means you can export them from programs like Illustrator or anything that generates the standard SVG vector graphics, via an SVG-XAML converter.
I like WPF Unleashed and it has a nice discussion of 2D graphics and how to use the DrawingContext class for such a visual editor.
Do you know that there's an event called Paint? Everytime Windows OS needs to displays or repaint something on your form, this event is triggered. So, you create a Paint event handler, and everything is possible in that. For eg:
Word: you have a WordDocument data structure with the formatted tags and stuffs, you paint each character/ each word or each block of words one-by-one using a desired brush/paint and font. You might also wanna paint your background and stuff... If, for example the user change the font of 1 particular block, your WordDocument must change something to reflect that font change. And then you do an myForm.Invalidate() to repaint your form (and thus update your font). => Dynamically update your GUI.
Sketchpad: you need datastructures such as Line, Point, Triangle, etc. And then, each time OnPaint is triggered, you paint it dynamically. E.g: myGraphics.DrawLine(..), myGraphics.DrawCircle(..)
Similarly to Finale.
One thing you should do is to handle your data structure and drawing classes carefully, and instead of drawing everything in your OnPaint() method, you create several DrawMe(..) methods in your entity classes, and ask them to draw themselves. E.g: myCircle.DrawMe(..), myScore.DrawMe(..)
Hope that'll help,
Ben
There is no universal answer to your question - it is too generic.
Are you talking about dynamicly created controls, standard UI components (dropdowns, buttons)?
Is it vector graphics - like in drawings, or may be it is 2D image processing - or is it 3D?

Categories