DirectX 2D drawing with Vb.net - vb.net

I'm using using System.Graphics for my latest project (A simple 2D application). Problem is, it gets a horrible FPS and I'm only drawing 8x8 tiles (usually 10-12 is enough to bring it down to 12FPS).
A friend of mine suggested that I use DirectX. He also suggested XNA but I opposed because I don't want my clients to have to install the XNA distributional. DirectX is common enough (to my knowledge) and I can just include the dll's if I need to.
So, my search began. I've been looking only for DirectX 2D tutorials for VB.net. I've had no solid success thus far. In truth, all I need to do is be able to draw bitmap x at position pos.
I've been using System.Graphics and a hacked up bitmap as my buffer thus far so I'll go for any improvement that I can get.
I'm using VB.net so I'll be ok if you give my one for C#, I'm pretty good at being able to read it (and I have a nice converter too). I would just prefer VB.net to save time.
Thanks! :)

This article in MSDN Magazine was in 2003 edition had a nice example of managed DirectX code in action:
http://msdn.microsoft.com/en-us/magazine/cc164112.aspx
Sadly enough, currently, there's no managed library of DirectX (a.k.a. DirectX .NET wrapper) in DX 10 and DX 11. Microsoft only provided managed library for DX 9.0a and DX 9.0b.
In Managed DirectX wikipedia, you'll see that it's being replaced by Microsoft XNA.
If you download current/latest DirectX SDK, you will have samples only in C++ and HLSL codes.
If you really need fancy UI and also nice animation and 3D drawing based on DirectX, you can go use WPF, especially WPF in .NET 3.0 SP2 (or simply download and install .NET 3.5 SP1). WPF is build on top of DirectX 9.0c stack, without worrying to know large libraries of DirectX 9 API. You'll also get 3D primitives support too.
More on WPF, visit this:
http://msdn.microsoft.com/en-us/library/ms754130.aspx

Related

How do you draw text in DirectX 12?

This is a follow-up question of How do you draw text in DirectX 11?
In Direct3D-12, things got much more complex and since it's new I couldn't find any suitable libraries online.
I'm building a basic Direct3D12 FPS Test application, and I like to display the FPS data on screen with my rendered image.
The general answer to questions like this is "if you have to ask, then you probably should be using DirectX 11." DirectX 12 is a graphics expert API that provide immense control, and is not particularly concerned with ease-of-use for novices. See this thread for more thoughts in this vein.
With that out of the way, one option is to use device interop and Direct2D/DirectWrite. See Working with Direct3D 11, Direct3D 10 and Direct2D.
UPDATE: DirectX Tool Kit for DirectX 12 is now available. It includes a SpriteFont / SpriteBatch implementation that will draw text on Direct3D 12 render targets. See this tutorial.
Pure DirectX 12, then you need to load the font glyph data into a vertex buffer and render with a vertex shader and pixel shader. You mentioned libraries online, will this is expert stuff and fortunately James Stanard at Microsoft release a how to with their open source MiniEngine project. He handles multiple fonts, antialiasing, and drop shadows in DirectX 12.
Find the project files at GitHub https://github.com/Microsoft/DirectX-Graphics-Samples/tree/master/MiniEngine and check out Textrender.h and Textrender.cpp
If you want maximum feature set with minimum work you probably should go with DirectWrite on top of a D3D11 interop device, like Chuck said in his answer.
If you want to roll your own high performance text rendering you may want to take a look at the text renderer in the miniengine example repository on github, it has some interesting ideas.
Unfortunately the only ways have already been described. Interface with DirectWrite or create your glyph file system.
What you are doing is importing a texture file with glyphs on it, cutting out small squares around each character from the glyph texture file, and then gluing it all together to form a string. It results in some faster drawing (in some case).
I think the approach to this as referenced by the others is slightly outdated and destined to fail. Direct3D11 had the same lack of text drawing support as Direct3D12 (perhaps misinformation on that). It was Direct3D9 which had the built in text drawing support, which nonetheless worked fine, and later supported sprite batch drawing where you could render all text in one sprite.
It seems backwards to state that you simply "need to know" or "are not an expert" to implement such a basic yet tedious system. Such a system is destined to fail in the same way why no one wants to use Assembly to code something they can code in C and onward.
The D3D11 and D3D12 math library also suffers from the same failures. To define and convert vectors you are better off including D3D9X math or custom math structures because the newer methods included are so backwards. "Someone" made it and must like it, but I remember making a complaint showing how easy it is to do vector operations before vs afterward, it nearly doubles or triples the amount of lines needed to perform basic vectors operation and conversions, not even counting the amount of references and learning time you would need to see how someone else's lib works. It seems to be a big failure presented by mathematicians who were never good at programming.

Integrating Octave in VB

I have a code written for displaying 2D histogram in Octave. I want to build a nice GUI for displaying the demo for the code. I thought of using VB forms (using VS2012) for building this. However I could not call the Octave programs from VB. Can anyone give me some ideas regarding this?
Thanks in advance
The Visual Studio distribution of Octave 3.6.2 for Windows includes some basic UI functionality, which may be enough for your needs, so that you could do it all in Octave without having to get Octave and VB to talk to each other. From Summary of important user-visible changes for version 3.6:
** The following Matlab-compatible handle graphics functions have
been
added:
guidata uipanel uitoolbar
guihandles uipushtool uiwait
uicontextmenu uiresume waitfor
uicontrol uitoggletool
The uiXXX functions above are experimental.
Except for uiwait and uiresume, the uiXXX functions are not
supported with the FLTK+OpenGL graphics toolkit.
The gnuplot graphics toolkit does not support any of the uiXXX
functions nor the waitfor function.
3.6.4 is also out (see http://sourceforge.net/projects/octave/files/Octave%20Windows%20binaries/Octave%203.6.4%20for%20Windows%20Microsoft%20Visual%20Studio/), but I don't know if the UI functionality has been improved or not.

Media on Windows CE using Compact Framework

I have the following requirements:
I need a api that works on CE (x86) + .NET Compact Framework to play videos (Similar to CorePlayer API... Just free)?
Is their anything else available or must I use CorePlayer?
You could use the MediaPlayer with COM interop. Have a look at this and this.
Also, Media Player may not be installed in your device.
You need to use DShow and have the codecs for whatever media you intend to play in the image. COM interop for WMP 9.0 (which is what ships up through at least CE 5.0, maybe also in 6.0) is a non-starter for managed code.
If you don't know DShow, it's a fair amount of work - even in native code - as DShow is not a fun or friendly API set.
The plus side is that you don't need WMP at all in the image, so you can typically use a Core CE license (Pro is required to use WMP). I know of a commercial DShow control, but you said you're looking for a free solution and I'm not aware of anything other than rolling your own. Depending on your level of familiarity with COM interop (which you'll need for the DShow stuff) and the use of DShow and filtergraphs, I'd allocate at least a week or two to getting this working.
One added note - the complexity also changes depending on how you want the video displayed. If it's just full-screen then it's a bit less work than getting it inside a Window within your app. Not a lot less, but at least a little.
DirectShow?
Check out this page for a starting point.
Provided that DirectShow is present on your CE, which I don't know...
EDIT: Since you can use DirectShow, I'd like to add a bit.
As ctacke notes, it can be a lot of work if you do everything manually, but it's pretty straightforward if you can use IGraphBuilder (see the sample I linked above).
I don't know much about DirectShow versions, but the one included with Windows Mobile 6.0 lacks a splitter for MPEG audio. It means, e.g., that out of the box it won't play .mp3 files unless you wrap them in RIFF headers.
I bet you can convert some of DirectShow.Net to run on CE if you are looking for a C# solution.

Will Expression Blend relieve me from having to learn xaml?

I don't mind learning xaml and I'm sure I need to be familiar somewhat, but when I was first trying out Silverlight 1 with javascript it looked like a tremendous amount of overhead. I decided to wait until tools matured and asp.net was added. Well, asp.net has been added with Silverlight 2.0, and now I want to look at using it. But, xaml, to me, still looks like a lot of work for each small step. My experience with Flash seemed a lot more simpler for the graphics side of things (never liked ActionScript that much.) Will $500 for Blend take care of much of my xaml concerns? Can I use Visual Studio Express with the full version of Microsoft Expression Blend?
Do I need Microsoft Expression Studio 2?
Thank you.
Just as a profressional web developer can't lean on Dreamweaver's drag-and-drop to avoid learning HTML, you should climb the XAML learning curve.
Blend will still help, however- just as many started up the HTML curve by doing some drag-and-drop and studying the resulting HTML code. I did some prototyping with Silverlight 1.1 and Blend helped significantly in my understanding of XAML. It helps to have a "real" project to work on, even if it's a proof of concept. Concentrate on the containment paradigm between Canvas and other elements and you'll pick it up quickly enough. I wouldn't worry too much about the MPATH stuff, do rely on the tool for that.
Microsoft Expression Blend takes care of a lot of XAML for you and helps you create animations and setting up triggers (XAML triggers). I would hate to have to do all that by hand coded XAML. I have not used Blend with Visual Studio Express but I believe it will work just fine. Microsoft Expression Blend 2 uses the sln file to open a project.
Expression Blend will not help with databinding. VS2010 promises databinding in its WPF designer, but if you can't wait until then, look to learning some XAML.
Count XAML as one of the many new .NET 3.5 things to learn when working with WPF/Silverlight. I recommend Pro WPF in C# 2008 from APress
Expression Blend give you the ability to draw shapes, paths, Union or diff shapes, create animations (similar to Flash Tweening), wire up simple triggers (like on mouseover play an animation). All with out having to dive into XAML.

How do I get input from an XBox 360 controller?

I'm writing a program that needs to take input from an XBox 360 controller. The input will then be sent wirelessly to an RC Helicopter that I am building.
So far, I've learned that this can be done using either the XInput library from DirectX, or the Input framework in XNA.
I'm wondering if there are any other options available. The scope of my program is rather small, and having to install a large gaming library like DirectX or XNA seems like excessive. Further, I'd like the program to be cross platform and not Microsoft specific.
Is there a simple lightweight way I can grab the controller input with something like Python?
Edit to answer some comments:
The copter will have 6 total propellers, arranged in 3 co-axial pairs. Basically, it will be very similar to this, only it will cost about $1,000 rather than $15,000. It will use an Arduino for onboard processing, and Zigbee for wireless control.
The 360 controller was selected because it is well designed. It is very ergonomic and has all of the control inputs needed. For those familiar with helicopter controls, the left joystick will control the collective, the right joystick with control the pitch and roll, and the analog triggers will control the yaw. The analog triggers are a big feature for the 360 controller. PS and most others do not have them.
I have a webpage for the project, but it is still pretty sparse. I do plan on documenting the whole design though, so eventually it will be interesting.
http://tricopter.googlecode.com
On a side note, would it kill Google to have a blog feature for googlecode projects?
I would like the 360 controller input program to run in both Linux and Windows if possible. Eventually though, I'd like to hook the controller directly to an embedded microcontroller board (such as Arduino) so that I don't have to go through a computer, but its not a high priority at the moment.
It is not all that difficult. As the earlier guy mentioned, you can use the SDL libraries to read the status of the xbox controller and then you can do whatever you'd like with it.
There is a SDL tutorial: http://sdl.beuc.net/sdl.wiki/Handling_Joysticks which is fairly useful.
Note that an Xbox controller has the following:
two joysticks:
left joystick is axis 0 & 1;
left trigger is axis 2;
right joystick is axis 3 & 4;
right trigger is axis 5
one hat (the D-pad)
11 SDL buttons
two of them are joystick center presses
two triggers (act as axis, see above)
The upcoming SDL v1.3 also will support force feedback (aka. haptic).
I assume, since this thread is several years old, you have already done something, so this post is primarily to inform future visitors.
PyGame can read joysticks, which is what the X360 controller shows up as on a PC.
Well, if you really don't want to add a dependency on DirectX, you can use the old Windows Joystick API -- Windows Multimedia -> Joystick Reference in the platform SDK.
The standard free cross plaform game library is Simple DirectMedia Layer, originally written to port Windows games to Unix (Linux) systems. It's a very basic, lightweight API that tends to support the minimal subset of features on each system, and it has bindings for most major languages. It has very basic joystick and gamepad support (no force feedback, for example) but it might be sufficient for your needs.
Perhaps the Mono.Xna library has added GamePad support, which would provide the cross platform functionality you were looking for:
http://code.google.com/p/monoxna/
As far as the concerns about the library being too heavy weight, sure, for this option it may be true ... however, it could open up opportunities to do some nice visualization in the future.
disclaimer: I'm not familiar with the status of the mono xna project, so it may not have added this feature yet. But still, 'tis an option :-)