/// <summary> /// Builds or rebuilds the the light sources for the world. /// TODO: Call this whenenver render distance changes! /// </summary> public void BuildLightsForWorld() { if (TheSun != null) { TheSun.Destroy(); MainWorldView.Lights.Remove(TheSun); TheSunClouds.Destroy(); MainWorldView.Lights.Remove(TheSunClouds); ThePlanet.Destroy(); MainWorldView.Lights.Remove(ThePlanet); } View3D.CheckError("Load - World - Deletes"); int wid = CVars.r_shadowquality.ValueI; TheSun = new SkyLight(Location.Zero, MaximumStraightBlockDistance() * 2, SunLightDef, new Location(0, 0, -1), MaximumStraightBlockDistance() * 2 + Chunk.CHUNK_SIZE * 2, false, wid); MainWorldView.Lights.Add(TheSun); View3D.CheckError("Load - World - Sun"); // TODO: Separate cloud quality CVar? TheSunClouds = new SkyLight(Location.Zero, MaximumStraightBlockDistance() * 2, CloudSunLightDef, new Location(0, 0, -1), MaximumStraightBlockDistance() * 2 + Chunk.CHUNK_SIZE * 2, true, wid); MainWorldView.Lights.Add(TheSunClouds); View3D.CheckError("Load - World - Clouds"); // TODO: Separate planet quality CVar? ThePlanet = new SkyLight(Location.Zero, MaximumStraightBlockDistance() * 2, PlanetLightDef, new Location(0, 0, -1), MaximumStraightBlockDistance() * 2 + Chunk.CHUNK_SIZE * 2, false, wid); MainWorldView.Lights.Add(ThePlanet); View3D.CheckError("Load - World - Planet"); OnCloudShadowChanged(null, null); View3D.CheckError("Load - World - Changed"); }
protected override void Render(double delta, int xoff, int yoff) { string tt = Text; if (Clicked) { tt = TextClick; } else if (Hovered) { tt = TextHover; } if (Icon != null) { float x = GetX() + xoff; float y = GetY() + yoff; Icon.Bind(); Client TheClient = GetClient(); TheClient.Rendering.SetColor(IconColor); TheClient.Rendering.RenderRectangle(x, y, x + TextFont.font_default.Height, y + TextFont.font_default.Height); TextFont.DrawColoredText(tt, new Location(x + TextFont.font_default.Height, y, 0), int.MaxValue, 1, false, BColor); TheClient.Rendering.SetColor(OpenTK.Vector4.One); } else { TextFont.DrawColoredText(tt, new Location(GetX() + xoff, GetY() + yoff, 0), int.MaxValue, 1, false, BColor); } View3D.CheckError("RenderScreen - TextLink"); }
protected override void RenderChildren(double delta, int xoff, int yoff) { if (ResetOnRender) { GL.ClearBuffer(ClearBuffer.Color, 0, new float[] { 0f, 0.5f, 0.5f, 1f }); GL.ClearBuffer(ClearBuffer.Depth, 0, new float[] { 1f }); View3D.CheckError("RenderScreen - Reset"); } base.RenderChildren(delta, xoff, yoff); View3D.CheckError("RenderScreen - Children"); }
public void TickInvMenu() { if (CInvMenu != null) { MainItemView.CameraPos = -Forw * 10; MainItemView.ForwardVec = Forw; MainItemView.CameraUp = () => Location.UnitY; // TODO: Should this really be Y? Probably not... View3D temp = MainWorldView; MainWorldView = MainItemView; MainItemView.Render(); MainWorldView = temp; View3D.CheckError("ItemRender"); } }
public void Destroy() { GL.DeleteFramebuffer(fbo); View3D.CheckError("RS4P - Destroy - 0.1"); GL.DeleteTexture(DiffuseTexture); View3D.CheckError("RS4P - Destroy - 0.2"); GL.DeleteTexture(PositionTexture); View3D.CheckError("RS4P - Destroy - 0.3"); GL.DeleteTexture(NormalsTexture); View3D.CheckError("RS4P - Destroy - 0.5"); GL.DeleteTexture(DepthTexture); View3D.CheckError("RS4P - Destroy - 0.6"); GL.DeleteTexture(RenderhintTexture); View3D.CheckError("RS4P - Destroy - 0.7"); GL.DeleteTexture(Rh2Texture); View3D.CheckError("RS4P - Destroy"); }
protected override void Render(double delta, int xoff, int yoff) { string tex = MaxX != null?TextFont.SplitAppropriately(Text, MaxX()) : Text; float bx = GetX() + xoff; float by = GetY() + yoff; if (BackColor.W > 0) { Location meas = TextFont.MeasureFancyLinesOfText(tex); Client TheClient = GetClient(); TheClient.Rendering.SetColor(BackColor); TheClient.Rendering.RenderRectangle(bx, by, bx + (float)meas.X, by + (float)meas.Y); TheClient.Rendering.SetColor(Vector4.One); } TextFont.DrawColoredText(tex, new Location(bx, by, 0), int.MaxValue, 1, false, BColor); View3D.CheckError("RenderScreen - Label"); }
/// <summary> /// Renders a line box. /// </summary> public void RenderLineBox(Location min, Location max, Matrix4d?rot = null) { if (min.IsNaN() || min.IsInfinite() || max.IsNaN() || max.IsInfinite()) { SysConsole.Output(OutputType.WARNING, "Invalid line box from " + min + " to " + max); return; } GL.ActiveTexture(TextureUnit.Texture0); Engine.White.Bind(); View3D.CheckError("RenderLineBox: BindTexture"); Location halfsize = (max - min) / 2; if ((min + halfsize) == Location.Zero) { return; // ??? } if (Math.Abs(min.X + halfsize.X) < 1 || Math.Abs(min.Y + halfsize.Y) < 1 || Math.Abs(min.Z + halfsize.Z) < 1) { return; // ??? } if (Math.Abs(min.X) < 1 || Math.Abs(min.Y) < 1 || Math.Abs(min.Z) < 1) { return; // ??? } if (bbreak) { return; // TODO: Fix! } Matrix4d mat = Matrix4d.Scale(ClientUtilities.ConvertD(halfsize)) * (rot != null && rot.HasValue ? rot.Value : Matrix4d.Identity) * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(min + halfsize)); Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference! View3D.CheckError("RenderLineBox: SetMatrix"); GL.BindVertexArray(Box._VAO); View3D.CheckError("RenderLineBox: Bind VAO"); GL.DrawElements(PrimitiveType.Lines, 24, DrawElementsType.UnsignedInt, IntPtr.Zero); if (View3D.CheckError("RenderLineBox: Pass")) { SysConsole.Output(OutputType.DEBUG, "Caught: " + Box._VAO + ", " + min + ", " + max + ", " + halfsize); } }
// TODO: Merge with base.Render() as much as possible! public override void Render() { View3D.CheckError("Render - Player - Pre"); Location renderrelpos = GetWeldSpot(); if (TheClient.IsMainMenu || !TheClient.CVars.r_drawself.ValueB) { return; } TheClient.SetEnts(); if (TheClient.CVars.n_debugmovement.ValueB) { if (ServerLocation.IsInfinite() || ServerLocation.IsNaN() || renderrelpos.IsInfinite() || renderrelpos.IsNaN()) { SysConsole.Output(OutputType.WARNING, "NaN server data"); } else { TheClient.Rendering.RenderLine(ServerLocation, renderrelpos); View3D.CheckError("Render - Player - Line"); TheClient.Rendering.RenderLineBox(ServerLocation + new Location(-0.2), ServerLocation + new Location(0.2)); if (View3D.CheckError("Render - Player - LineBox")) { SysConsole.Output(OutputType.DEBUG, "Caught: " + (ServerLocation + new Location(-0.2)) + "::: " + (ServerLocation + new Location(0.2))); } } } if (TheClient.VR != null) { return; } View3D.CheckError("Render - Player - 0"); OpenTK.Matrix4d mat = OpenTK.Matrix4d.Scale(1.5f) * OpenTK.Matrix4d.CreateRotationZ((Direction.Yaw * Utilities.PI180)) * PlayerAngleMat * OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); TheClient.Rendering.SetMinimumLight(0.0f); model.CustomAnimationAdjustments = new Dictionary <string, OpenTK.Matrix4>(SavedAdjustmentsOTK) { // TODO: safe (no-collision) rotation check? { "spine04", GetAdjustmentOTK("spine04") * OpenTK.Matrix4.CreateRotationX(-(float)(Direction.Pitch / 2f * Utilities.PI180)) } }; View3D.CheckError("Render - Player - 1"); if (!TheClient.MainWorldView.RenderingShadows && TheClient.CVars.g_firstperson.ValueB) { model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01") * OpenTK.Matrix4.CreateRotationX(-(float)(160f * Utilities.PI180)); } else { model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01"); } model.Draw(aHTime, hAnim, aTTime, tAnim, aLTime, lAnim); Model mod = TheClient.GetItemForSlot(TheClient.QuickBarPos).Mod; bool hasjp = HasJetpack(); View3D.CheckError("Render - Player - 2"); if (!hasjp && tAnim != null && mod != null) { mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments); // TODO: Logic of this rotation math? Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; SingleAnimationNode hand = tAnim.GetNode("metacarpal2.r"); Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f) * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f)) * hand.GetBoneTotalMatrix(aTTime, adjs)) * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-90) * Utilities.PI180) % 360f)); OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24, (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44); GL.UniformMatrix4(100, false, ref bonemat); mod.LoadSkin(TheClient.Textures); mod.Draw(); bonemat = OpenTK.Matrix4.Identity; GL.UniformMatrix4(100, false, ref bonemat); } View3D.CheckError("Render - Player - 3"); if (hasjp) { // TODO: Abstractify! Model jetp = GetHeldItem().Mod; mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(); Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; SingleAnimationNode spine = tAnim.GetNode("spine04"); Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f) * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f)) * spine.GetBoneTotalMatrix(aTTime, adjs)) * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)((90) * Utilities.PI180) % 360f)); OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24, (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44); GL.UniformMatrix4(100, false, ref bonemat); jetp.LoadSkin(TheClient.Textures); jetp.Draw(); bonemat = OpenTK.Matrix4.Identity; GL.UniformMatrix4(100, false, ref bonemat); } View3D.CheckError("Render - Player - 4"); if (IsTyping) { TheClient.Textures.GetTexture("ui/game/typing").Bind(); // TODO: store! TheClient.Rendering.RenderBillboard(renderrelpos + new Location(0, 0, 4), new Location(2), TheClient.MainWorldView.CameraPos); } View3D.CheckError("Render - Player - Post"); }
/// <summary> /// Called when the window is loading, only to be used by the startup process. /// </summary> void Window_Load(object sender, EventArgs e) { SysConsole.Output(OutputType.INIT, "Window generated!"); DPIScale = Window.Width / CVars.r_width.ValueF; SysConsole.Output(OutputType.INIT, "DPIScale is " + DPIScale + "!"); SysConsole.Output(OutputType.INIT, "Loading base textures..."); PreInitRendering(); Textures = new TextureEngine(); Textures.InitTextureSystem(this); ItemFrame = Textures.GetTexture("ui/hud/item_frame"); SysConsole.Output(OutputType.INIT, "Loading shaders..."); Shaders = new ShaderEngine(); GLVendor = GL.GetString(StringName.Vendor); CVars.s_glvendor.Value = GLVendor; GLVersion = GL.GetString(StringName.Version); CVars.s_glversion.Value = GLVersion; GLRenderer = GL.GetString(StringName.Renderer); CVars.s_glrenderer.Value = GLRenderer; SysConsole.Output(OutputType.INIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer); if (GLVendor.ToLowerFast().Contains("intel")) { SysConsole.Output(OutputType.INIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')"); Shaders.MCM_GOOD_GRAPHICS = false; } Shaders.InitShaderSystem(this); View3D.CheckError("Load - Shaders"); SysConsole.Output(OutputType.INIT, "Loading rendering helper..."); Rendering = new Renderer(Textures, Shaders); Rendering.Init(); SysConsole.Output(OutputType.INIT, "Preparing load screen..."); Texture load_screen = Textures.GetTexture("ui/menus/loadscreen"); load_screen.Bind(); Shaders.ColorMultShader.Bind(); Establish2D(); Rendering.RenderRectangle(0, 0, Window.Width, Window.Height); Window.SwapBuffers(); SysConsole.Output(OutputType.INIT, "Loading block textures..."); TBlock = new TextureBlock(); TBlock.Generate(this, CVars, Textures); View3D.CheckError("Load - Textures"); SysConsole.Output(OutputType.INIT, "Loading fonts..."); Fonts = new GLFontEngine(Shaders); Fonts.Init(this); FontSets = new FontSetEngine(Fonts); FontSets.Init(this); View3D.CheckError("Load - Fonts"); SysConsole.Output(OutputType.INIT, "Loading animation engine..."); Animations = new AnimationEngine(); SysConsole.Output(OutputType.INIT, "Loading model engine..."); Models = new ModelEngine(); Models.Init(Animations, this); SysConsole.Output(OutputType.INIT, "Loading general graphics settings..."); CVars.r_vsync.OnChanged += onVsyncChanged; onVsyncChanged(CVars.r_vsync, null); CVars.r_cloudshadows.OnChanged += onCloudShadowChanged; View3D.CheckError("Load - General Graphics"); SysConsole.Output(OutputType.INIT, "Loading UI engine..."); UIConsole.InitConsole(); // TODO: make this non-static InitChatSystem(); View3D.CheckError("Load - UI"); SysConsole.Output(OutputType.INIT, "Preparing rendering engine..."); InitRendering(); View3D.CheckError("Load - Rendering"); SysConsole.Output(OutputType.INIT, "Loading particle effect engine..."); Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) }; SysConsole.Output(OutputType.INIT, "Preparing mouse, keyboard, and gamepad handlers..."); KeyHandler.Init(); GamePadHandler.Init(); View3D.CheckError("Load - Keyboard/mouse"); SysConsole.Output(OutputType.INIT, "Building the sound system..."); Sounds = new SoundEngine(); Sounds.Init(this, CVars); View3D.CheckError("Load - Sound"); SysConsole.Output(OutputType.INIT, "Building game world..."); BuildWorld(); View3D.CheckError("Load - World"); SysConsole.Output(OutputType.INIT, "Preparing networking..."); Network = new NetworkBase(this); RegisterDefaultEntityTypes(); View3D.CheckError("Load - Net"); SysConsole.Output(OutputType.INIT, "Playing background music..."); BackgroundMusic(); CVars.a_musicvolume.OnChanged += onMusicVolumeChanged; CVars.a_musicpitch.OnChanged += onMusicPitchChanged; CVars.a_music.OnChanged += onMusicChanged; CVars.a_echovolume.OnChanged += OnEchoVolumeChanged; OnEchoVolumeChanged(null, null); SysConsole.Output(OutputType.INIT, "Setting up screens..."); TheMainMenuScreen = new MainMenuScreen(this); TheGameScreen = new GameScreen(this); TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this); SysConsole.Output(OutputType.INIT, "Preparing inventory..."); InitInventory(); SysConsole.Output(OutputType.INIT, "Showing main menu..."); ShowMainMenu(); SysConsole.Output(OutputType.INIT, "Trying to grab RawGamePad..."); try { RawGamePad = new XInput(); } catch (Exception ex) { SysConsole.Output(OutputType.INIT, "Failed to grab RawGamePad: " + ex.Message); } View3D.CheckError("Load - Final"); SysConsole.Output(OutputType.INIT, "Ready and looping!"); }
public void Generate(Client tclient, ClientCVar cvars, TextureEngine eng, bool delayable) { TheClient = tclient; if (Anims != null) { for (int i = 0; i < Anims.Count; i++) { Anims[i].Destroy(); } } if (TextureID > -1) { GL.DeleteTexture(TextureID); GL.DeleteTexture(NormalTextureID); GL.DeleteTexture(HelpTextureID); } Anims = new List <AnimatedTexture>(); TEngine = eng; TextureID = GL.GenTexture(); TWidth = cvars.r_blocktexturewidth.ValueI; GL.BindTexture(TextureTarget.Texture2DArray, TextureID); int levels = TheClient.CVars.r_block_mipmaps.ValueB ? 4 : 1; GL.TexStorage3D(TextureTarget3d.Texture2DArray, levels, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMinFilter.Linear: TextureMinFilter.Nearest)); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMagFilter.Linear : TextureMagFilter.Nearest)); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); HelpTextureID = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID); GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); NormalTextureID = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID); GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); // TODO: Use normal.a! List <MaterialTextureInfo> texs = new List <MaterialTextureInfo>(MaterialHelpers.Textures.Length); IntTexs = new string[MaterialHelpers.Textures.Length]; for (int ia = 0; ia < MaterialHelpers.Textures.Length; ia++) { int i = ia; Action a = () => { MaterialTextureInfo tex = new MaterialTextureInfo() { Mat = (Material)i }; string[] refrornot = MaterialHelpers.Textures[i].SplitFast('@'); if (refrornot.Length > 1) { string[] rorn = refrornot[1].SplitFast('%'); if (rorn.Length > 1) { tex.RefrRate = Utilities.StringToFloat(rorn[1]); } tex.RefractTextures = rorn[0].SplitFast(','); } string[] glowornot = refrornot[0].SplitFast('!'); if (glowornot.Length > 1) { tex.GlowingTextures = glowornot[1].SplitFast(','); } string[] reflornot = glowornot[0].SplitFast('*'); if (reflornot.Length > 1) { tex.ReflectTextures = reflornot[1].SplitFast(','); } string[] specularornot = reflornot[0].SplitFast('&'); if (specularornot.Length > 1) { tex.SpecularTextures = specularornot[1].SplitFast(','); } string[] normalornot = specularornot[0].SplitFast('$'); GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID); if (normalornot.Length > 1) { string[] rorn = normalornot[1].SplitFast('%'); if (rorn.Length > 1) { tex.NormRate = Utilities.StringToFloat(rorn[1]); } tex.NormalTextures = rorn[0].SplitFast(','); SetTexture((int)tex.Mat, tex.NormalTextures[0]); if (tex.NormalTextures.Length > 1) { SetAnimated((int)tex.Mat, tex.NormRate, tex.NormalTextures, NormalTextureID); } } else { SetTexture((int)tex.Mat, "normal_def"); } string[] rateornot = normalornot[0].SplitFast('%'); if (rateornot.Length > 1) { tex.Rate = Utilities.StringToFloat(rateornot[1]); } tex.Textures = rateornot[0].SplitFast(','); GL.BindTexture(TextureTarget.Texture2DArray, TextureID); SetTexture((int)tex.Mat, tex.Textures[0]); if (tex.Textures.Length > 1) { SetAnimated((int)tex.Mat, tex.Rate, tex.Textures, TextureID); } texs.Add(tex); IntTexs[(int)tex.Mat] = tex.Textures[0]; if (!delayable) { TheClient.PassLoadScreen(); } }; if (delayable) { TheClient.Schedule.ScheduleSyncTask(a, i * LoadRate); } else { a(); } } double time = (MaterialHelpers.Textures.Length + 1) * LoadRate; if (TheClient.CVars.r_block_mipmaps.ValueB) { Action mipmap = () => { GL.BindTexture(TextureTarget.Texture2DArray, TextureID); GL.GenerateMipmap(GenerateMipmapTarget.Texture2DArray); View3D.CheckError("Mipmapping"); }; if (delayable) { TheClient.Schedule.ScheduleSyncTask(mipmap, time); } else { mipmap(); } } for (int ia = 0; ia < texs.Count; ia++) { int i = ia; Action a = () => { GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID); Bitmap combo = GetCombo(texs[i], 0); TEngine.LockBitmapToTexture(combo, (int)texs[i].Mat); if ((texs[i].SpecularTextures != null) && (texs[i].ReflectTextures != null) && (texs[i].RefractTextures != null) && (texs[i].GlowingTextures != null) && texs[i].SpecularTextures.Length > 1) { Bitmap[] bmps = new Bitmap[texs[i].SpecularTextures.Length]; bmps[0] = combo; for (int x = 1; x < bmps.Length; x++) { bmps[x] = GetCombo(texs[i], x); } SetAnimated((int)texs[i].Mat, texs[i].RefrRate, bmps, HelpTextureID); for (int x = 1; x < bmps.Length; x++) { bmps[x].Dispose(); } } combo.Dispose(); if (!delayable) { TheClient.PassLoadScreen(); } }; if (delayable) { TheClient.Schedule.ScheduleSyncTask(a, time + i * LoadRate); } else { a(); } } GL.BindTexture(TextureTarget.Texture2DArray, 0); GL.BindTexture(TextureTarget.Texture2DArray, 0); }
/// <summary> /// Called when the window is loading, only to be used by the startup process. /// </summary> void Window_Load(object sender, EventArgs e) { SysConsole.Output(OutputType.CLIENTINIT, "Window generated!"); DPIScale = Window.Width / CVars.r_width.ValueF; SysConsole.Output(OutputType.CLIENTINIT, "DPIScale is " + DPIScale + "!"); SysConsole.Output(OutputType.CLIENTINIT, "Loading base textures..."); PreInitRendering(); Textures = new TextureEngine(); Textures.InitTextureSystem(Files); ItemFrame = Textures.GetTexture("ui/hud/item_frame"); SysConsole.Output(OutputType.CLIENTINIT, "Loading shaders..."); Shaders = new ShaderEngine(); GLVendor = GL.GetString(StringName.Vendor); CVars.s_glvendor.Value = GLVendor; GLVersion = GL.GetString(StringName.Version); CVars.s_glversion.Value = GLVersion; GLRenderer = GL.GetString(StringName.Renderer); CVars.s_glrenderer.Value = GLRenderer; SysConsole.Output(OutputType.CLIENTINIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer); if (GLVendor.ToLowerFast().Contains("intel")) { SysConsole.Output(OutputType.CLIENTINIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')"); Shaders.MCM_GOOD_GRAPHICS = false; } Shaders.InitShaderSystem(Files); View3D.CheckError("Load - Shaders"); SysConsole.Output(OutputType.CLIENTINIT, "Loading rendering helper..."); Rendering = new Renderer(Textures, Shaders); Rendering.Init(); SysConsole.Output(OutputType.CLIENTINIT, "Preparing load screen..."); load_screen = Textures.GetTexture("ui/menus/loadscreen"); Establish2D(); SWLoading.Start(); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Loading block textures..."); TBlock = new TextureBlock(); TBlock.Generate(this, CVars, Textures, false); View3D.CheckError("Load - Textures"); SysConsole.Output(OutputType.CLIENTINIT, "Loading fonts..."); Fonts = new GLFontEngine(Shaders); Fonts.Init(Files); FontSets = new FontSetEngine(Fonts); FontSets.Init((subdat) => Languages.GetText(Files, subdat), () => Ortho, () => GlobalTickTimeLocal); View3D.CheckError("Load - Fonts"); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Loading animation engine..."); Animations = new AnimationEngine(); SysConsole.Output(OutputType.CLIENTINIT, "Loading model engine..."); Models = new ModelEngine(); Models.Init(Animations, this); LODHelp = new ModelLODHelper(this); SysConsole.Output(OutputType.CLIENTINIT, "Loading general graphics settings..."); CVars.r_vsync.OnChanged += OnVsyncChanged; OnVsyncChanged(CVars.r_vsync, null); CVars.r_cloudshadows.OnChanged += OnCloudShadowChanged; View3D.CheckError("Load - General Graphics"); SysConsole.Output(OutputType.CLIENTINIT, "Loading UI engine..."); UIConsole.InitConsole(); // TODO: make this non-static InitChatSystem(); PassLoadScreen(); View3D.CheckError("Load - UI"); SysConsole.Output(OutputType.CLIENTINIT, "Preparing rendering engine..."); InitRendering(); View3D.CheckError("Load - Rendering"); SysConsole.Output(OutputType.CLIENTINIT, "Loading particle effect engine..."); Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) }; SysConsole.Output(OutputType.CLIENTINIT, "Preparing mouse, keyboard, and gamepad handlers..."); KeyHandler.Init(); GamePadHandler.Init(); PassLoadScreen(); View3D.CheckError("Load - Keyboard/mouse"); SysConsole.Output(OutputType.CLIENTINIT, "Building the sound system..."); Sounds = new SoundEngine(); Sounds.Init(this, CVars); View3D.CheckError("Load - Sound"); SysConsole.Output(OutputType.CLIENTINIT, "Building game world..."); BuildWorld(); PassLoadScreen(); View3D.CheckError("Load - World"); SysConsole.Output(OutputType.CLIENTINIT, "Preparing networking..."); Network = new NetworkBase(this); RegisterDefaultEntityTypes(); View3D.CheckError("Load - Net"); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Playing background music..."); BackgroundMusic(); CVars.a_musicvolume.OnChanged += OnMusicVolumeChanged; CVars.a_musicpitch.OnChanged += OnMusicPitchChanged; CVars.a_music.OnChanged += OnMusicChanged; CVars.a_echovolume.OnChanged += OnEchoVolumeChanged; OnEchoVolumeChanged(null, null); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Setting up screens..."); TheMainMenuScreen = new MainMenuScreen(this); TheGameScreen = new GameScreen(this); TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this); TheLoadScreen = new LoadScreen(this); CScreen = TheMainMenuScreen; SysConsole.Output(OutputType.CLIENTINIT, "Trying to grab RawGamePad..."); try { RawGamePad = new XInput(); } catch (Exception ex) { SysConsole.Output(OutputType.CLIENTINIT, "Failed to grab RawGamePad: " + ex.Message); } SysConsole.Output(OutputType.CLIENTINIT, "Preparing inventory..."); InitInventory(); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Requesting a menu server..."); LocalServer?.ShutDown(); LocalServer = new Server(28009) { IsMenu = true }; // TODO: Grab first free port? Object locky = new Object(); bool ready = false; Schedule.StartAsyncTask(() => { LocalServer.StartUp("menu", () => { lock (locky) { ready = true; } }); }); while (true) { lock (locky) { if (ready) { break; } } PassLoadScreen(); Thread.Sleep(50); } SysConsole.Output(OutputType.CLIENTINIT, "Connecting to a menu server..."); Network.LastConnectionFailed = false; Network.Connect("localhost", "28009", true, null); // TODO: Grab accurate local IP? Stopwatch sw = new Stopwatch(); sw.Start(); bool annc = false; while (true) { if (Network.LastConnectionFailed) { SysConsole.Output(OutputType.CLIENTINIT, "Failed to connect to menu server! Failing!"); Window.Close(); return; } if (Network.IsAlive) { break; } sw.Stop(); long ms = sw.ElapsedMilliseconds; sw.Start(); if (ms > 5000 && !annc) { annc = true; SysConsole.Output(OutputType.WARNING, "Taking weirdly long, did something fail?!"); } if (ms > 10000) { SysConsole.Output(OutputType.CLIENTINIT, "Timed out while trying to connect to menu server! Failing!"); Window.Close(); return; } PassLoadScreen(); Thread.Sleep(50); } SysConsole.Output(OutputType.CLIENTINIT, "Showing main menu..."); ShowMainMenu(); View3D.CheckError("Load - Final"); SysConsole.Output(OutputType.CLIENTINIT, "Ready and looping!"); }
public void Render(double mind, double maxd) { View3D.CheckError("Rendering - Particles - Pre"); if (TheClient.MainWorldView.FBOid == FBOID.FORWARD_TRANSP || TheClient.MainWorldView.FBOid.IsMainTransp() || (TheClient.MainWorldView.FBOid == FBOID.DYNAMIC_SHADOWS && TheClient.MainWorldView.TranspShadows)) { double mindsq = mind * mind; double maxdsq = maxd * maxd; View3D.CheckError("Rendering - Particles - PreFX"); List <Vector3> pos = new List <Vector3>(); List <Vector4> col = new List <Vector4>(); List <Vector2> tcs = new List <Vector2>(); // TODO: If this gets too big, try to async it? Parallel.ForEach or similar could speed it up, in that situation! Would require a logic adjustment though. for (int i = 0; i < ActiveEffects.Count; i++) { if (ActiveEffects[i].Type == ParticleEffectType.SQUARE) { double dist = ActiveEffects[i].Start(ActiveEffects[i]).DistanceSquared(TheClient.MainWorldView.CameraPos); if (dist < mindsq || dist >= maxdsq) { continue; } Tuple <Location, Vector4, Vector2> dets = ActiveEffects[i].GetDetails(); if (dets != null) { pos.Add(ClientUtilities.Convert(dets.Item1 - TheClient.MainWorldView.CameraPos)); if (TheClient.MainWorldView.FBOid == FBOID.FORWARD_TRANSP) { col.Add(Vector4.Min(dets.Item2, Vector4.One)); } else { col.Add(dets.Item2); } tcs.Add(dets.Item3); } } else { ActiveEffects[i].Render(); // TODO: Deprecate / remove / fully replace!? } if (ActiveEffects[i].TTL <= 0) { ActiveEffects[i].OnDestroy?.Invoke(ActiveEffects[i]); ActiveEffects.RemoveAt(i--); } } View3D.CheckError("Rendering - Particles - PreClouds"); if (TheClient.CVars.r_clouds.ValueB) { int cloudID = GetTextureID("effects/clouds/cloud2"); // TODO: Cache! List <Task> tasks = new List <Task>(TheClient.TheRegion.Clouds.Count); // This could be an array. List <ParticleData> datas = new List <ParticleData>(tasks.Capacity); foreach (Cloud tcl in TheClient.TheRegion.Clouds) { Cloud cloud = tcl; ParticleData pd = new ParticleData(); datas.Add(pd); tasks.Add(Task.Factory.StartNew(() => { pd.Poses = new Vector3[cloud.Points.Count]; pd.Cols = new Vector4[cloud.Points.Count]; pd.TCs = new Vector2[cloud.Points.Count]; for (int i = 0; i < cloud.Points.Count; i++) { Location ppos = (cloud.Position + cloud.Points[i]) - TheClient.MainWorldView.CameraPos; double dist = ppos.DistanceSquared(TheClient.MainWorldView.CameraPos); if (dist < mindsq || dist >= maxdsq) { // TODO: Fix this. List? -> continue; } pd.Poses[i] = ClientUtilities.Convert(ppos); pd.Cols[i] = Vector4.One; // TODO: Colored clouds? pd.TCs[i] = new Vector2(cloud.Sizes[i], cloudID); } })); } int count = pos.Count; for (int i = 0; i < tasks.Count; i++) { tasks[i].Wait(); pos.AddRange(datas[i].Poses); col.AddRange(datas[i].Cols); tcs.AddRange(datas[i].TCs); } View3D.CheckError("Rendering - Particles - PostClouds"); } if (TheClient.MainWorldView.FBOid == FBOID.FORWARD_TRANSP) { TheClient.s_forw_particles = TheClient.s_forw_particles.Bind(); GL.Uniform4(4, new Vector4(TheClient.MainWorldView.Width, TheClient.MainWorldView.Height, TheClient.CVars.r_znear.ValueF, TheClient.ZFar())); GL.Uniform1(6, (float)TheClient.GlobalTickTimeLocal); GL.Uniform4(12, new Vector4(ClientUtilities.Convert(TheClient.MainWorldView.FogCol), TheClient.MainWorldView.FogAlpha)); GL.Uniform1(13, TheClient.CVars.r_znear.ValueF); GL.Uniform1(14, TheClient.ZFar()); } else if (TheClient.MainWorldView.FBOid == FBOID.DYNAMIC_SHADOWS) { TheClient.s_shadow_parts = TheClient.s_shadow_parts.Bind(); } else { // TODO: From FBOid if (TheClient.CVars.r_transpshadows.ValueB && TheClient.CVars.r_shadows.ValueB) { if (TheClient.CVars.r_transpll.ValueB) { TheClient.s_transponlylitsh_ll_particles = TheClient.s_transponlylitsh_ll_particles.Bind(); } else { TheClient.s_transponlylitsh_particles = TheClient.s_transponlylitsh_particles.Bind(); } } else { if (TheClient.CVars.r_transpll.ValueB) { TheClient.s_transponlylit_ll_particles = TheClient.s_transponlylit_ll_particles.Bind(); } else { TheClient.s_transponlylit_particles = TheClient.s_transponlylit_particles.Bind(); } } GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, TheClient.MainWorldView.RS4P.DepthTexture); } View3D.CheckError("Rendering - Particles - 1"); GL.UniformMatrix4(1, false, ref TheClient.MainWorldView.PrimaryMatrix); Matrix4 ident = Matrix4.Identity; GL.UniformMatrix4(2, false, ref ident); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2DArray, TextureID); Vector3[] posset = pos.ToArray(); Vector4[] colorset = col.ToArray(); Vector2[] texcoords = tcs.ToArray(); uint[] posind = new uint[posset.Length]; for (uint i = 0; i < posind.Length; i++) { posind[i] = i; } View3D.CheckError("Rendering - Particles - 2"); Part_C = posind.Length; GL.BindBuffer(BufferTarget.ArrayBuffer, Part_VBO_Pos); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(posset.Length * OpenTK.Vector3.SizeInBytes), posset, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, Part_VBO_Tcs); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(texcoords.Length * OpenTK.Vector2.SizeInBytes), texcoords, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, Part_VBO_Col); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(colorset.Length * OpenTK.Vector4.SizeInBytes), colorset, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ElementArrayBuffer, Part_VBO_Ind); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(posind.Length * sizeof(uint)), posind, BufferUsageHint.StaticDraw); GL.BindVertexArray(Part_VAO); if (!prepped) { GL.BindBuffer(BufferTarget.ArrayBuffer, Part_VBO_Pos); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(0); GL.BindBuffer(BufferTarget.ArrayBuffer, Part_VBO_Tcs); GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(2); GL.BindBuffer(BufferTarget.ArrayBuffer, Part_VBO_Col); GL.VertexAttribPointer(4, 4, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(4); GL.BindBuffer(BufferTarget.ElementArrayBuffer, Part_VBO_Ind); prepped = true; } GL.DrawElements(PrimitiveType.Points, Part_C, DrawElementsType.UnsignedInt, IntPtr.Zero); GL.BindVertexArray(0); TheClient.isVox = true; TheClient.SetEnts(); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, 0); View3D.CheckError("Rendering - Particles - 3"); } }
public void RenderLoader(float x, float y, float size, double delta) { RenderLoadIconV2(x, y, size, delta); View3D.CheckError("RenderLoader"); }