Browse files

Font Parser Update

  • Loading branch information...
1 parent 1e76788 commit 522703dc2f9c6531d14d2997a380e1c1ce3b6480 @53V3N1X committed Nov 15, 2013
View
2 .gitignore
@@ -26,7 +26,7 @@ build/
*_p.c
*.ilk
*.meta
-*.obj
+#*.obj
*.pch
*.pdb
*.pgc
View
11 Documentation/FileFormatSpecifications/SevenStateSpecification.txt
@@ -1,11 +0,0 @@
-state 'stateName'
-
-shader 'shaderName' 'shaderFilePath'
-
-texture 'filepath'
-
-staticModel 'filepath' 'positionX' 'positionY' 'positionZ' 'orientationW' 'orientationX' 'orientationY' 'orientationZ' 'scaleX' 'scaleY' 'scaleZ'
-
-sprite 'filePath'
-
-defaultshader 'shaderName'
View
12 Documentation/FileFormatSpecifications/SevenStaticModelSpecifications.txt
@@ -1,12 +0,0 @@
-// entries within quotes are variables
-
-staticModel 'staticModelName'
-shader 'shaderName' 'filePath'
-staticMesh 'staticMeshName'
-texture 'textureName' 'fileLocation'
-vertex 'x' 'y' 'z'
-vertexTexture 'u' 'v'
-vertexNormal 'x' 'y' 'z'
-face 'references1' 'references2' 'references3'
-endStaticMesh
-endStaticModel
View
1 Documentation/FileFormatSpecifications/SevenTexture.txt
@@ -1 +0,0 @@
-texture 'textureName' 'filePath'
View
BIN Engine.v11.suo
Binary file not shown.
View
12 Engine/Models/StaticModel.cs
@@ -20,6 +20,8 @@
namespace SevenEngine.Models
{
+ #region StaticMesh
+
/// <summary>Represents a single mesh that has been loaded on the GPU. multiple references of this class SHOULD exist,
/// because each reference of this class means another hardware instance. Hardware instancing is when you re-use the
/// same buffers on the GPU, which is good for both speed and memory space.</summary>
@@ -86,6 +88,10 @@ public class StaticMesh : InterfaceStringId
}
}
+ #endregion
+
+ #region StaticModelMesh
+
public class StaticModelMesh : InterfaceStringId
{
private string _id;
@@ -104,6 +110,10 @@ public StaticModelMesh(string id, Texture texture, StaticMesh staticMesh)
}
}
+ #endregion
+
+ #region StaticModel
+
/// <summary>Represents a collection of static meshes that all use the same transformational matrices. Multiples references to the same
/// StaticModel should not exists because the contents are NOT being hardware instanced on the GPU.</summary>
public class StaticModel : InterfaceStringId, InterfacePositionVector
@@ -193,4 +203,6 @@ internal StaticModel(string staticModelId, List<StaticModelMesh> meshes)
_orientation = Quaternion.FactoryIdentity;
}
}
+
+ #endregion
}
View
322 Engine/Renderer.cs
@@ -99,67 +99,66 @@ public static void SetProjectionMatrix()
#endregion
- #region DrawImmediateMode
+ #region ImmediateMode
- public static void DrawImmediateModeVertex(Vector position, Color color, Point uvs)
+ public static void DrawImmediateMode(float[] verteces, float[] colors, float[] uvs)
{
- GL.Color4(color.R, color.G, color.B, color.A);
- GL.TexCoord2(uvs.X, uvs.Y);
- GL.Vertex3(position.X, position.Y, position.Z);
+ throw new RendererException("not implemented method \"DrawImmediateMode\"");
}
#endregion
#region Text
- // THIS NEEDS TP BE THE RATIO OF CHARACTER ON SPRITE SHEET TO SIZE ON SCREEN
- private static float _pixelAdjust = 7f;
private static Font _font;
+
+ /// <summary>The current font that will be used when rendering text.</summary>
public static Font Font { get { return _font; } set { _font = value; } }
+ /// <summary>Renders text using screen cartesian coordinates and the current Font property.</summary>
+ /// <param name="message">The message to be rendered.</param>
+ /// <param name="x">The leftmost X value to start rendering the text from.</param>
+ /// <param name="y">The lowermost Y value to start rendering the text from.</param>
+ /// <param name="scale">The size relative to the image provided font file.</param>
+ /// <param name="rotation">The rotation about the Z axis IN RADIANS.</param>
+ /// <param name="color">The color you wish the text to be (NOT YET SUPPORTED, I MESSED UP. IM WORKING ON IT).</param>
public static void RenderText(string message, float x, float y, float scale, float rotation, Color color)
{
- // NOTE: I DON'T SUPPORT VARIABLE COLOR YET
+ // Apply the 2D orthographic matrix transformation
SetOrthographicMatrix();
+
+ // Apply the model view matrix transformations
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Translate(x * _screenWidth - _screenWidth / 2, y * _screenHeight - _screenHeight / 2, 0);
if (rotation != 0)
GL.Rotate(rotation, 0, 0, 1);
+
+ // Set up the verteces (hardware instanced for all character sprites)
+ GL.BindBuffer(BufferTarget.ArrayBuffer, CharacterSprite.GpuVertexBufferHandle);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
+ GL.EnableClientState(ArrayCap.VertexArray);
+
for (int i = 0; i < message.Length; i++)
{
CharacterSprite sprite = _font.Get(message[i]);
- // Aply the character offsets
- //GL.Translate(sprite.XOffset / _pixelAdjust, -sprite.YOffset / _pixelAdjust, 0);
+ // Apply the character offsets and scaling
GL.Translate(sprite.XOffset * scale, -sprite.YOffset * scale, 0);
-
GL.Scale(sprite.OriginalWidth * scale, sprite.OriginalHeight * scale, 0);
- // Vertex Array Buffer
- // Bind to the Array Buffer ID
- GL.BindBuffer(BufferTarget.ArrayBuffer, sprite.GpuVertexBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
- GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
- GL.EnableClientState(ArrayCap.VertexArray);
-
- // Bind the texture to which the UVs are mapping to.
+ // Bind the texture and set up the texture coordinates
GL.BindTexture(TextureTarget.Texture2D, sprite.Texture.GpuHandle);
- // Bind to the Array Buffer ID
GL.BindBuffer(BufferTarget.ArrayBuffer, sprite.GPUTextureCoordinateBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
GL.EnableClientState(ArrayCap.TextureCoordArray);
- // Select the vertex buffer as the active buffer (I don't think this is necessary but I haven't tested it yet).
- GL.BindBuffer(BufferTarget.ArrayBuffer, sprite.GpuVertexBufferHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
+ // Perform the render
GL.DrawArrays(BeginMode.Triangles, 0, sprite.VertexCount);
+ // Undo the offsets and scaling effects for this character
+ // and advance to the next character position
GL.Scale(1 / (sprite.OriginalWidth * scale), 1 / (sprite.OriginalHeight * scale), 0);
-
if (i + 1 < message.Length)
GL.Translate(
// Remove the xoffset
@@ -178,12 +177,12 @@ public static void RenderText(string message, float x, float y, float scale, flo
sprite.XAdvance * scale,
// Remove the yoffset and
sprite.YOffset * scale, 0);
- }
+ }
}
#endregion
- #region DrawSprite2d
+ #region Sprite
public static void DrawSprite(Sprite sprite)
{
@@ -204,21 +203,16 @@ public static void DrawSprite(Sprite sprite)
GL.Rotate(sprite.Rotation, 0, 0, 1);
GL.Scale(sprite.Scale.X, sprite.Scale.Y, 1);
- // Vertex Array Buffer
- // Bind to the Array Buffer ID
+ // Set up verteces
GL.BindBuffer(BufferTarget.ArrayBuffer, sprite.GpuVertexBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
// Enable the client state so it will use this array buffer pointer
GL.EnableClientState(ArrayCap.VertexArray);
- // Bind the texture to which the UVs are mapping to.
+ // Select texture and set up texture coordinates
GL.BindTexture(TextureTarget.Texture2D, sprite.Texture.GpuHandle);
- // Bind to the Array Buffer ID
GL.BindBuffer(BufferTarget.ArrayBuffer, sprite.GPUTextureCoordinateBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
GL.EnableClientState(ArrayCap.TextureCoordArray);
// Select the vertex buffer as the active buffer (I don't think this is necessary but I haven't tested it yet).
@@ -229,66 +223,148 @@ public static void DrawSprite(Sprite sprite)
#endregion
- #region DrawSkybox
+ #region Skybox
public static void DrawSkybox(SkyBox skybox)
{
-
+ // Apply the 3D projection matrix transformation
SetProjectionMatrix();
+ // Apply the model view matrix transformations
GL.MatrixMode(MatrixMode.Modelview);
-
+ // Apply the camera transformation
Matrix4 cameraTransform = _currentCamera.GetMatrix();
GL.LoadMatrix(ref cameraTransform);
-
+ // Apply the world transformation
GL.Translate(skybox.Position.X, skybox.Position.Y, skybox.Position.Z);
GL.Scale(skybox.Scale.X, skybox.Scale.Y, skybox.Scale.Z);
-
- // Vertex Array Buffer
- // Bind to the Array Buffer ID
+
+ // Set up verteces
GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
GL.EnableClientState(ArrayCap.VertexArray);
- // Bind the texture to which the UVs are mapping to.
- GL.BindTexture(TextureTarget.Texture2D, skybox.Left.GpuHandle);
- // Bind to the Array Buffer ID
+ // Select texture and set up texture coordinates
GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
GL.EnableClientState(ArrayCap.TextureCoordArray);
- // Select the vertex buffer as the active buffer (I don't think this is necessary but I haven't tested it yet).
- GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
+ // Render left side of skybox
+ GL.BindTexture(TextureTarget.Texture2D, skybox.Left.GpuHandle);
GL.DrawArrays(BeginMode.Triangles, 0, 6);
- // Bind the texture to which the UVs are mapping to.
+ // Render front side of skybox
GL.BindTexture(TextureTarget.Texture2D, skybox.Front.GpuHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
GL.DrawArrays(BeginMode.Triangles, 6, 6);
- // Bind the texture to which the UVs are mapping to.
+ // Render right side of skybox
GL.BindTexture(TextureTarget.Texture2D, skybox.Right.GpuHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
GL.DrawArrays(BeginMode.Triangles, 12, 6);
- // Bind the texture to which the UVs are mapping to.
+ // Render back side of skybox
GL.BindTexture(TextureTarget.Texture2D, skybox.Back.GpuHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
GL.DrawArrays(BeginMode.Triangles, 18, 6);
- // Bind the texture to which the UVs are mapping to.
+ // Render top side of skybox
GL.BindTexture(TextureTarget.Texture2D, skybox.Top.GpuHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
GL.DrawArrays(BeginMode.Triangles, 24, 6);
}
#endregion
+ #region StaticModel
+
+ /// <summary>Renders a single static model using "GL.DrawArrays()".</summary>
+ /// <param name="staticModel">The mesh to be rendered.</param>
+ public static void DrawStaticModel(StaticModel staticModel)
+ {
+ // Apply the 3D projection matrix transformations
+ SetProjectionMatrix();
+
+ // Apply the model view matrix transformations
+ GL.MatrixMode(MatrixMode.Modelview);
+ // Apply the camera transformation
+ Matrix4 cameraTransform = _currentCamera.GetMatrix();
+ GL.LoadMatrix(ref cameraTransform);
+ // Apply the world transformation
+ GL.Translate(staticModel.Position.X, staticModel.Position.Y, staticModel.Position.Z);
+ GL.Rotate(staticModel.Orientation.W, staticModel.Orientation.X, staticModel.Orientation.Y, staticModel.Orientation.Z);
+ GL.Scale(staticModel.Scale.X, staticModel.Scale.Y, staticModel.Scale.Z);
+
+ // Call the drawing functions for each mesh within the model
+ staticModel.Meshes.Foreach(DrawStaticModelPart);
+ }
+
+ private static void DrawStaticModelPart(StaticModelMesh subStaticModel)
+ {
+ // Make sure something will render
+ if (subStaticModel.StaticMesh.VertexBufferHandle == 0 ||
+ (subStaticModel.StaticMesh.ColorBufferHandle == 0 && subStaticModel.StaticMesh.TextureCoordinateBufferHandle == 0))
+ return;
+
+ // Push current Array Buffer state so we can restore it later
+ GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);
+
+ if (GL.IsEnabled(EnableCap.Lighting))
+ {
+ // Normal Array Buffer
+ if (subStaticModel.StaticMesh.NormalBufferHandle != 0)
+ {
+ // Set up normals
+ GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.NormalBufferHandle);
+ GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
+ GL.EnableClientState(ArrayCap.NormalArray);
+ }
+ }
+ else
+ {
+ // Color Array Buffer
+ if (subStaticModel.StaticMesh.ColorBufferHandle != 0)
+ {
+ // Set up colors
+ GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.ColorBufferHandle);
+ GL.ColorPointer(3, ColorPointerType.Float, 0, IntPtr.Zero);
+ GL.EnableClientState(ArrayCap.ColorArray);
+ }
+ }
+
+ // Texture Array Buffer
+ if (GL.IsEnabled(EnableCap.Texture2D) && subStaticModel.StaticMesh.TextureCoordinateBufferHandle != 0)
+ {
+ // Select the texture and set up texture coordinates
+ GL.BindTexture(TextureTarget.Texture2D, subStaticModel.Texture.GpuHandle);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.TextureCoordinateBufferHandle);
+ GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
+ GL.EnableClientState(ArrayCap.TextureCoordArray);
+ }
+ else
+ // Nothing will render if this branching is reached.
+ return;
+
+ // Set up verteces
+ GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.VertexBufferHandle);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
+ GL.EnableClientState(ArrayCap.VertexArray);
+
+ if (subStaticModel.StaticMesh.ElementBufferHandle != 0)
+ {
+ // Set up indeces
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, subStaticModel.StaticMesh.ElementBufferHandle);
+ GL.IndexPointer(IndexPointerType.Int, 0, IntPtr.Zero);
+ GL.EnableClientState(ArrayCap.IndexArray);
+
+ // Ready to render using an index buffer
+ GL.DrawElements(BeginMode.Triangles, subStaticModel.StaticMesh.VertexCount, DrawElementsType.UnsignedInt, 0);
+ }
+ else
+ // Ready to render
+ GL.DrawArrays(BeginMode.Triangles, 0, subStaticModel.StaticMesh.VertexCount);
+
+ GL.PopClientAttrib();
+ }
+
+ #endregion
+
#region DrawStaticModel - OLD!
///// <summary>Renders a single static model using "GL.DrawArrays()".</summary>
@@ -300,10 +376,10 @@ public static void DrawSkybox(SkyBox skybox)
// // Select the model view matrix to apply the world and camera transformation.
// GL.MatrixMode(MatrixMode.Modelview);
-
+
// // This line is not necessary when the camera matrix is loaded in just after.
// //GL.LoadIdentity();
-
+
// // Get and load the camera transformatino matrix.
// Matrix4 cameraTransform = _currentCamera.GetMatrix();
// GL.LoadMatrix(ref cameraTransform);
@@ -411,123 +487,7 @@ public static void DrawSkybox(SkyBox skybox)
#endregion
- #region DrawStaticModel
-
- /// <summary>Renders a single static model using "GL.DrawArrays()".</summary>
- /// <param name="camera">The camera used to capture the world (needed for the world to camera transformation).</param>
- /// <param name="staticModel">The mesh to be rendered.</param>
- public static void DrawStaticModel(StaticModel staticModel)
- {
- SetProjectionMatrix();
-
- // Select the model view matrix to apply the world and camera transformation.
- GL.MatrixMode(MatrixMode.Modelview);
-
- // This line is not necessary when the camera matrix is loaded in just after.
- //GL.LoadIdentity();
-
- // Get and load the camera transformatino matrix.
- Matrix4 cameraTransform = _currentCamera.GetMatrix();
- GL.LoadMatrix(ref cameraTransform);
-
- // Apply the world transformation due to the mesh's position, scale, and rotation
- GL.Translate(staticModel.Position.X, staticModel.Position.Y, staticModel.Position.Z);
- //GL.Rotate(staticModel.RotationAngle, staticModel.RotationAmmounts.X, staticModel.RotationAmmounts.Y, staticModel.RotationAmmounts.Z);
- GL.Rotate(staticModel.Orientation.W, staticModel.Orientation.X, staticModel.Orientation.Y, staticModel.Orientation.Z);
- GL.Scale(staticModel.Scale.X, staticModel.Scale.Y, staticModel.Scale.Z);
-
- staticModel.Meshes.Foreach(DrawStaticModelPart);
- }
-
- private static void DrawStaticModelPart(StaticModelMesh subStaticModel)
- {
- // If there is no vertex buffer, nothing will render anyway, so we can stop it now.
- if (subStaticModel.StaticMesh.VertexBufferHandle == 0 ||
- // If there is no color or texture, nothing will render anyway
- (subStaticModel.StaticMesh.ColorBufferHandle == 0 && subStaticModel.StaticMesh.TextureCoordinateBufferHandle == 0))
- return;
-
- // Push current Array Buffer state so we can restore it later
- GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);
-
- if (GL.IsEnabled(EnableCap.Lighting))
- {
- // Normal Array Buffer
- if (subStaticModel.StaticMesh.NormalBufferHandle != 0)
- {
- // Bind to the Array Buffer ID
- GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.NormalBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
- GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
- GL.EnableClientState(ArrayCap.NormalArray);
- }
- }
- else
- {
- // Color Array Buffer (Colors not used when lighting is enabled)
- if (subStaticModel.StaticMesh.ColorBufferHandle != 0)
- {
- // Bind to the Array Buffer ID
- GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.ColorBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
- GL.ColorPointer(3, ColorPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
- GL.EnableClientState(ArrayCap.ColorArray);
- }
- }
-
- // Texture Array Buffer
- if (GL.IsEnabled(EnableCap.Texture2D))
- {
- if (subStaticModel.StaticMesh.TextureCoordinateBufferHandle != 0)
- {
- // Bind the texture to which the UVs are mapping to.
- GL.BindTexture(TextureTarget.Texture2D, subStaticModel.Texture.GpuHandle);
- // Bind to the Array Buffer ID
- GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.TextureCoordinateBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
- GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
- GL.EnableClientState(ArrayCap.TextureCoordArray);
- }
- else
- // Nothing will render if this branching is reached.
- return;
- }
-
- // Vertex Array Buffer
- // Bind to the Array Buffer ID
- GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.VertexBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
- GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
- GL.EnableClientState(ArrayCap.VertexArray);
-
- if (subStaticModel.StaticMesh.ElementBufferHandle != 0)
- {
- // Element Array Buffer
- // Bind to the Array Buffer ID
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, subStaticModel.StaticMesh.ElementBufferHandle);
- // Set the Pointer to the current bound array describing how the data ia stored
- GL.IndexPointer(IndexPointerType.Int, 0, IntPtr.Zero);
- // Enable the client state so it will use this array buffer pointer
- GL.EnableClientState(ArrayCap.IndexArray);
- // Draw the elements in the element array buffer
- // Draws up items in the Color, Vertex, TexCoordinate, and Normal Buffers using indices in the ElementArrayBuffer
- GL.DrawElements(BeginMode.Triangles, subStaticModel.StaticMesh.VertexCount, DrawElementsType.UnsignedInt, 0);
- }
- else
- {
- // Select the vertex buffer as the active buffer (I don't think this is necessary but I haven't tested it yet).
- GL.BindBuffer(BufferTarget.ArrayBuffer, subStaticModel.StaticMesh.VertexBufferHandle);
- // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
- GL.DrawArrays(BeginMode.Triangles, 0, subStaticModel.StaticMesh.VertexCount);
- }
-
- GL.PopClientAttrib();
- }
-
- #endregion
+ /// <summary>This is used for throwing rendering exceptions only to make debugging faster.</summary>
+ private class RendererException : Exception { public RendererException(string message) : base(message) { } }
}
}
View
199 Engine/TextManager.cs
@@ -15,7 +15,6 @@
using System.Globalization;
using SevenEngine.Texts;
using SevenEngine.DataStructures;
-using SevenEngine.DataStructures.Interfaces;
namespace SevenEngine
{
@@ -25,61 +24,173 @@ public static class TextManager
public static void LoadFontFile(string id, string filePath, string textureLocations)
{
- ListArray<CharacterSprite> characters = new ListArray<CharacterSprite>(100);
- ListArray<string> textures = new ListArray<string>(1);
- using (StreamReader reader = new StreamReader(filePath))
+ try
{
- while (!reader.EndOfStream)
+ ListArray<CharacterSprite> characters = new ListArray<CharacterSprite>(255);
+ ListArray<string> textures = new ListArray<string>(1);
+ using (StreamReader reader = new StreamReader(filePath))
{
- string line = reader.ReadLine();
- string[] parameters = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
-
- switch (parameters[0])
+ int lineNumber = 1;
+ while (!reader.EndOfStream)
{
- case "page":
- string[] textureFile = parameters[2].Split("\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- TextureManager.LoadTexture(textureFile[1], textureLocations + textureFile[1]);
- textures.Add(textureFile[1]);
- break;
- case "char":
- characters.Add(new CharacterSprite(
- // Texture
- TextureManager.Get(textures[int.Parse(parameters[9].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture)]),
- // Id
- int.Parse(parameters[1].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // X Advance
- int.Parse(parameters[8].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // X
- int.Parse(parameters[2].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // Y
- int.Parse(parameters[3].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // Width
- int.Parse(parameters[4].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // Height
- int.Parse(parameters[5].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // X Offset
- int.Parse(parameters[6].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- // Y Offset
- int.Parse(parameters[7].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture)));
+ string line = reader.ReadLine();
+ string[] parameters = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ switch (parameters[0].ToLower())
+ {
+ case "page":
+ string[] textureFile = parameters[2].Split("\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ try { TextureManager.LoadTexture(textureFile[1], textureLocations + textureFile[1]); }
+ catch { throw new TextManagerException("The font file is using a non-supported image file on line " + lineNumber + "."); }
+ textures.Add(textureFile[1]);
break;
- case "kerning":
- int first = int.Parse(parameters[1].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture);
- for (int i = 0; i < characters.Count; i++)
- if (characters[i].Id == first)
- characters[i].AddKearning(
- int.Parse(parameters[2].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
- int.Parse(parameters[3].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture));
+
+ case "char":
+ int charId = -1,
+ x = -1, y = -1,
+ width = -1, height = -1,
+ xOffset = int.MinValue, yOffset = int.MinValue,
+ xAdvance = -1,
+ page = -1;
+ // channel=-1;
+
+ // Lets get all the attributes of the character
+ for (int i = 1; i < parameters.Length; i++)
+ {
+ string[] attribute = parameters[i].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ if (attribute.Length < 2)
+ throw new TextManagerException("Font file has a corrupted character attribute on line " + lineNumber + ".");
+ switch (attribute[0].ToLower())
+ {
+ case "id":
+ if (!int.TryParse(attribute[1], out charId))
+ throw new TextManagerException("An id value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "x":
+ if (!int.TryParse(attribute[1], out x))
+ throw new TextManagerException("A x value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "y":
+ if (!int.TryParse(attribute[1], out y))
+ throw new TextManagerException("A y value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "width":
+ if (!int.TryParse(attribute[1], out width))
+ throw new TextManagerException("A width value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "height":
+ if (!int.TryParse(attribute[1], out height))
+ throw new TextManagerException("A height value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "xoffset":
+ if (!int.TryParse(attribute[1], out xOffset))
+ throw new TextManagerException("A xoffset value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "yoffset":
+ if (!int.TryParse(attribute[1], out yOffset))
+ throw new TextManagerException("A yoffset value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "xadvance":
+ if (!int.TryParse(attribute[1], out xAdvance))
+ throw new TextManagerException("A xadvance value in font file is corrupted on line " + lineNumber + ".");
+ break;
+ case "page":
+ if (!int.TryParse(attribute[1], out page))
+ throw new TextManagerException("A page value in font file is corrupted on line " + lineNumber + ".");
+ break;
+
+ //// This check is most likely unnecessary, an error will be thrown during image loading attempt.
+ //case "chnl":
+ // if (!int.TryParse(attribute[1], out channel))
+ // throw new TextManagerException("A chnl value in font file is corrupted on line " + lineNumber + ".");
+ // if (channel != 15)
+ // throw new TextManagerException("The font file is using a non-supported image file.");
+ }
+ }
+
+ // Make sure all the necessary values were imported and are valid
+ if (charId == -1)
+ throw new TextManagerException("Font file is corrupt/missing on a char id on line " + lineNumber + ".");
+ if (x < 0)
+ throw new TextManagerException("Font file has corrupt/missing on x value on line " + lineNumber + ".");
+ if (y < 0)
+ throw new TextManagerException("Font file has a corrupt/missing y value on line " + lineNumber + ".");
+ if (width < 0)
+ throw new TextManagerException("Font file has a corrupt/missing width value on line " + lineNumber + ".");
+ if (height == -1)
+ throw new TextManagerException("Font file has a corrupt/missing height value on line " + lineNumber + ".");
+ if (xOffset == int.MinValue)
+ throw new TextManagerException("Font file is missing a xoffset value on line " + lineNumber + ".");
+ if (yOffset == int.MinValue)
+ throw new TextManagerException("Font file is missing a yoffset value on line " + lineNumber + ".");
+ if (xAdvance < 0)
+ throw new TextManagerException("Font file has a corrupt/missing xadvance value on line " + lineNumber + ".");
+ if (page < 0 || page > textures.Count)
+ throw new TextManagerException("Font file has a corrupt/missing page value on line " + lineNumber + ".");
+
+ //// This check is most likely unnecessary, an error will be thrown during image loading attempt.
+ //if (channel == -1)
+ // throw new TextManagerException("Font file is missing a channel value on line " + lineNumber + ".");
+
+ characters.Add(
+ new CharacterSprite(
+ TextureManager.Get(textures[page]),
+ charId,
+ xAdvance,
+ x, y,
+ width, height,
+ xOffset, yOffset));
break;
+
+ // THIS WAS MY INITIAL PARSER JUST TO GET THINGS WORKING
+ // characters.Add(new CharacterSprite(
+ // // Texture
+ // TextureManager.Get(textures[int.Parse(parameters[9].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture)]),
+ // // Id
+ // int.Parse(parameters[1].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // X Advance
+ // int.Parse(parameters[8].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // X
+ // int.Parse(parameters[2].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // Y
+ // int.Parse(parameters[3].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // Width
+ // int.Parse(parameters[4].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // Height
+ // int.Parse(parameters[5].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // X Offset
+ // int.Parse(parameters[6].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // // Y Offset
+ // int.Parse(parameters[7].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture)));
+ // break;
+ //case "kerning":
+ // int first = int.Parse(parameters[1].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture);
+ // for (int i = 0; i < characters.Count; i++)
+ // if (characters[i].Id == first)
+ // characters[i].AddKearning(
+ // int.Parse(parameters[2].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture),
+ // int.Parse(parameters[3].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture));
+ // break;
+ }
+ lineNumber++;
}
}
+ _fontDatabase.Add(new Font(id, characters));
+ string[] pathSplit = filePath.Split('\\');
+ Output.WriteLine("Font file loaded: \"" + pathSplit[pathSplit.Length - 1] + "\".");
}
- _fontDatabase.Add(new Font(id, characters));
+ catch { throw new TextManagerException("An unknown error has occured while loading the font " + id + "."); }
}
+ /// <summary>Pulls out a font from the database.</summary>
+ /// <param name="font">The name associated with this font when you loaded it in.</param>
+ /// <returns>The font associated with the string id.</returns>
public static Font GetFont(string font)
{
- Font fontToGet = _fontDatabase.Get(font);
- return fontToGet;
+ try { Font fontToGet = _fontDatabase.Get(font); return fontToGet; }
+ catch { throw new TextManagerException("The requested font does not exists."); }
}
+
+ /// <summary>This is used for throwing AVL Tree exceptions only to make debugging faster.</summary>
+ private class TextManagerException : Exception { public TextManagerException(string message) : base(message) { } }
}
}
View
2 Engine/Texts/CharacterSprite.cs
@@ -36,7 +36,7 @@ public class CharacterSprite
private int _originalHeight;
/// <summary>The handle to the memory of the texture buffer on the GPU.</summary>
- internal int GpuVertexBufferHandle { get { return _gpuVertexBufferHandle; } }
+ internal static int GpuVertexBufferHandle { get { return _gpuVertexBufferHandle; } }
/// <summary>The handle to the memory of the texture buffer on the GPU.</summary>
internal int GPUTextureCoordinateBufferHandle { get { return _gpuTextureMappingBufferHandle; } }
/// <summary>Returns 6, because character sprites always have 6 verteces.</summary>
View
9 Game/States/PowerRangerDNA.cs
@@ -143,10 +143,11 @@ public void Render()
if (_mushroomCloud.Scale.X > 0 && _bool)
Renderer.DrawStaticModel(_mushroomCloud);
- //Renderer.RenderText("WELCOME TO", -300f, 50f, 22f, 30f, Color.Black);
- //Renderer.RenderText("SEVENENGINE", -300f, 0f, 22f, 30f, Color.Black);
- Renderer.RenderText("WELCOME TO", 0f, .8f, 1.2f, 0f, Color.Black);
- Renderer.RenderText("SEVENENGINE", 0f, .6f, 1.2f, 0f, Color.Black);
+ Renderer.RenderText("Welcome To", 0f, .8f, .5f, 0f, Color.Black);
+ Renderer.RenderText("SevenEngine!", 0f, .7f, .5f, 0f, Color.Black);
+
+ //Renderer.RenderText("Welcome To", 0f, .8f, 100f, 0f, Color.Black);
+ //Renderer.RenderText("SevenEngine!", 0f, .6f, 100f, 0f, Color.Black);
}
private void RenderModel(StaticModel model)

0 comments on commit 522703d

Please sign in to comment.