I am trying to achieve a simple task (or so I thought) in XNA 4.0. I have objects that need to glow (rendering and Gaussian blurring them and then adding them to the main scene). These objects can be at different depths so I will need to make sure that they are obscured by objects in front of them in the main scene. It's 3D.
Because depth buffers cannot be re-used in XNA 4.0, I am having a hard time figuring out how I can achieve this?
I can find no examples or tutorials or explanations of this process. The bloom post process example of XNA also does not do exactly what I need, as it post processes the entire scene.
I know that I can preserve RenderTarget info by using PreserveContents, but it sounded like it was slow. Is there a way to achieve this without using PreserveContents?
Any help would be appreciated.
Thank you,
Riaan.
I'd try to render the glowing objects using a second rendertarget to store its depth... this is a multi target rendering technique...
I suppose that you will need another for the non glowing objects..(or use the same, storing both depths with an addtive blending) to compare them at postproccess time...
later in the post process it would be possible to know if the glowing object is visible or is hidden.
Related
since this is my very first time trying to make yet simple but useable sidescroller I'd like to ask some questions and hopefully gather ideas to make a good engine that can change the position of an Image in the form depending on X position of the drawn game character. I'd basically like to recreate just few seconds of a Mario game.
The starting Idea (correct me if it's wrong / poorly performance / whatever) would be to create a picture long in width and whit fixed height and upon the press of, for example, A or D keys, the drawn character moves till a certain X point, after that, character gets locked in place and if the key is still pressed, the background image starts moving.
But the problem there would be the fix for collisions, would be possible to check for the X position of the drawn background picture and set "collisions" accordingly for the character?
Other questions : why picturebox should be avoided at all costs and use the form itself instead ? Placing the greater part of the classes methods inside a timer_tick event is the wrong approach ? I read somewhere that the best way to do games of this kind would be relying on infinite loops in the forms main method, but I simply cannot even think how this could possibly works, taking in count all the times we may need to get out of the loop and do different code in different places.
Any other different ideas/approach and direct links to further explanations would be greatly liked
Edit : yes i'd like to improve with windows forms before moving to xna/unity
Assumption: You want to make a little game and its your first time working with moving graphics and you're working with WindowsForms. Suggestion: try using a more advanced framework such as MonoGame or XNA and working your way through introductory documentation and tutorials. Also WPF has a more advanced graphics platform for doing things like drawing and 3D, you may want to give that a shot.
To expand on my comment a bit.
Windows Forms and GDI (the tech behind drawing) aren't meant for this kind of use. When GDI was created its purpose was essentially drawing lines and fonts on the screen. XNA is a really good framework for learning the basics up to professional design. Unfortunately the XNA framework is no longer supported by Microsoft and as such MonoGame is the recommended development route for managed .NET 3D and 2D game development.
The WPF provides basic access to Direct3D and Direct2D, and has 2D and 3D shapes and animations built into the framework and is what WPF is based on.
But you also have the choice, if need be, to create an XNA component and embed it in a Windows Form as demonstrated in these two tutorials.
XNA in Windows Forms I
XNA in Windows Forms II
Also using a Windows Forms Timer isn't recommended because they are unreliable. The .Net Framework provides a 'Server Timer' and a 'Threading timer' that can be used as well.
If you are really keen on using GDI for a game may I recommend reading about the basics of game programming (I think there are a few XNA docs on the subject) that should guide you on things like the basic run time loop, getting input, and simple physics.
I am implementing a simplistic GUI library for a game.
My solution uses SFML 2.1 2d API.
As you can imagine, the ui elements are organized in a hierarchical structure. Children are expected to render within the bounds of their parents.
I could live with the need to trust children to render outside their parent. However, to implement scrolling in a simple manner, I'd like to clip whatever children render.
Is there a way to achieve this using the SFML 2d api ?
For now, I could only come up with drawing to a texture and use that texture for a shape or sprite. I am concerned with performance (even though, the texture would only be regenerated when UI content changes).
Unfortunately this features isn't yet implemented, but you're not the only one waiting for it, see the first issue ever created on SFML's GitHub issue tracker.
In the meantime the only way is to either use OpenGL directly or via a sf::RenderTexture.
I have this odd little lifesim program I've been working on that involves data in a 2d array. This was never supposed to be a big thing, and I initially looked at a few snapshots of it by just writing it out to an external bitmap, pixel by pixel, which I then open and look at. This doesn't give me any sort of live update to the screen. This is a horrible way to do this, and in trying to implement drawing this directly in a window, I want to do this correct and efficiently the first time.
I did some searching and found bitblt, which will let me draw a whole rectangle at a time, but all of my graphics experience being limited to things like WPF, a lot of the terminology is lost on me. I don't know what format my data should be in order to hand it to this function as a bitmap. In reading around msdn I find references to things like DC, etc, more things I haven't yet learned about.
I don't need to know lots about Windows graphics API or .NET's drawing framework. I don't want to learn a bunch of DirectX. I want to make a Window of a specific dimension and I want to be able to set the RGB value of each of those pixels as I see fit. No drawings shapes or anything, just pixels. But I also don't want to do it one pixel at a time, a separate system call for each, because even a lame programmer like myself knows how terribly inefficient that is. Does anyone know if a good resource that will give a simple explanation of graphics in Windows and will let me do this? MSDN is great for looking things up, but it's a bit much if you're trying to learn something from scratch.
C# is preferable because the lifesim in written in it, but I don't have any qualms about rewriting it in C++ if there's a good reason for it.
You could try the WriteableBitmap class in WPF and see if it fits your purposes.
A tutorial
All you would have to do is keep the data in the 2D array and write it to the WriteableBitmap. Set the WriteableBitmap as the image source of a WPF Image and you're done.
Let me know if you need an example.
What you probably want to do is use LockBits to lock up your image data, and then manipulate your image as an array. Here's a great tutorial by Bob Powell:
https://web.archive.org/web/20121203144033/http://www.bobpowell.net/lockingbits.htm
Otherwise, if speed is not a concern, you can use the GetPixel and SetPixel methods. These are horribly slow though, but will work in a managed environment.
My goal is to gain a better understanding of the characteristics of C#, and become more comfortable creating simple apps. I am fairly competent with Flash (Actionscript 3), and found an old Tic-Tac-Toe game I'd written. I started wondering about porting this code into a C# application. Not knowing much about C#, I'm wondering how difficult the migration would be.
On the one hand, the underlying game logic is syntactically similar, and therefore would be easy to port.
However, as far as the graphics are concerned, I don't even know where to begin. So far, I've only exposed myself to Windows Forms and Console apps in C#.
I'm wondering if these Flash concepts have similar analogs in C#, or if the procedures and syntax are radically different:
Placing graphic elements on a stage
Rendering lines from start/end coordinates
Event listeners on movie clips
Swapping the image inside a graphic element (or, in my Flash version, nextFrame() in a movie clip)
You may want to try developping your little game using Silverlight. Silverlight applications, coded using C# and Xaml, are pretty similar in form with flash applications, and you should find everything you need without trouble.
So I suggest you download the Silverlight SDK (free) and give it a try.
Firstly, Flash is to WPF (close enough) as ActionScript is to C#.
The WPF/Silverlight model is much more similar to Flex that it is to Flash. Everything is added to the UI tree as a object, even lines.
Likewise, adding event handlers to controls (like a button click) can be done in the "code behind" (the code that lives with the view), but the recommendation is to use the MVVM pattern. If you are new to the concepts of separation of concerns and unit testing, feel free to start with the simpler "code behind" method.
While WPF and Silverlight are very similar, I'd recommend starting with Silverlight as the SDK and available samples are richer. You can easily move onto WPF later on (though porting an application from Silverlight to WPF is not automatic).
Swapping images, as you mentioned, would be done via "Visual States" in Silverlight (or possibly changing the image reference, which is more "hacky").
Have a look at the following links to get started:
Learn # Silverlight.net
Silverlight on MSDN
Shapes and Drawing (Silverlight)
If you're looking specifically to do games and the like, you may wish to look into the free XNA framework. However, there will be differences as Flash gives you far more ability to "set up" things beforehand and modify them.
Placing graphic elements on a stage
If you go the XNA route, you will be drawing sprites using the spritebatch, you tell them where and how to draw and that's where they will go
Rendering lines from start/end coordinates
In windows forms you can do this via a simple System.Drawing call, however if you wish to do this in XNA, you will either have to make a 1 pixel square and stretch/rotate it to what you want, or use 3d primitives (Though this will limit you to a 1 pixel line)
Event listeners on movie clips
Look into delegates, but there isn't really an equivalent for movie clips to my knowledge
Swapping the image inside a graphic element (or, in my Flash version, nextFrame() in a movie clip)
This is fairly simple, depending on what you mean. If you want to, say, animate a sprite. You can do this by moving the source rectangle or changing the texture of the spritesheet. If you mean the screen as a whole, this is mostly handled for you provided you use the spritebatch. In windows forms you'll have to do more of it yourself, but the base concepts are the same.
Overall it's not that bad, but if that doesn't sound appealing check out Silverlight. It's basically C# styled flash so you may find the transition easier.
Good luck and hope this helps.
image http://prod.triplesign.com/map.jpg
How can I produce a similar output in C# window forms in the easiest way?
Is there a good library for this purpose?
I just needs to be pointed in the direction of which graphic library is best for this.
You should just roll your own in a 3d graphics library. You could use directx. If using WPF it is built-in, you can lookup viewport3d. http://msdn.microsoft.com/en-us/magazine/cc163449.aspx
In graphics programming what you are building is a very simple version of a heightmap. I think building your own would give your greater flexibility in the long run.
So a best library doesn't exist. There are plenty of them and some are just for different purposes. Here a small list of possibilities:
Tao: Make anything yourself with OpenGL
OpenTK: The successor of the Tao framework
Dundas: One of the best but quite expensive (lacks in real time performance)
Nevron: Quite good, but much cheaper (also has problems with real time data)
National Instruments: Expensive, not the best looking ones, but damn good in real time data.
... Probably someone else made some other experiences.
Checkout Microsoft Chart Controls library.
Here's how I'd implement this using OpenGL.
First up, you will need a wrapper to import the OpenGL API into C#. A bit of Googling led me to this:
CsGL - OpenGL .NET
There a few example programs available to demonstrate how the OpenGL interface works. Play around with them to get an idea of how the system works.
To implement the 3D map:
Create an array of vectors (that's not the std::vector/List type but x,y,z triplets) where x and y are along the horizontal plane and z is the up amount.
Set the Z compare to less-than-or-equal (so the overlaid line segments are visible).
Create a list of quads where the vertices of the quads are taken from the array in (1)
Calculate the colour of the quad. Use a dot-product of the quad's normal and a light source direction to get a value to shade value, i.e. normal.light of 1 is black and -1 is white.
Create a list of line segments, again from the array in (1).
Calculate the screen position of the various projected axes points.
Set up your camera and world->view transform (use the example programs to get an idea of how to do this).
Render the quads and lines, OpenGL will do the transformation from world co-ordinates (the list in (1)) to screen space. Draw the labels, you might not want to do this using OpenGL as the labels shouldn't scale with distance from camera, otherwise they could get too small to read.
Since the above is quite a lot of stuff, there isn't really the space (and time on my part) to post working code (but someone else might add something if you're lucky). You could break the task down and ask questions on the parts you don't quite understand.
Have you tried this... gigasoft data visualization tools (Its not free)
And you can checkout the online wireframe demo here