public void render(float partialTicks) { if (camera == null) { return; } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); prepare(); var viewMatrix = MatrixHelper.createViewMatrix(camera); if (Game.INSTANCE.world != null) { worldRenderer.render(viewMatrix); entityRenderer.render(partialTicks); skyboxRenderer.render(viewMatrix); } //render other gui if (Game.INSTANCE.player != null) { guiRenderer.renderCrosshair(); guiRenderer.renderHUD(); } //render gui screen if (Game.INSTANCE.guiScreen != null) { Game.INSTANCE.CursorVisible = true; guiRenderer.render(Game.INSTANCE.guiScreen); } }
private void _ClearTexture(COGLTexture texture) { if (texture.DataSize.Equals(texture.Size)) { return; } GL.BindFramebuffer(OpenTK.Graphics.OpenGL.FramebufferTarget.Framebuffer, _FBO); GL.FramebufferTexture2D(OpenTK.Graphics.OpenGL.FramebufferTarget.Framebuffer, OpenTK.Graphics.OpenGL.FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, texture.Name, 0); GL.ClearColor(Color.FromArgb(0)); GL.Clear(ClearBufferMask.ColorBufferBit); GL.ClearColor(Color.Black); GL.BindFramebuffer(OpenTK.Graphics.OpenGL.FramebufferTarget.Framebuffer, 0); }
protected override void OnRenderFrame(FrameEventArgs args) { GL.Clear(ClearBufferMask.ColorBufferBit); Shader.Use(); #region Coloring var timeValue = _timer.Elapsed.TotalSeconds; GetColor(ref _greenValue, ref _redValue, ref _blueValue, ref timeValue); var vertexColorLocation = GL.GetUniformLocation(Shader.Handle, "ourColor"); GL.Uniform4(vertexColorLocation, _redValue, _greenValue, _blueValue, 1.0f); #endregion GL.BindVertexArray(VertexArrayObject); GL.DrawArrays(PrimitiveType.Triangles, 0, 3); SwapBuffers(); base.OnRenderFrame(args); }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.CullFace(CullFaceMode.Back); GL.FrontFace(FrontFaceDirection.Ccw); GL.Enable(EnableCap.DepthTest); GL.ClearColor(Color.FromArgb(0, 0, 138)); GL.MatrixMode(MatrixMode.Modelview); GL.Enable(EnableCap.Fog); GL.Fog(FogParameter.FogMode, (int)FogMode.Linear); GL.Fog(FogParameter.FogColor, new float[] { 0.5f, 0.5f, 0.5f, 1.0f }); GL.Fog(FogParameter.FogDensity, 2000f); GL.Hint(HintTarget.FogHint, HintMode.Nicest); GL.Fog(FogParameter.FogStart, 1.0f); GL.Fog(FogParameter.FogEnd, 4000.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); camera.LoadMatrix(); RenderObjects(); SwapBuffers(); }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); #if TEST #else GL.Clear(TK.ClearBufferMask.DepthBufferBit | TK.ClearBufferMask.ColorBufferBit); if (ortho) { modelView = Matrix4.CreateOrthographic(width, height, -height, height); GL.MatrixMode(TK.MatrixMode.Projection); GL.PushMatrix(); GL.LoadMatrix(ref modelView); GL.Scale(scale_factor, scale_factor, scale_factor); } else { modelView = Matrix4.LookAt(eye, target, up); GL.MatrixMode(TK.MatrixMode.Modelview); GL.PushMatrix(); GL.LoadMatrix(ref modelView); } GL.PushMatrix(); GL.Rotate(offsetX, 0.0f, 1.0f, 0.0f); GL.Rotate(offsetY, 1.0f, 0.0f, 0.0f); DrawGrid(); #region Draw 3D Polyhedrons GL.Color3(0.0, 0.5, 1.0); GL.Enable(TK.EnableCap.Light0); GL.Enable(TK.EnableCap.Lighting); int i = 0; foreach (Body body in bodies) { float[] color = colors[i % colors.Count()]; color[3] = 0.9f; GL.Color4(color); body.Draw(); color[3] = 0.25f; GL.Color4(color); body.getBSphere().Draw(); i++; } if (picked != -1) { GL.Color3(colors[picked % colors.Count()]); GL.PolygonMode(TK.MaterialFace.FrontAndBack, TK.PolygonMode.Line); foreach (Body body in bodies.ElementAt(picked).getBSphere().cells) { body.Draw(); } GL.PolygonMode(TK.MaterialFace.FrontAndBack, TK.PolygonMode.Fill); } GL.Disable(TK.EnableCap.Lighting); GL.Disable(TK.EnableCap.Light0); #endregion #region Draw Gizmos drawCollisionIntervals(); #endregion GL.PopMatrix(); GL.PopMatrix(); SwapBuffers(); showFPS(); //showInfo(); #endif }
static void Main() { Console.WriteLine("Entering"); using (var game = new GameWindow(1920, 1080, new GraphicsMode(ColorFormat.Empty, 8, 0, 6), "Heart of Gold", GameWindowFlags.Default)) { game.Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location); var size = 500; var zoom = 1.0; game.Load += (sender, e) => { game.VSync = VSyncMode.On; GL.PointSize(10); }; game.MouseWheel += delegate(object sender, MouseWheelEventArgs args) { if (args.Delta > 0) { zoom *= 1.1; } //zoom += args.Delta/10.0; else { zoom /= 1.1; } //zoom += args.Delta/10.0; if (zoom <= 0.1) { zoom = 0.1; } //var aspect = game.Width / (double)game.Height; //GL.Viewport(0, 0, game.Width, game.Height); //GL.Ortho(-xsize, xsize, ysize, -ysize, 0, 4.0); }; game.Resize += (sender, e) => GL.Viewport(0, 0, game.Width, game.Height); #region Heights var matrix = new double[size, size]; //var r = new Random(); #endregion #region Color Console.WriteLine("Initializing color..."); var cmatrix = new Color[size, size]; using (var b = (Bitmap)Image.FromFile(@"E:\Downloads\Untitled5.png")) { for (var i = 0; i < size; i++) { Console.Write($"\rOn column {i,4} of {size}"); for (var j = 0; j < size; j++) { matrix[i, j] = ((double)b.GetPixel(i, j).A + 1); // / 8.0; cmatrix[i, j] = Color.FromArgb(255, b.GetPixel(i, j)); } } } Console.WriteLine(); #endregion bool wDown = false, aDown = false, sDown = false, dDown = false; game.KeyDown += (sender, args) => { switch (args.Key) { case Key.W: wDown = true; break; case Key.A: aDown = true; break; case Key.S: sDown = true; break; case Key.D: dDown = true; break; } }; var translate = Vector2.Zero; game.KeyUp += (sender, args) => { switch (args.Key) { case Key.Escape: game.Exit(); break; case Key.R: zoom = 1; break; case Key.W: if (wDown) { translate += new Vector2(1f, 1f); } wDown = false; break; case Key.A: if (aDown) { translate += new Vector2(1f, -1f); } aDown = false; break; case Key.S: if (sDown) { translate += new Vector2(-1f, -1f); } sDown = false; break; case Key.D: if (dDown) { translate += new Vector2(-1f, 1f); } dDown = false; break; } }; double time = 0, sin = 0; game.UpdateFrame += (sender, e) => { time += e.Time; sin = (Math.Sin(time / 4) + 1) / 2; game.Title = $"Heart of Gold - {game.RenderFrequency:000.00}fps - {game.UpdateFrequency:000.00}tps"; }; var items = new List <BufferElement>(size * size * 12); Console.WriteLine("Prepping buffer elements..."); //First half var side = matrix.GetLength(0); var half = side / 2; for (var i = 0; i < side; i++) { Console.Write($"\rCreating row {i,4} of {side}"); int x = i, y = 0; while (x >= 0) { var hasleft = y != side - 1; var hasright = x != side - 1; var left = hasleft ? (double?)matrix[x, y + 1] : -2; var right = hasright ? (double?)matrix[x + 1, y] : -2; items.AddRange(AddOne(matrix[x, y], x - half, y - half, cmatrix[x--, y++], left, right)); } } // Pt 2 for (var i = 1; i <= side - 1; i++) { Console.Write($"\rCreating column {i,4} of {side}"); int x = side - 1, y = i; while (y < side) { var hasleft = y != side - 1; var hasright = x != side - 1; var left = hasleft ? (double?)matrix[x, y + 1] : -2; var right = hasright ? (double?)matrix[x + 1, y] : -2; items.AddRange(AddOne(matrix[x, y], x - half, y - half, cmatrix[x--, y++], left, right)); } } Console.WriteLine("\rCreating vertex buffer object... "); Action a = delegate { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.VertexPointer(3, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0)); GL.ColorPointer(3, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector3.SizeInBytes)); }; var terrain = new VertexBuffer <BufferElement>(items.ToArray(), a, BufferUsageHint.StaticDraw); Console.WriteLine("Done!"); game.RenderFrame += delegate { // render graphics GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(size, -size, size, -size, -double.MaxValue, double.MaxValue); GL.Scale(1 * zoom, (game.Width / (double)game.Height) * zoom, 1 * zoom); GL.Rotate(90 * sin, 1, 0, 0); GL.Rotate(45, 0, 0, 1); GL.Translate(translate.X, translate.Y, -matrix[(int)-translate.X + half, (int)-translate.Y + half]); terrain.Render(PrimitiveType.Quads); //GL.Begin(PrimitiveType.LineLoop); //DrawOne(matrix[(int) -translate.X + half, (int) -translate.Y + half], (int) -translate.X, (int) -translate.Y, // Color.Black); //GL.End(); game.SwapBuffers(); }; game.WindowState = WindowState.Maximized; game.Run(60.0, 60); } }
public void Clear(GLClearBufferMask mask) { GL.Clear((ClearBufferMask)mask); }
private void GlPaint(object sender, PaintEventArgs e) { if (!_glLoaded) { return; } // Color fonColor = Color.FromArgb(_soundColor.R, _soundColor.B, 0); _fonStrong = ((_fonStrong * 3) + _total) / 4; if (_fonStrong > 1) { _fonStrong = 1; } Color fonColor = Color.FromArgb((int)(255 * _fonStrong), (int)(255 * _fonStrong), (int)(255 * _fonStrong * 0.2)); GL.ClearColor(fonColor); // GL.ClearColor(1f, 1f, 1f, 1f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.LoadIdentity(); GL.Disable(EnableCap.Lighting); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //Прорисoвка круга if (Visual1.Colors.Count >= 10) { Color spin = new Color(); GL.Begin(PrimitiveType.TriangleFan); GL.Color3(Visual1.Colors[0]); GL.Color4(Visual1.Colors[0].R, Visual1.Colors[0].G, Visual1.Colors[0].B, (double)0.5); GL.Color4(Color.FromArgb(Visual1.Colors[0].A * 0, Visual1.Colors[0].R, Visual1.Colors[0].G, Visual1.Colors[0].B)); GL.Vertex3(-0, -0, -1); GL.Vertex3(Visual1.Coordinates[0].X, Visual1.Coordinates[0].Y, -1); for (int i = 0; i < Visual1.Coordinates.Count; i++) { if ((i % 4 == 0) && (i > 0)) { GL.End(); GL.Begin(PrimitiveType.TriangleFan); GL.Vertex3(-0, -0, (float)((double)i / Visual1.Coordinates.Count / 2 - 1)); for (int j = i - 3; j < i; j++) { GL.Vertex3(-Visual1.Coordinates[j - 1].X, -Visual1.Coordinates[j - 1].Y, (float)((double)j / Visual1.Coordinates.Count / 2 - 1)); } GL.End(); GL.Begin(PrimitiveType.TriangleFan); GL.Vertex3(-0, -0, (float)((double)i / Visual1.Coordinates.Count / 2 - 1)); GL.Vertex3(Visual1.Coordinates[i - 1].X, Visual1.Coordinates[i - 1].Y, (float)((double)i / Visual1.Coordinates.Count / 2 - 1)); } GL.Color3(Visual1.Colors[i]); GL.Color4(Visual1.Colors[i].R, Visual1.Colors[i].G, Visual1.Colors[i].B, (double)0.5); GL.Color4(Color.FromArgb((int)((double)i / Visual1.Coordinates.Count * TR * 255), Visual1.Colors[i].R, Visual1.Colors[i].G, Visual1.Colors[i].B)); GL.Vertex3(Visual1.Coordinates[i].X, Visual1.Coordinates[i].Y, (float)((double)i / Visual1.Coordinates.Count / 2 - 1)); } GL.End(); } //////конец прорисовки круга float[] diffuse = new float[3] { 0.5f, 0.5f, 0.5f }; GL.Light(LightName.Light0, LightParameter.Diffuse, diffuse); float[] ambient = new float[3] { 4, 4, 4 }; GL.Light(LightName.Light0, LightParameter.Ambient, ambient); float[] lightPos = new float[4] { -glControl1.Width, 0.0f, 10.0f, 1.0f }; GL.Light(LightName.Light0, LightParameter.Position, lightPos); float[] specular = new float[4] { 10, 10, 10, 1 }; GL.Light(LightName.Light0, LightParameter.Specular, specular); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); GL.LightModel(LightModelParameter.LightModelTwoSide, 1); //звуковой спектр снизу в виде диаграмм Random rand = new Random(); for (int color = 0; color < 5; color++) { LoadTexture(bmpTex[color]); for (int j = 0; j < 50; j++) { if (_FFTnum[j] - 1 != color) { continue; } GL.Enable(EnableCap.Texture2D); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.PolygonMode(MaterialFace.FrontAndBack, mode); GL.Begin(PrimitiveType.QuadStrip); double w = glControl1.Width / 25; float k = 0.5f; double r = 0.5; int n = 20; for (int i = 0; i <= n; ++i) { double a = Math.PI / n * i; double x = r * Math.Cos(a); double z = r * Math.Sin(a); GL.TexCoord2(0, 1); GL.Vertex3(x * w + w * j + (w / 2) - glControl1.Width, -glControl1.Height * (1 - _FFTSpectr[_FFTnum[j] - 1]), z); GL.TexCoord2(1, 0); GL.Vertex3(x * w + w * j + (w / 2) - glControl1.Width, -glControl1.Height, z); if (i > 0) { GL.Normal3(-(x - r * Math.Cos(a - 1)), (x - r * Math.Cos(a - 1)), 0); } } GL.End(); } } GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.Texture2D); //myThread t1 = new myThread("Thread 1", glControl1.Width, glControl1.Height, firstColorSpectr, spectrRadius, // _FFTSpectr, glControl1); //myThread t2 = new myThread("Thread 1", -glControl1.Width, glControl1.Height, firstColorSpectr, spectrRadius, // _FFTSpectr, glControl1); //myThread t3 = new myThread("Thread 1", glControl1.Width, -glControl1.Height, firstColorSpectr, spectrRadius, // _FFTSpectr, glControl1); //myThread t4 = new myThread("Thread 1", -glControl1.Width, -glControl1.Height, firstColorSpectr, spectrRadius, // _FFTSpectr, glControl1); MusicCirsle(glControl1.Width, glControl1.Height, Math.PI, 3 * Math.PI / 2); MusicCirsle(-glControl1.Width, glControl1.Height, 3 * Math.PI / 2, 2 * Math.PI); MusicCirsle(glControl1.Width, -glControl1.Height, Math.PI / 2, 2 * Math.PI); MusicCirsle(-glControl1.Width, -glControl1.Height, 0, Math.PI / 2); //GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.Blend); GL.Flush(); //GL.Finish(); glControl1.SwapBuffers(); }
protected override void _ClearScreen() { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); }