Permalink
Browse files

Decal rendering #5: Render decal colours

  • Loading branch information...
LogicAndTrick committed Feb 9, 2013
1 parent 08a0ba3 commit c6fa811b46f7bd3741f143e0115384a29054683c
View
@@ -136,8 +136,8 @@ private void EditorLoad(object sender, EventArgs e)
TextureProvider.Register(new SprProvider());
var spritesFolder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Sprites");
TexturePackage.Load(spritesFolder);
TexturePackage.LoadTextureData(TexturePackage.GetLoadedItems().Select(x => x.Name));
//TexturePackage.Load(spritesFolder);
//TexturePackage.LoadTextureData(TexturePackage.GetLoadedItems().Select(x => x.Name));
Subscribe();
}
@@ -67,6 +67,7 @@ void main()
vertexLighting = (vec4(1,1,1,1) * light1intensity * incidence1) * 0.5
+ (vec4(1,1,1,1) * light2intensity * incidence2) * 0.5
+ (vec4(1,1,1,1) * ambient);
vertexLighting.w = 1; // Reset the alpha channel or transparency gets messed up later
texCoord = texture;
vertexSelected = selected;
}
@@ -91,6 +91,7 @@ private static int CreateAndBindTexture()
private static void SetTextureParameters()
{
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.IO;
using Sledge.Graphics;
@@ -11,6 +12,54 @@ namespace Sledge.Providers.Texture
{
public class WadProvider : TextureProvider
{
private static Bitmap PostProcessBitmap(string name, Bitmap bmp)
{
// Transparent textures are named like: {Name
if (name.StartsWith("{"))
{
var palette = bmp.Palette;
// Two transparency types: "blue" transparency and "decal" transparency
// Decal transparency is all greyscale and doesn't contain any of palette #255 colour
var blueTransparency = false;
for (var i = 0; i < palette.Entries.Length - 1; i++)
{
var color = palette.Entries[i];
if (color.R != color.B || color.R != color.G || color.B != color.G)
{
blueTransparency = true;
break;
}
}
if (blueTransparency)
{
// We found the last index, therefore it should be transparent
palette.Entries[palette.Entries.Length - 1] = Color.Transparent;
}
else
{
// If we didn't find the last index, we have a decal
var last = palette.Entries[palette.Entries.Length - 1];
for (var i = 0; i < palette.Entries.Length - 1; i++)
{
palette.Entries[i] = Color.FromArgb(255 - palette.Entries[i].R, last);
}
}
bmp.Palette = palette;
// Copy the bitmap to a new one with a proper alpha channel
var clone = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb);
using (var g = System.Drawing.Graphics.FromImage(clone))
{
g.DrawImage(bmp, new Rectangle(0, 0, clone.Width, clone.Height));
}
bmp.Dispose();
return clone;
}
return bmp;
}
public class WadStreamSource : TextureStreamSource
{
private readonly Dictionary<string, Tuple<HLLib.Package, HLLib.Folder>> _packages;
@@ -34,7 +83,8 @@ public override Bitmap GetImage(TextureItem item)
{
using (var stream = root.Item1.CreateStream(search))
{
return new Bitmap(new MemoryStream(stream.ReadAll()));
var bmp = new Bitmap(new MemoryStream(stream.ReadAll()));
return PostProcessBitmap(item.Name, bmp);
}
}
return null;
@@ -72,10 +122,10 @@ protected override void LoadTexture(TexturePackage package, string name)
var item = pack.GetRootFolder().GetItemByName(name + ".bmp", HLLib.FindType.Files);
using (var stream = pack.CreateStream(item))
{
using (var bmp = new Bitmap(new MemoryStream(stream.ReadAll())))
{
TextureHelper.Create(name, bmp);
}
var bmp = new Bitmap(new MemoryStream(stream.ReadAll()));
bmp = PostProcessBitmap(name, bmp);
TextureHelper.Create(name, bmp);
bmp.Dispose();
}
}
}
@@ -99,10 +149,10 @@ protected override void LoadTextures(TexturePackage package, IEnumerable<string>
if (!item.Exists) continue;
using (var stream = pack.CreateStream(item))
{
using (var bmp = new Bitmap(new MemoryStream(stream.ReadAll())))
{
TextureHelper.Create(name, bmp);
}
var bmp = new Bitmap(new MemoryStream(stream.ReadAll()));
bmp = PostProcessBitmap(name, bmp);
TextureHelper.Create(name, bmp);
bmp.Dispose();
}
}
}

0 comments on commit c6fa811

Please sign in to comment.