public static glpic_t Draw_CachePic(string path) { for (int i = 0; i < menu_numcachepics; i++) { cachepic_t p = menu_cachepics[i]; if (p.name == path)// !strcmp(path, pic->name)) { return(p.pic); } } if (menu_numcachepics == q_shared.MAX_CACHED_PICS) { Sys_Error("menu_numcachepics == MAX_CACHED_PICS"); } cachepic_t pic = menu_cachepics[menu_numcachepics]; menu_numcachepics++; pic.name = path; // // load the pic from disk // byte[] data = COM_LoadFile(path); if (data == null) { Sys_Error("Draw_CachePic: failed to load {0}", path); } dqpicheader_t header = BytesToStructure <dqpicheader_t>(data, 0); game_engine.SwapPic(header); int headerSize = Marshal.SizeOf(typeof(dqpicheader_t)); // HACK HACK HACK --- we need to keep the bytes for // the translatable player picture just for the menu // configuration dialog if (path == "gfx/menuplyr.lmp") { Buffer.BlockCopy(data, headerSize, menuplyr_pixels, 0, header.width * header.height); //memcpy (menuplyr_pixels, dat->data, dat->width*dat->height); } glpic_t gl = new glpic_t(); gl.width = header.width; gl.height = header.height; //gl = (glpic_t *)pic->pic.data; gl.texnum = GL_LoadPicTexture(gl, new ByteArraySegment(data, headerSize)); gl.sl = 0; gl.sh = 1; gl.tl = 0; gl.th = 1; pic.pic = gl; return(gl); }
public static void W_LoadWadFile(string filename) { wad_base = COM_LoadFile(filename); if (wad_base == null) { Sys_Error("Wad.LoadWadFile: couldn't load {0}", filename); } if (_Handle.IsAllocated) { _Handle.Free(); } _Handle = GCHandle.Alloc(wad_base, GCHandleType.Pinned); _DataPtr = _Handle.AddrOfPinnedObject(); wadinfo_t header = BytesToStructure <wadinfo_t>(wad_base, 0); if (header.identification[0] != 'W' || header.identification[1] != 'A' || header.identification[2] != 'D' || header.identification[3] != '2') { Sys_Error("Wad file {0} doesn't have WAD2 id\n", filename); } int numlumps = LittleLong(header.numlumps); int infotableofs = LittleLong(header.infotableofs); int lumpInfoSize = Marshal.SizeOf(typeof(lumpinfo_t)); _Lumps = new Dictionary <string, lumpinfo_t>(numlumps); for (int i = 0; i < numlumps; i++) { IntPtr ptr = new IntPtr(_DataPtr.ToInt64() + infotableofs + i * lumpInfoSize); lumpinfo_t lump = (lumpinfo_t)Marshal.PtrToStructure(ptr, typeof(lumpinfo_t)); lump.filepos = LittleLong(lump.filepos); lump.size = LittleLong(lump.size); if (lump.type == q_shared.TYP_QPIC) { ptr = new IntPtr(_DataPtr.ToInt64() + lump.filepos); dqpicheader_t pic = (dqpicheader_t)Marshal.PtrToStructure(ptr, typeof(dqpicheader_t)); SwapPic(pic); Marshal.StructureToPtr(pic, ptr, true); } _Lumps.Add(Encoding.ASCII.GetString(lump.name).TrimEnd('\0').ToLower(), lump); } }
public static glpic_t Draw_PicFromWad(string name) { int offset = game_engine.W_GetLumpName(name); IntPtr ptr = new IntPtr(game_engine._DataPtr.ToInt64() + offset); dqpicheader_t header = (dqpicheader_t)Marshal.PtrToStructure(ptr, typeof(dqpicheader_t)); glpic_t gl = new glpic_t(); // (glpic_t)Marshal.PtrToStructure(ptr, typeof(glpic_t)); gl.width = header.width; gl.height = header.height; offset += Marshal.SizeOf(typeof(dqpicheader_t)); // load little ones into the scrap if (gl.width < 64 && gl.height < 64) { int x, y; int texnum = Scrap_AllocBlock(gl.width, gl.height, out x, out y); scrap_dirty = true; int k = 0; for (int i = 0; i < gl.height; i++) { for (int j = 0; j < gl.width; j++, k++) { _ScrapTexels[texnum][(y + i) * q_shared.BLOCK_WIDTH + x + j] = game_engine.wad_base[offset + k];// p->data[k]; } } texnum += scrap_texnum; gl.texnum = texnum; gl.sl = (float)((x + 0.01) / (float)q_shared.BLOCK_WIDTH); gl.sh = (float)((x + gl.width - 0.01) / (float)q_shared.BLOCK_WIDTH); gl.tl = (float)((y + 0.01) / (float)q_shared.BLOCK_WIDTH); gl.th = (float)((y + gl.height - 0.01) / (float)q_shared.BLOCK_WIDTH); pic_count++; pic_texels += gl.width * gl.height; } else { gl.texnum = GL_LoadPicTexture(gl, new ByteArraySegment(game_engine.wad_base, offset)); } return(gl); }
public static void Draw_Init() { _ScrapAllocated = new int[q_shared.MAX_SCRAPS][]; for (int i = 0; i < _ScrapAllocated.GetLength(0); i++) { _ScrapAllocated[i] = new int[q_shared.BLOCK_WIDTH]; } _ScrapTexels = new byte[q_shared.MAX_SCRAPS][]; for (int i = 0; i < _ScrapTexels.GetLength(0); i++) { _ScrapTexels[i] = new byte[q_shared.BLOCK_WIDTH * q_shared.BLOCK_HEIGHT * 4]; } for (int i = 0; i < menu_cachepics.Length; i++) { menu_cachepics[i] = new cachepic_t(); } gl_nobind = new cvar_t("gl_nobind", "0"); gl_max_size = new cvar_t("gl_max_size", "1024"); gl_picmip = new cvar_t("gl_picmip", "0"); // 3dfx can only handle 256 wide textures string renderer = GL.GetString(StringName.Renderer); if (renderer.Contains("3dfx") || renderer.Contains("Glide")) { Cvar.Cvar_Set("gl_max_size", "256"); } Cmd_AddCommand("gl_texturemode", Draw_TextureMode_f); // load the console background and the charset // by hand, because we need to write the version // string into the background before turning // it into a texture int offset = game_engine.W_GetLumpName("conchars"); byte[] draw_chars = game_engine.wad_base; // draw_chars for (int i = 0; i < 256 * 64; i++) { if (draw_chars[offset + i] == 0) { draw_chars[offset + i] = 255; // proper transparent color } } // now turn them into textures char_texture = GL_LoadTexture("charset", 128, 128, new ByteArraySegment(draw_chars, offset), false, true); byte[] buf = COM_LoadFile("gfx/conback.lmp"); if (buf == null) { Sys_Error("Couldn't load gfx/conback.lmp"); } dqpicheader_t cbHeader = BytesToStructure <dqpicheader_t>(buf, 0); game_engine.SwapPic(cbHeader); // hack the version number directly into the pic string ver = String.Format("(c# {0,7:F2}) {1,7:F2}", (float)q_shared.CSQUAKE_VERSION, (float)q_shared.VERSION); int offset2 = Marshal.SizeOf(typeof(dqpicheader_t)) + 320 * 186 + 320 - 11 - 8 * ver.Length; int y = ver.Length; for (int x = 0; x < y; x++) { CharToConback(ver[x], new ByteArraySegment(buf, offset2 + (x << 3)), new ByteArraySegment(draw_chars, offset)); } conback = new glpic_t(); conback.width = cbHeader.width; conback.height = cbHeader.height; int ncdataIndex = Marshal.SizeOf(typeof(dqpicheader_t)); // cb->data; SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest); conback.texnum = GL_LoadTexture("conback", conback.width, conback.height, new ByteArraySegment(buf, ncdataIndex), false, false); conback.width = vid.width; conback.height = vid.height; // save a texture slot for translated picture translate_texture = texture_extension_number++; // save slots for scraps scrap_texnum = texture_extension_number; texture_extension_number += q_shared.MAX_SCRAPS; // // get the other pics we need // draw_disc = Draw_PicFromWad("disc"); draw_backtile = Draw_PicFromWad("backtile"); }
public static void SwapPic(dqpicheader_t pic) { pic.width = LittleLong(pic.width); pic.height = LittleLong(pic.height); }