Represents a 128-bit color with red, green, blue and alpha channels at 32 bits each.
Пример #1
0
		/// <summary>Draws a rectangle.</summary>
		/// <param name="texture">The texture, or a null reference.</param>
		/// <param name="point">The top-left coordinates in pixels.</param>
		/// <param name="size">The size in pixels.</param>
		/// <param name="color">The color, or a null reference.</param>
		internal static void DrawRectangle(Textures.Texture texture, Point point, Size size, Color128? color) {
			// TODO: Remove Nullable<T> from color once RenderOverlayTexture and RenderOverlaySolid are fully replaced.
			if (texture == null || !Textures.LoadTexture(texture, Textures.OpenGlTextureWrapMode.ClampClamp)) {
				GL.Disable(EnableCap.Texture2D);
				if (color.HasValue) {
					GL.Color4(color.Value.R, color.Value.G, color.Value.B, color.Value.A);
				}
				GL.Begin(PrimitiveType.Quads);
				GL.Vertex2(point.X, point.Y);
				GL.Vertex2(point.X + size.Width, point.Y);
				GL.Vertex2(point.X + size.Width, point.Y + size.Height);
				GL.Vertex2(point.X, point.Y + size.Height);
				GL.End();
			} else {
                GL.Enable(EnableCap.Texture2D);
				GL.BindTexture(TextureTarget.Texture2D, texture.OpenGlTextures[(int)Textures.OpenGlTextureWrapMode.ClampClamp].Name);
				if (color.HasValue) {
					GL.Color4(color.Value.R, color.Value.G, color.Value.B, color.Value.A);
				}
				GL.Begin(PrimitiveType.Quads);
				GL.TexCoord2(0.0f, 0.0f);
				GL.Vertex2(point.X, point.Y);
				GL.TexCoord2(1.0f, 0.0f);
				GL.Vertex2(point.X + size.Width, point.Y);
				GL.TexCoord2(1.0f, 1.0f);
				GL.Vertex2(point.X + size.Width, point.Y + size.Height);
				GL.TexCoord2(0.0f, 1.0f);
				GL.Vertex2(point.X, point.Y + size.Height);
				GL.End();
			}
		}
Пример #2
0
		/// <summary>Draws a rectangle.</summary>
		/// <param name="texture">The texture, or a null reference.</param>
		/// <param name="point">The top-left coordinates in pixels.</param>
		/// <param name="size">The size in pixels.</param>
		/// <param name="color">The color, or a null reference.</param>
		internal static void DrawRectangle(int texture, Point point, Size size, Color128? color)
		{
			GL.Enable(EnableCap.Blend);
			// TODO: Remove Nullable<T> from color once RenderOverlayTexture and RenderOverlaySolid are fully replaced.
			if (texture == -1)
			{
				GL.Disable(EnableCap.Texture2D);
				if (color.HasValue)
				{
					GL.Color4(color.Value.R, color.Value.G, color.Value.B, color.Value.A);
				}
				GL.Begin(PrimitiveType.Quads);
				GL.Vertex2(point.X, point.Y);
				GL.Vertex2(point.X + size.Width, point.Y);
				GL.Vertex2(point.X + size.Width, point.Y + size.Height);
				GL.Vertex2(point.X, point.Y + size.Height);
				GL.End();
			}
			else
			{
				GL.Enable(EnableCap.Texture2D);
				GL.BindTexture(TextureTarget.Texture2D, TextureManager.Textures[texture].OpenGlTextureIndex);
				if (color.HasValue)
				{
					GL.Color4(color.Value.R, color.Value.G, color.Value.B, color.Value.A);
				}
				GL.Begin(PrimitiveType.Quads);
				if(TextureManager.Texture.VFlip == true)
				{
					GL.TexCoord2(0.0f, 1.0f);
					GL.Vertex2(point.X, point.Y);
					GL.TexCoord2(1.0f, 1.0f);
					GL.Vertex2(point.X + size.Width, point.Y);
					GL.TexCoord2(1.0f, 0.0f);
					GL.Vertex2(point.X + size.Width, point.Y + size.Height);
					GL.TexCoord2(0.0f, 0.0f);
					GL.Vertex2(point.X, point.Y + size.Height);
					GL.End();
				}
				// else
				// {
				// 	GL.TexCoord2(0.0f, 0.0f);
				// 	GL.Vertex2(point.X, point.Y);
				// 	GL.TexCoord2(1.0f, 0.0f);
				// 	GL.Vertex2(point.X + size.Width, point.Y);
				// 	GL.TexCoord2(1.0f, 1.0f);
				// 	GL.Vertex2(point.X + size.Width, point.Y + size.Height);
				// 	GL.TexCoord2(0.0f, 1.0f);
				// 	GL.Vertex2(point.X, point.Y + size.Height);
				// 	GL.End();
				// }
				
			}
			GL.Disable(EnableCap.Blend);
		}
Пример #3
0
 /// <summary>Renders a string to the screen.</summary>
 /// <param name="font">The font to use.</param>
 /// <param name="text">The string to render.</param>
 /// <param name="location">The location.</param>
 /// <param name="orientation">The orientation.</param>
 /// <param name="color">The color.</param>
 /// <remarks>This function sets the OpenGL blend function to glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA).</remarks>
 private static void DrawString(Fonts.OpenGlFont font, string text, Point location, TextAlignment alignment, Color128 color)
 {
     if (text == null) {
         return;
     }
     /*
      * Prepare the top-left coordinates for rendering, incorporating the
      * orientation of the string in relation to the specified location.
      * */
     int left;
     if ((alignment & TextAlignment.Left) == 0) {
         int width = 0;
         for (int i = 0; i < text.Length; i++) {
             Textures.Texture texture;
             Fonts.OpenGlFontChar data;
             i += font.GetCharacterData(text, i, out texture, out data) - 1;
             width += data.TypographicSize.Width;
         }
         if ((alignment & TextAlignment.Right) != 0) {
             left = location.X - width;
         } else {
             left = location.X - width / 2;
         }
     } else {
         left = location.X;
     }
     int top;
     if ((alignment & TextAlignment.Top) == 0) {
         int height = 0;
         for (int i = 0; i < text.Length; i++) {
             Textures.Texture texture;
             Fonts.OpenGlFontChar data;
             i += font.GetCharacterData(text, i, out texture, out data) - 1;
             if (data.TypographicSize.Height > height) {
                 height = data.TypographicSize.Height;
             }
         }
         if ((alignment & TextAlignment.Bottom) != 0) {
             top = location.Y - height;
         } else {
             top = location.Y - height / 2;
         }
     } else {
         top = location.Y;
     }
     /*
      * Render the string.
      * */
     Gl.glEnable(Gl.GL_TEXTURE_2D);
     for (int i = 0; i < text.Length; i++) {
         Textures.Texture texture;
         Fonts.OpenGlFontChar data;
         i += font.GetCharacterData(text, i, out texture, out data) - 1;
         if (Textures.LoadTexture(texture, Textures.OpenGlTextureWrapMode.ClampClamp)) {
             Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.OpenGlTextures[(int)Textures.OpenGlTextureWrapMode.ClampClamp].Name);
             int x = left - (data.PhysicalSize.Width - data.TypographicSize.Width) / 2;
             int y = top - (data.PhysicalSize.Height - data.TypographicSize.Height) / 2;
             /*
              * In the first pass, mask off the background with pure black.
              * */
             Gl.glBlendFunc(Gl.GL_ZERO, Gl.GL_ONE_MINUS_SRC_COLOR);
             Gl.glBegin(Gl.GL_POLYGON);
             Gl.glColor4f(color.A, color.A, color.A, 1.0f);
             Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Top);
             Gl.glVertex2f(x, y);
             Gl.glColor4f(color.A, color.A, color.A, 1.0f);
             Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Top);
             Gl.glVertex2f(x + data.PhysicalSize.Width, y);
             Gl.glColor4f(color.A, color.A, color.A, 1.0f);
             Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom);
             Gl.glVertex2f(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height);
             Gl.glColor4f(color.A, color.A, color.A, 1.0f);
             Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom);
             Gl.glVertex2f(x, y + data.PhysicalSize.Height);
             Gl.glEnd();
             /*
              * In the second pass, add the character onto the background.
              * */
             Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE);
             Gl.glBegin(Gl.GL_POLYGON);
             Gl.glColor4f(color.R, color.G, color.B, color.A);
             Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Top);
             Gl.glVertex2f(x, y);
             Gl.glColor4f(color.R, color.G, color.B, color.A);
             Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Top);
             Gl.glVertex2f(x + data.PhysicalSize.Width, y);
             Gl.glColor4f(color.R, color.G, color.B, color.A);
             Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom);
             Gl.glVertex2f(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height);
             Gl.glColor4f(color.R, color.G, color.B, color.A);
             Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom);
             Gl.glVertex2f(x, y + data.PhysicalSize.Height);
             Gl.glEnd();
         }
         left += data.TypographicSize.Width;
     }
     Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); // HACK //
 }
Пример #4
0
 /// <summary>Renders a string to the screen.</summary>
 /// <param name="font">The font to use.</param>
 /// <param name="text">The string to render.</param>
 /// <param name="location">The location.</param>
 /// <param name="orientation">The orientation.</param>
 /// <param name="color">The color.</param>
 /// <param name="shadow">Whether to draw a shadow.</param>
 /// <remarks>This function sets the OpenGL blend function to glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA).</remarks>
 private static void DrawString(Fonts.OpenGlFont font, string text, Point location, TextAlignment alignment, Color128 color, bool shadow)
 {
     if (shadow) {
         DrawString(font, text, new Point(location.X - 1, location.Y + 1), alignment, new Color128(0.0f, 0.0f, 0.0f, 0.5f * color.A));
         DrawString(font, text, location, alignment, color);
     } else {
         DrawString(font, text, location, alignment, color);
     }
 }
Пример #5
0
		/// <summary>Renders a string to the screen.</summary>
		/// <param name="font">The font to use.</param>
		/// <param name="text">The string to render.</param>
		/// <param name="location">The location.</param>
		/// <param name="alignment">The alignment.</param>
		/// <param name="color">The color.</param>
		/// <remarks>This function sets the OpenGL blend function to glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA).</remarks>
		private static void DrawString(Fonts.OpenGlFont font, string text, Point location, TextAlignment alignment, Color128 color) {
			if (text == null) {
				return;
			}
			/*
			 * Prepare the top-left coordinates for rendering, incorporating the
			 * orientation of the string in relation to the specified location.
			 * */
			int left;
			if ((alignment & TextAlignment.Left) == 0) {
				int width = 0;
				for (int i = 0; i < text.Length; i++) {
					Textures.Texture texture;
					Fonts.OpenGlFontChar data;
					i += font.GetCharacterData(text, i, out texture, out data) - 1;
					width += data.TypographicSize.Width;
				}
				if ((alignment & TextAlignment.Right) != 0) {
					left = location.X - width;
				} else {
					left = location.X - width / 2;
				}
			} else {
				left = location.X;
			}
			int top;
			if ((alignment & TextAlignment.Top) == 0) {
				int height = 0;
				for (int i = 0; i < text.Length; i++) {
					Textures.Texture texture;
					Fonts.OpenGlFontChar data;
					i += font.GetCharacterData(text, i, out texture, out data) - 1;
					if (data.TypographicSize.Height > height) {
						height = data.TypographicSize.Height;
					}
				}
				if ((alignment & TextAlignment.Bottom) != 0) {
					top = location.Y - height;
				} else {
					top = location.Y - height / 2;
				}
			} else {
				top = location.Y;
			}
			/*
			 * Render the string.
			 * */
			GL.Enable(EnableCap.Texture2D);
			for (int i = 0; i < text.Length; i++) {
				Textures.Texture texture;
				Fonts.OpenGlFontChar data;
				i += font.GetCharacterData(text, i, out texture, out data) - 1;
				if (Textures.LoadTexture(texture, Textures.OpenGlTextureWrapMode.ClampClamp)) {
					GL.BindTexture(TextureTarget.Texture2D,texture.OpenGlTextures[(int)Textures.OpenGlTextureWrapMode.ClampClamp].Name);
					int x = left - (data.PhysicalSize.Width - data.TypographicSize.Width) / 2;
					int y = top - (data.PhysicalSize.Height - data.TypographicSize.Height) / 2;
					/*
					 * In the first pass, mask off the background with pure black.
					 * */
					GL.BlendFunc(BlendingFactorSrc.Zero,BlendingFactorDest.OneMinusSrcColor);
					GL.Begin(PrimitiveType.Polygon);
					GL.Color4(color.A, color.A, color.A, 1.0f);
					GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Top);
					GL.Vertex2(x, y);
					GL.Color4(color.A, color.A, color.A, 1.0f);
					GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Top);
					GL.Vertex2(x + data.PhysicalSize.Width, y);
					GL.Color4(color.A, color.A, color.A, 1.0f);
					GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom);
					GL.Vertex2(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height);
					GL.Color4(color.A, color.A, color.A, 1.0f);
					GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom);
					GL.Vertex2(x, y + data.PhysicalSize.Height);
					GL.End();
					/*
					 * In the second pass, add the character onto the background.
					 * */
					GL.BlendFunc(BlendingFactorSrc.SrcAlpha,BlendingFactorDest.One);
					GL.Begin(PrimitiveType.Polygon);
					GL.Color4(color.R, color.G, color.B, color.A);
					GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Top);
					GL.Vertex2(x, y);
					GL.Color4(color.R, color.G, color.B, color.A);
					GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Top);
					GL.Vertex2(x + data.PhysicalSize.Width, y);
					GL.Color4(color.R, color.G, color.B, color.A);
					GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom);
					GL.Vertex2(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height);
					GL.Color4(color.R, color.G, color.B, color.A);
					GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom);
					GL.Vertex2(x, y + data.PhysicalSize.Height);
					GL.End();
				}
				left += data.TypographicSize.Width;
			}
			GL.BlendFunc(BlendingFactorSrc.SrcAlpha,BlendingFactorDest.OneMinusSrcAlpha); // HACK //
		}
Пример #6
0
 /// <summary>Checks whether two colors are equal.</summary>
 /// <param name="a">The first color.</param>
 /// <param name="b">The second color.</param>
 /// <returns>Whether the two colors are equal.</returns>
 public bool Equals(Color128 a, Color128 b)
 {
     return(a.R != b.R | a.G != b.G | a.B != b.B | a.A != b.A);
 }