This is not really language-specific (although I am most comfortable in C#). I am basically trying to create an application that would display basic 2D graphics over an OpenGL application (specifically FlightGear). There would be no need to have mouse-interaction (e.g. clicks) with the overlay - it would be for informational purposes only.
What is the simplest way of going about this?
If I understand your question correctly, you just have to render your scene and after that you can change your camera transformation to a parallel projection, with the size of your viewport. You can now render simple rectangles with your 2D graphics as textures on it.
Related
I currently have a WinForms C# application. I have a .txt file with GPS coordinates of some points (borders of buildings, roads etc.), and using Graphics.FillPolygon method in System.Drawing I am drawing these on a Panel. However, I got an idea that for what I am trying to do (it basically is a 2D game), a Unity 2D project would be more suitable and easy to use (mainly because of easier view handling using the cameras). However, I don't know how to do this drawing in it. I just need to somehow get these coordinates drawn in Unity, but I don't know how to do it.
Note: I already have some minor expirience with 3D in Unity, but I am a total newbie to 2D.
Thanks
There is no GDI/canvas implementation built into Unity. Drawing these in rastered 2D would be quite hard in Unity (basically putpixel level, or finding some third party library).
You have an alternative, though - you can draw these shapes in 3D, ignoring the third dimension. You have a few methods for this:
Line renderers - this one will be the easiest, but forget about anything else than just drawing the outline, no fill etc.
Make your own mesh - This will let you use the geometry with your scene. It's an retained mode API (you init your geometry once)
Use the GL namespace - This will be only rendered on the screen, no interaction with the scene. It's an immidiate mode API (draw everything on every frame)
I just have a question:
I need to draw some WPF geometries in a canvas, and each geometry's surface is a complicate Texture2D in Direct3D 11. I'm using SharpDX and just convert the Texture2D into a MemoryStream then Convert to a WPF ImageSource, because I'm using Compute Shader, the Format.Bgra isn't supported with UAV texture, so I can't use a D3DImage. Since there're performance issue, how can I bind a Texture2D to a WPF Geometry directly? Thanks.
For performance reasons, you should perform the whole rendering with SharpDX and not using WPF Geometries, only D3DImage to synchronize the result of rendering with WPF. If you need to convert a texture from one format to another to match WPF formats, you can simply render a full quad with a simple shader copying the texture. If you are doing this with SharpDX Toolkit, it is fairly easy to develop it as it is providing a WPF control.
Short answer is you can't, WPF 3D is still in its infancy and custom shader support is available for 2D effects only. Best advice I can offer at the moment is to render your geometry onto an XNA surface and display it in an AirspacePopup with your WPF controls on top.
Im developing a game like "bubble-bobble". So far I have done physics and collision detection.
Now I want to make my Hero (Rectangle Sprite) animated. I would be glad if someone could explain simple scripting for simple animated characters or some nice links for animation.
The XNA Documentation includes an entire article on Animating a Sprite. The basic technique is to use an AnimatedTexture class, which is included within the Animated sprite sample code.
The high level idea is that you load a texture into memory using a graphics API. Since you're using C#, this is most likely done through XNA.
This texture you have loaded contains each frame of animation that is required, and may span across multiple textures. When you go and render your 'sprite' object, you pass the XNA API the texture you want to use, and a source rectangle coordinates that surround the specific frame of animation you want within that texture.
It's up to you to manage this process. I create tools that assemble these source rectangles and stores meta data about each specific animation each sprite has; like which rectangles, and the duration of each frame, etc.
So I've been trying to wrap my head around shaders in 2D in XNA.
http://msdn.microsoft.com/en-us/library/bb313868(v=xnagamestudio.31).aspx
This link above stated that I needed to use SpriteSortMode.Immediate, which is a problem for me because I have developed a parallax system that relies on deferred rendering (SpriteSortMode.BackToFront).
Can someone explain to me the significance of SpriteSortMode in shaders, if Immediate is mandatory, anything I can do to maintain my current system, and anything else in general to help me understand this better?
In addition, my game runs off of multiple SpriteBatch.Begin()/End() calls (for drawing background, then the game, then the foreground and HUD and etc). I've noticed that the Bloom example does not work in that case, and I am guessing it has something to do with this.
In general, I've been having some trouble understanding these concepts. I know what a shader is and how it works, but I don't know how it interacts with XNA and what goes on there. I would really appreciate some enlightenment. :)
Thanks SO!
The sort mode will matter if you are attempting to do something non-trivial like render layered transparency or make use of a depth buffer. I'm going to assume you want to do something non-trivial since you want to use a pixel shader to accomplish it.
SpriteSortMode.Immediate will draw things in exactly the order of the draw calls. If you use another mode, SpriteBatch will group the draw calls to the video card by texture if it can. This is for performance reasons.
Keep in mind that every time you call SpriteBatch.Begin you are applying a new pixel shader and discarding the one previously set. (Even if the new one is just SpriteBatch's standard pixel shader that applies a Tint color.) Additionally, remember that by calling SpriteBatch.End you are telling the video card to execute all of the current SpriteBatch commands.
This means that you could potentially keep your existing sorting method, if your fancy pixel shaders are of limited scope. In other words, draw your background with one Effect and then your foreground and characters with another. Each Begin/End call to SpriteBatch can be treated separately.
If your goal is to apply one Effect (such as heat waves or bloom) to everything on the screen you have another option. You could choose to render all of your graphics onto a RenderTarget that you create instead of directly to the video card's backbuffer. If you do this, at the end of your rendering section you can call GraphicsDevice.SetRenderTarget(null) and paint your completed image to the backbuffer with a custom shader that applies to the entire scene.
I'm not one hundred percent sure on how much the sprite sorting mode effects shaders, i would think it would vary depending on what you were using the shader for.
as for bloom if you're using multiple begin and ends (which you really want to minimise if you can). you can create a render target the size of the screen, draw everything as you are now. then at the very end, take that render target back (using graphicsdevice.SetRenderTarget(null);) then draw your full screen render target (at 0,0 position) with the bloom shader, that way you will bloom the entire scene, regardless of the components of the scene using various sort modes.
I would like to do something like this: a rotating cube on a form. I don't want to use any external library or dll, just pure .NET 3.5 (without directx). And a cube build with lines only. Could you please tell me how to do this?
I don't want to use external libraries because I don't need > 100 MB library to do this thing right? I want only to animate a rotating cube made with lines.
This is how you go about making a Cube in GDI+
C# 3D Drawing with GDI+ Euler Rotation
http://www.vcskicks.com/3d-graphics-improved.html
C# 3D-Drawing Cube with Shading
http://www.vcskicks.com/3d_gdiplus_drawing.html
Study assignment? This can be done with some simple 3D maths. You just need to understand the basics of matrix algebra, 3D transformations, and 3D->2D view transformation. The DirectX tutorial covers this, but you can google for it and you'll get plenty of other tutorials.
Added: Just to clarify - I'm not suggesting to use DirectX or anything. You can do this with standard System.Drawing tools. You just need to understand the math, and that's explained in the DirectX tutorials.
You might try using WPF and the 3D Tools source code released by the WPF team.
3DTools
Assuming you are using WPF for your GUI:
Make an animated PNG of the cube using a graphics program.
Use the APNG WPF Control to insert the image into your GUI.
This will yield a small assembly size and transparent background if needed.
You need a way to represent 3d points. There is no ready struct for that in .NET unless you use directx or WPF.
Then with a standard euler rotation matrix applied to the points you get the transformed points. If you only do rotations you can get away with 3x3 matrix, but if you want translation you better use 4x4 matrices and homogenous points.
After this you need a way to project those 3d points to the 2d canvas. Depending whether you are using perspective or orthographic projection the projection matrix will look a bit different.
Look into WPF in general, it will help you do this with a few measly lines of code. You can also host a WPF window in Forms.
http://msdn.microsoft.com/en-us/library/aa970268.aspx