internal static unsafe GLTexture CreateBG(GLContext ctx) { GLTexture tex = new GLTexture(ctx, 16, 16); tex.Bind(); //Create BG texture ABGRPixel left = new ABGRPixel(255, 192, 192, 192); ABGRPixel right = new ABGRPixel(255, 240, 240, 240); int * pixelData = stackalloc int[16 * 16]; ABGRPixel *p = (ABGRPixel *)pixelData; for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) { *p++ = ((x & 8) == (y & 8)) ? left : right; } } //ctx.glEnable(GLEnableCap.Texture2D); //ctx.glBindTexture(GLTextureTarget.Texture2D, _backTex._id); ctx.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.WrapS, (int)GLTextureWrapMode.REPEAT); ctx.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.WrapT, (int)GLTextureWrapMode.REPEAT); ctx.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureMinFilter.NEAREST); ctx.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureMagFilter.NEAREST); ctx.glTexImage2D(GLTexImageTarget.Texture2D, 0, GLInternalPixelFormat._4, 16, 16, 0, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, pixelData); return(tex); }
protected override bool OnInitialize() { _flags = Header->Flags; _colorMask = (ARGBPixel)Header->_colorMask; _colors.Clear(); if ((_flags & CLR0EntryFlags.IsSolid) != 0) { _numEntries = 0; _solidColor = (ARGBPixel)Header->SolidColor; } else { _numEntries = ((CLR0Node)_parent)._numFrames + 1; ABGRPixel *data = Header->Data; for (int i = 0; i < _numEntries; i++) { _colors.Add((ARGBPixel)(*data++)); } } if ((_name == null) && (Header->_stringOffset != 0)) { _name = Header->ResourceString; } return(false); }
protected internal override void OnRebuild(VoidPtr address, int length, bool force) { int count = Children.Count; int stride = (_numFrames + 1) * 4 * count; //int data; CLR0Entry *pEntry = (CLR0Entry *)(address + 0x3C + (count * 0x10)); ABGRPixel *pData = (ABGRPixel *)(((int)pEntry + count * 0x10)); CLR0 *header = (CLR0 *)address; *header = new CLR0(length, _unk1, _numFrames, count, _unk2); ResourceGroup *group = header->Group; *group = new ResourceGroup(count); ResourceEntry *entry = group->First; foreach (CLR0EntryNode n in Children) { entry->_dataOffset = (int)pEntry - (int)group; if (n._numEntries == 0) { *pEntry = new CLR0Entry(n._flags, (ABGRPixel)n._colorMask, (ABGRPixel)n._solidColor); } //*(RGBAPixel*)&data = (RGBAPixel)n._solidColor; else { *pEntry = new CLR0Entry(n._flags, (ABGRPixel)n._colorMask, (int)pData - ((int)pEntry + 12)); } //data = (int)pData - ((int)pEntry + 12); entry++; pEntry++; foreach (ARGBPixel p in n._colors) { *pData++ = (ABGRPixel)p; } n._changed = false; } }
public override bool OnInitialize() { _colorMask = (ARGBPixel)Header->_colorMask; _colors.Clear(); if (_constant) { _numEntries = 0; _solidColor = (ARGBPixel)Header->SolidColor; } else { _numEntries = ((CLR0Node)Parent.Parent)._numFrames; ABGRPixel *data = Header->Data; for (int i = 0; i < _numEntries; i++) { _colors.Add((ARGBPixel)(*data++)); } } _name = _target.ToString(); return(false); }
private unsafe void Load(int index, int program, PLT0Node palette) { if (_context == null) { return; } Source = null; if (Texture != null) { Texture.Delete(); } Texture = new GLTexture(_context, 0, 0); Texture.Bind(index, program); //ctx._states[String.Format("{0}_TexRef", Name)] = Texture; Bitmap bmp = null; TEX0Node tNode = null; if (_context._states.ContainsKey("_Node_Refs")) { List <ResourceNode> nodes = _context._states["_Node_Refs"] as List <ResourceNode>; List <ResourceNode> searched = new List <ResourceNode>(nodes.Count); foreach (ResourceNode n in nodes) { ResourceNode node = n.RootNode; if (searched.Contains(node)) { continue; } searched.Add(node); //Search node itself first if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null) { Source = tNode; if (palette != null) { bmp = tNode.GetImage(0, palette); } else { bmp = tNode.GetImage(0); } } else { //Then search node directory string path = node._origPath; if (path != null) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif")) { Source = file.FullName; bmp = (Bitmap)Bitmap.FromFile(file.FullName); break; } } } } if (bmp != null) { break; } } searched.Clear(); if (bmp != null) { int w = bmp.Width, h = bmp.Height, size = w * h; Texture._width = w; Texture._height = h; //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureFilter.LINEAR); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0); //if (tNode != null) // _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, tNode.LevelOfDetail); //else // _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, 0); BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); try { using (UnsafeBuffer buffer = new UnsafeBuffer(size << 2)) { ARGBPixel *sPtr = (ARGBPixel *)data.Scan0; ABGRPixel *dPtr = (ABGRPixel *)buffer.Address; for (int i = 0; i < size; i++) { *dPtr++ = (ABGRPixel)(*sPtr++); } int res = _context.gluBuild2DMipmaps(GLTextureTarget.Texture2D, GLInternalPixelFormat._4, w, h, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, buffer.Address); if (res != 0) { } } } finally { bmp.UnlockBits(data); bmp.Dispose(); } } } }
public override void OnRebuild(VoidPtr address, int length, bool force) { int count = Children.Count; CLR0Material *pMat = (CLR0Material *)(address + (_version == 4 ? CLR0v4.Size : CLR0v3.Size) + 0x18 + (count * 0x10)); int offset = Children.Count * 8; foreach (CLR0MaterialNode n in Children) { offset += n.Children.Count * 8; } ABGRPixel *pData = (ABGRPixel *)((VoidPtr)pMat + offset); ResourceGroup *group; if (_version == 4) { CLR0v4 *header = (CLR0v4 *)address; * header = new CLR0v4(length, _numFrames, count, _loop); group = header->Group; } else { CLR0v3 *header = (CLR0v3 *)address; * header = new CLR0v3(length, _numFrames, count, _loop); group = header->Group; } *group = new ResourceGroup(count); ResourceEntry *entry = group->First; foreach (CLR0MaterialNode n in Children) { (entry++)->_dataOffset = (int)pMat - (int)group; uint newFlags = 0; CLR0MaterialEntry *pMatEntry = (CLR0MaterialEntry *)((VoidPtr)pMat + 8); foreach (CLR0MaterialEntryNode e in n.Children) { newFlags |= ((uint)((1 + (e._constant ? 2 : 0)) & 3) << ((int)e._target * 2)); if (e._numEntries == 0) { *pMatEntry = new CLR0MaterialEntry((ABGRPixel)e._colorMask, (ABGRPixel)e._solidColor); } else { *pMatEntry = new CLR0MaterialEntry((ABGRPixel)e._colorMask, (int)pData - (int)((VoidPtr)pMatEntry + 4)); foreach (ARGBPixel p in e._colors) { *pData++ = (ABGRPixel)p; } } pMatEntry++; e._changed = false; } pMat->_flags = newFlags; pMat = (CLR0Material *)pMatEntry; n._changed = false; } if (_userEntries.Count > 0 && _version == 4) { CLR0v4 *header = (CLR0v4 *)address; header->UserData = pData; _userEntries.Write(pData); } }