Click here to Skip to main content
15,920,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: Incorporating applications to another project! Pin
Michael Sync12-Nov-07 18:08
Michael Sync12-Nov-07 18:08 
QuestionSendTo Shortcut Pin
smarttom9912-Nov-07 11:09
smarttom9912-Nov-07 11:09 
AnswerRe: SendTo Shortcut Pin
Michael Sync12-Nov-07 14:49
Michael Sync12-Nov-07 14:49 
QuestionSsl Stream and certificates Pin
kingletas12-Nov-07 9:38
kingletas12-Nov-07 9:38 
QuestionMake zedGraph legend scrollable Pin
gizmokaka12-Nov-07 9:13
gizmokaka12-Nov-07 9:13 
AnswerRe: Make zedGraph legend scrollable Pin
Judah Gabriel Himango12-Nov-07 11:09
sponsorJudah Gabriel Himango12-Nov-07 11:09 
QuestionExpand possibilties with zedGraph color and symbols Pin
gizmokaka12-Nov-07 9:10
gizmokaka12-Nov-07 9:10 
QuestionEmbed font and DirectX.Direct3D.Font Pin
eterno.darknight12-Nov-07 8:29
eterno.darknight12-Nov-07 8:29 
I have a problem.
I'm trying to create a Game using DirectX.
I use a special font for every text into the game, and I load it into PrivateFontCollection using [PFC.AddFontFile(pathtofile)] method.
Now I want to embed my font info a resource dll, and I find a code for reading font from resource.
It work only with GDI+ [e.Graphics.DrawString()] but while I try to use this font with [o3DFont.DrawText()] the text use the default font and not the selected font.

This sample demostrate what happen (just change font file[darknight.ttf], and referenced dll resource [GenericRes]):


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Text;
using System.IO;
using Microsoft.DirectX.Direct3D;
using D3DFont = Microsoft.DirectX.Direct3D.Font;
using D3DSprite = Microsoft.DirectX.Direct3D.Sprite;
using DGDevice = Microsoft.DirectX.Direct3D.Device;
using GDIFont = System.Drawing.Font;

namespace test {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}

PrivateFontCollection pfc = new PrivateFontCollection();


System.Reflection.Assembly extAssembly;
private void Form1_Load(object sender, System.EventArgs e) {
extAssembly = System.Reflection.Assembly.GetAssembly(typeof(GenericRes.Class1));

CaricaFontDaResource("darknight.ttf");

}

private void CaricaFontDaResource(string fontName) {
Stream fontStream = extAssembly.GetManifestResourceStream("GenericRes.NextAgeResources.Font." + fontName);
byte[] buffer = new byte[fontStream.Length];

fontStream.Read(buffer, 0, (int)fontStream.Length);
fontStream.Close();
unsafe {
fixed (byte* pFontData = buffer) {
pfc.AddMemoryFont((System.IntPtr)pFontData, buffer.Length);
}
}
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
System.Drawing.Font fn;
fn = new GDIFont(pfc.Families[0], 18, FontStyle.Strikeout);

// D3D font
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.PresentationInterval = PresentInterval.One;
DGDevice dGDevice = new DGDevice(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);

dGDevice.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0);
dGDevice.BeginScene();

D3DFont m_Font = new D3DFont(dGDevice, fn);
m_Font.DrawText(null, "stringa", new Rectangle(0, 100, 100, 100), DrawTextFormat.Left, Color.White);

dGDevice.EndScene();
dGDevice.Present();

//GDI font
e.Graphics.PageUnit = GraphicsUnit.Point;
SolidBrush b = new SolidBrush(Color.Black);

e.Graphics.DrawString(fn.Name, fn, b, 5, 5, StringFormat.GenericTypographic);

b.Dispose();
}
}
}

Did someone know why it happen? And maybe how to resolve this problem?
The only solution I found was to save font from resource when the game is opened and delete it when it'll be closed.
But I'd like to use embeded resource.
AnswerRe: Embed font and DirectX.Direct3D.Font Pin
Judah Gabriel Himango12-Nov-07 11:13
sponsorJudah Gabriel Himango12-Nov-07 11:13 
GeneralRe: Embed font and DirectX.Direct3D.Font Pin
eterno.darknight12-Nov-07 13:04
eterno.darknight12-Nov-07 13:04 
GeneralRe: Embed font and DirectX.Direct3D.Font Pin
Judah Gabriel Himango12-Nov-07 16:22
sponsorJudah Gabriel Himango12-Nov-07 16:22 
QuestionTree Node Question [modified] Pin
T4AMD12-Nov-07 7:54
T4AMD12-Nov-07 7:54 
AnswerRe: Tree Node Question Pin
Pete O'Hanlon12-Nov-07 8:47
mvePete O'Hanlon12-Nov-07 8:47 
AnswerOT: Big security risk Pin
Luis Alonso Ramos12-Nov-07 18:18
Luis Alonso Ramos12-Nov-07 18:18 
Question'System.EventHandler' Pin
azza10412-Nov-07 7:49
azza10412-Nov-07 7:49 
AnswerRe: 'System.EventHandler' Pin
Colin Angus Mackay12-Nov-07 8:26
Colin Angus Mackay12-Nov-07 8:26 
QuestionCustom MIME association for c# app Pin
gordon2412-Nov-07 6:48
gordon2412-Nov-07 6:48 
QuestionDisplaying selected row in the dataGrid's view area for Windows Mobile Pin
asrs6312-Nov-07 6:11
asrs6312-Nov-07 6:11 
AnswerRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
Skippums12-Nov-07 9:19
Skippums12-Nov-07 9:19 
GeneralRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
asrs6312-Nov-07 9:38
asrs6312-Nov-07 9:38 
GeneralRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
Skippums12-Nov-07 11:56
Skippums12-Nov-07 11:56 
GeneralRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
asrs6313-Nov-07 4:17
asrs6313-Nov-07 4:17 
GeneralRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
Skippums13-Nov-07 4:52
Skippums13-Nov-07 4:52 
GeneralRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
asrs6313-Nov-07 10:46
asrs6313-Nov-07 10:46 
GeneralRe: Displaying selected row in the dataGrid's view area for Windows Mobile Pin
Skippums13-Nov-07 11:57
Skippums13-Nov-07 11:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.