Merge branch 'glfonts', remote branches 'alzeih/master' and 'pchote/master'
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#region Copyright & License Information
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
@@ -28,7 +28,6 @@ using Tao.Cg;
|
||||
using Tao.OpenGl;
|
||||
using OpenRa.FileFormats.Graphics;
|
||||
using Tao.Sdl;
|
||||
using ISE;
|
||||
|
||||
[assembly: Renderer( typeof( OpenRa.GlRenderer.GraphicsDevice ))]
|
||||
|
||||
@@ -60,9 +59,12 @@ namespace OpenRa.GlRenderer
|
||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
|
||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 8);
|
||||
|
||||
Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0");
|
||||
|
||||
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_NOFRAME | Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN));
|
||||
// Breaks os x usability
|
||||
//Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0");
|
||||
//surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_NOFRAME | Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN));
|
||||
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN));
|
||||
|
||||
Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA");
|
||||
Sdl.SDL_ShowCursor(0);
|
||||
Sdl.SDL_EnableUNICODE( 1 );
|
||||
@@ -265,11 +267,6 @@ namespace OpenRa.GlRenderer
|
||||
return new Shader( this, stream );
|
||||
}
|
||||
|
||||
public IFont CreateFont( string filename )
|
||||
{
|
||||
return new Font( this, filename );
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -453,63 +450,4 @@ namespace OpenRa.GlRenderer
|
||||
bitmap.UnlockBits(bits);
|
||||
}
|
||||
}
|
||||
|
||||
class Font : IFont
|
||||
{
|
||||
const int RenderedFontSize = 48;
|
||||
const float emHeight = 14f; /* px */
|
||||
|
||||
GraphicsDevice dev;
|
||||
FTFontGL font;
|
||||
|
||||
public Font( GraphicsDevice dev, string filename )
|
||||
{
|
||||
this.dev = dev;
|
||||
int Errors;
|
||||
font = new FTFontGL(filename, out Errors);
|
||||
|
||||
if (Errors > 0)
|
||||
throw new InvalidOperationException("Error(s) loading font");
|
||||
|
||||
font.ftRenderToTexture(RenderedFontSize, 192);
|
||||
font.FT_ALIGN = FTFontAlign.FT_ALIGN_LEFT;
|
||||
}
|
||||
|
||||
public void DrawText( string text, int2 pos, Color c )
|
||||
{
|
||||
pos.Y += (int)(emHeight);
|
||||
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||
Gl.glPushMatrix();
|
||||
Gl.glLoadIdentity();
|
||||
|
||||
Gl.glMatrixMode(Gl.GL_PROJECTION);
|
||||
Gl.glPushMatrix();
|
||||
Gl.glLoadIdentity();
|
||||
|
||||
Gl.glOrtho(0, dev.WindowSize.Width, 0, dev.WindowSize.Height, 0, 1);
|
||||
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||
Gl.glTranslatef(pos.X, dev.WindowSize.Height - pos.Y, 0);
|
||||
Gl.glScalef(emHeight / RenderedFontSize, emHeight / RenderedFontSize, 1);
|
||||
|
||||
font.ftBeginFont(false);
|
||||
Gl.glColor4f(c.R / 255f, c.G / 255f, c.B / 255f, c.A / 255f);
|
||||
font.ftWrite(text);
|
||||
font.ftEndFont();
|
||||
|
||||
Gl.glMatrixMode(Gl.GL_PROJECTION);
|
||||
Gl.glPopMatrix();
|
||||
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||
Gl.glPopMatrix();
|
||||
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public int2 Measure( string text )
|
||||
{
|
||||
return new int2((int)(font.ftExtent(ref text) / 3), (int)emHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user