View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# FW1FontWrapper in SlimDX

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.

9 replies to this topic

### #1hossainiir  Members

Posted 12 March 2013 - 04:03 AM

hi,

Has anyone used FW1FontWrapper.dll for rendering text in SlimDx(C#)?

indeed is this possible ,if yes how can i do that??

Edited by hossainiir, 12 March 2013 - 08:57 AM.

خلیج تا ابد فارس

Persian Gulf

### #2Jason Z  Members

Posted 12 March 2013 - 07:31 PM

I haven't done this, but from my understanding of the fw1 library it is more or less just generating a texture to hold the glyphs, and then those glyphs can be used for putting text into a rendered scene by just using textured quads.  Have you tried to adapt this technique, or is something tripping you up?

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #3MJP  Moderators

Posted 13 March 2013 - 12:11 AM

The interface is a C++ class, which you can't directly consume in a C# project. You would need to either write a managed wrapper for the library in C++/CLI (this is what SlimDX does for DirectX), or you can create a "flat" API consisting of just C functions (no classes) that you can call with p/invoke. The first option can be pretty difficult if you've never done it before, C++/CLI is fairly obscure and it can be tricky even if you're experienced with C++. The latter is easier if the interface is simple, but you'd still need some working knowledge of C/C++ in order to write it and set up the DLL correctly.

### #4hossainiir  Members

Posted 13 March 2013 - 12:26 AM

Thanks for replay ,

i want to render unicode char like persian chars, the problem is that in this kind of language letters may stick together, unlike latin letters that never stick together.

for example in english we have s and S but in persian we have ﺱ ﺲﺳ ﺴ(indeed S = س).

Sometimes it is hard to handle, but using this library is very simple.

خلیج تا ابد فارس

Persian Gulf

### #5hossainiir  Members

Posted 13 March 2013 - 12:33 AM

The interface is a C++ class, which you can't directly consume in a C# project. You would need to either write a managed wrapper for the library in C++/CLI (this is what SlimDX does for DirectX), or you can create a "flat" API consisting of just C functions (no classes) that you can call with p/invoke. The first option can be pretty difficult if you've never done it before, C++/CLI is fairly obscure and it can be tricky even if you're experienced with C++. The latter is easier if the interface is simple, but you'd still need some working knowledge of C/C++ in order to write it and set up the DLL correctly.

Thanks,

I've already called just method and function from C++ dll not creating interfaces from C++ dll, can you help me ?.

خلیج تا ابد فارس

Persian Gulf

### #6Erik Rufelt  Members

Posted 13 March 2013 - 11:06 AM

Do you want to do it with C functions or as a class?

I made an example with another DLL that exports C functions that uses the wrapper, and a C# class that can use it: http://www.rufelt.com/fw1fontwrapper/csharp/

Download FW1CWrapper.zip and extract the appropriate DLL together with the usual FW1FontWrapper.dll and use the source in FW1Wrapper.cs to use the DLLs from C#.

I haven't tested this extensively and I don't have very much experience in C# or interop, but it seems to work fine, as long as you compile with x86 or x64 and use the appropriate DLL.

Then in SlimDX you can do this:

using FW1;

...

IntPtr devicePtr = device.ComPointer;

IntPtr contextPtr = device.ImmediateContext.ComPointer;

FW1Wrapper fontWrapper = new FW1Wrapper(devicePtr, "Arial");

...

fontWrapper.DrawString(contextPtr, "a string", "Courier New", 64.0f, x, y, 0xffffffff, FW1Wrapper.Center);


I've only done the most common functions.

### #7hossainiir  Members

Posted 13 March 2013 - 12:11 PM

Thanks Erik!

I want to do with class ,l will try this.

,

خلیج تا ابد فارس

Persian Gulf

### #8hossainiir  Members

Posted 13 March 2013 - 01:05 PM

I got this error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

at the following line of code:

IntPtr pFW1FontWrapper = C_FW1_CreateFontWrapper(pDevice11,fontFamily,locale,mipLevels,anisotropicFiltering,disableGeometryShader);



خلیج تا ابد فارس

Persian Gulf

### #9Erik Rufelt  Members

Posted 13 March 2013 - 01:15 PM

Are both the FW1FontWrapper.dll and FW1CWrapper.dll files in the directory for your .exe?

Also, are they both matching x86 or x64, and not different, and have you chosen the same x86 or x64 target when building your C# program?

I tried it on the SlimDX MiniTri sample and it worked there for me. If I select the "Any" target instead of x86 or x64 it doesn't work though, I think you need a different method for that.

### #10hossainiir  Members

Posted 13 March 2013 - 01:37 PM

With x64 i got no error but nothing rendered!!!

خلیج تا ابد فارس

Persian Gulf

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.