public void Render(int x, int y) { if (textureID == -1) { return; } GL.BindTexture(TextureTarget.Texture2D, textureID); RHelp.Draw2DBox(x, y, ImgWidth, ImgHeight, 0f); }
public void End() { GL.GetInteger(GetPName.Viewport, Viewport); ScreenWidth = Viewport[2]; ScreenHeight = Viewport[3]; int stamp = Environment.TickCount; GL.Enable(EnableCap.Texture2D); GLHUDBegin(); { foreach (TextItem item in textItems) { int hash = GetItemHash(item); CachedInfo tex = new CachedInfo() { TextureID = -1 }; if (Cache.ContainsKey(hash)) { tex = Cache[hash]; tex.LastUsed = stamp; } else { PrepareText(item); if (item.TextureID != -1) { Cache[hash] = tex = new CachedInfo() { TextureID = item.TextureID, Width = item.ImgWidth, Height = item.ImgHeight, LastUsed = stamp }; } } if (tex.TextureID == -1) { continue; } GL.Color4(item.Color); GL.BindTexture(TextureTarget.Texture2D, tex.TextureID); RHelp.Draw2DBox(item.Box.X, ScreenHeight - item.Box.Y - tex.Height, tex.Width, tex.Height, 0f); } GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); GL.Color4(1f, 1f, 1f, 1f); } GLHUDEnd(); textItems.Clear(); }
public void RenderChat(float time, RenderPass pass) { runningTime += time; if (chatLines.Count == 0) { return; } int c = 0; int expired = 0; screenWidth = Window.Viewport[2]; screenHeight = Window.Viewport[3]; ChatLine[] lines; lock (chatLines) { lines = chatLines.ToArray(); c = lines.Length; for (int i = 0; i < c; i++) { if ((runningTime - lines[i].TimeAdded) > ChatLineTimeOnScreen) { expired++; ChatLine goner = chatLines.Dequeue(); goner.Dispose(); } else { break; } } if (expired > 0) { lines = chatLines.ToArray(); c = lines.Length; } } if (c == 0) { runningTime = 0f; return; } int maxWidth = (int)((float)screenWidth * 0.7f); int actualMaxWidth = 0; int height = 0; for (int i = 0; i < c; i++) { lines[i].PrepareText(maxWidth); if (lines[i].TextWidth > actualMaxWidth) { actualMaxWidth = lines[i].TextWidth; } height += lines[i].TextHeight; } int x = 5; int y = 5; GL.Enable(EnableCap.Texture2D); GL.Color4(ChatBackground); RHelp.Draw2DBox(x, y, actualMaxWidth + 6, height + 10, 1f); for (int i = c - 1; i >= 0; i--) { ChatLine line = lines[i]; OpenTK.Graphics.Color4 color = GetColorForStyle(line.Style); float remain = ChatLineTimeOnScreen - (runningTime - line.TimeAdded); if (remain < ChatLineFade) { color.A = remain / ChatLineFade; } GL.Color4(color); line.Render(x + 3, y + 5); y += line.TextHeight; } GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); GL.Color4(1f, 1f, 1f, 1f); }