protected void Run() { while (!_mainWindow.Closing) { if (!_mainWindow.HandleEvents()) { return; } Gl.Clear(Gl.ColorBufferBit); Gl.ClearColor(0.6901961f, 0.1921569f, 0.2470588f, 1); Gl.MatrixMode(Gl.Projection); Gl.LoadIdentity(); Gl.Ortho(0, 1, 0, 1, 0, 1); Gl.Begin(Gl.Triangles); Gl.Color3(1, 0, 0); Gl.Vertex2(0, 0); Gl.Color3(0, 1, 0); Gl.Vertex2(0.5f, 1); Gl.Color3(0, 0, 1); Gl.Vertex2(1, 0); Gl.End(); //Gl.Clear(Gl.ColorBufferBit); _mainWindow.Swap(); } }
public void DrawAxis(float px, float py, float pz, float dist, float thick) { Gl.Viewport(30, this.glControl.ClientSize.Height - 200, 150, 150); Gl.PushMatrix(); Gl.LoadIdentity(); Gl.LineWidth(thick); Gl.Translate(0, 0, 0); Gl.Rotate(this.camera.Pitch, 1, 0, 0); Gl.Rotate(this.camera.Yaw, 0, 1, 0); Gl.Rotate(this.camera.Roll, 0, 0, 1); Gl.Scale(1, 1, 1); this.Text = $"CogiEngine (Deubg : camera dir x = {camera.Pitch}, y ={camera.Yaw}, z = {camera.Roll}"; //X - Red Gl.Begin(PrimitiveType.Lines); Gl.Color3(1f, 0f, 0f); Gl.Vertex3(px, py, pz); Gl.Vertex3(px + dist, py, pz); //Y - Blue Gl.Color3(0, 0, 1f); Gl.Vertex3(px, py, pz); Gl.Vertex3(px, py + dist, pz); //Z - Green Gl.Color3(0f, 1f, 0f); Gl.Vertex3(px, py, pz); Gl.Vertex3(px, py, pz + dist); Gl.End(); Gl.PopMatrix(); }
/// <summary> /// Old school OpenGL 1.0 drawing. /// </summary> private void RenderControl_RenderGL100() { // Setup model-view matrix // Model-view matrix selector Gl.MatrixMode(MatrixMode.Modelview); // Load (reset) to identity Gl.LoadIdentity(); // Multiply with rotation matrix (around Z axis) Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f); // Draw triangle using immediate mode (8 draw call) // Start drawing triangles Gl.Begin(PrimitiveType.Triangles); // Feed triangle data: color and position // Note: vertex attributes (color, texture coordinates, ...) are specified before position information // Note: vertex data is passed using method calls (performance killer!) Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f); Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f); Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f); // Triangles ends Gl.End(); }
static void Main(string[] args) { Init(); int x, y, width, height; uint texture; if (!Glfw.Init()) { Environment.Exit(1); } windows[0] = OpenWindow("First", Glfw.Window.None, m_Offset, m_Offset); if (!windows[0]) { Glfw.Terminate(); Environment.Exit(1); } // This is the one and only time we create a texture // It is created inside the first context, created above // It will then be shared with the second context, created below texture = CreateTexture(); Glfw.GetWindowPos(windows[0], out x, out y); Glfw.GetWindowSize(windows[0], out width, out height); // Put the second window to the right of the first one windows[1] = OpenWindow("Second", windows[0], x + width + m_Offset, y); if (!windows[1]) { Glfw.Terminate(); Environment.Exit(1); } // Set drawing color for both contexts Glfw.MakeContextCurrent(windows[0]); Gl.Color3(0.6f, 0f, 0.6f); Glfw.MakeContextCurrent(windows[1]); Gl.Color3(0.6f, 0.6f, 0f); Glfw.MakeContextCurrent(windows[0]); while (!Glfw.WindowShouldClose(windows[0]) && !Glfw.WindowShouldClose(windows[1])) { Glfw.MakeContextCurrent(windows[0]); DrawQuad(texture); Glfw.MakeContextCurrent(windows[1]); DrawQuad(texture); Glfw.SwapBuffers(windows[0]); Glfw.SwapBuffers(windows[1]); Glfw.WaitEvents(); } Glfw.Terminate(); }
public override void Paint(Rectangle visibleTiles, MapLocation mouseLocationOnMap) { if (_toolStep > ToolStep.SetOrigin) { Gl.Begin(PrimitiveType.Triangles); RenderQuad(Owner.TextureMap[MapTileVisual.Origin], Owner.GetMapLocationOnClient(_origin), new Color4() { A = 1.0f, R = 1.0f, G = 1.0F, B = 1.0F }); if (_toolStep > ToolStep.SetDestination) { RenderQuad(Owner.TextureMap[MapTileVisual.Destination], Owner.GetMapLocationOnClient(_destination), new Color4() { A = 1.0f, R = 1.0f, G = 1.0F, B = 1.0F }); } Gl.End(); if (_toolStep == ToolStep.Pathfind && _computedPath?.Path?.Length > 0) { Gl.Disable(EnableCap.Texture2d); Gl.Begin(PrimitiveType.Lines); Gl.Color3(0.0f, 0.0f, 1.0f); var start = Owner.GetMapLocationOnClient(_computedPath.Path[0]); for (int i = 1; i < _computedPath.Path.Length; i++) { var end = Owner.GetMapLocationOnClient(_computedPath.Path[i]); Gl.Vertex2(start.X + start.Width / 2, start.Y + start.Height / 2); Gl.Vertex2(end.X + end.Width / 2, end.Y + end.Height / 2); start = end; } Gl.End(); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.Enable(EnableCap.Blend); Gl.Begin(PrimitiveType.Triangles); foreach (var coloredTile in _computedPath.ColoredTiles) { RenderQuad(Owner.TextureMap[MapTileVisual.White], Owner.GetMapLocationOnClient(coloredTile), new Color4() { A = 0.2f, R = 0.0f, G = 0.0F, B = 1.0F }); } Gl.End(); } } }
public void Draw() { if (VertexBufferName == 0) { if (Vertices == null) { throw new Exception(); } var names = new uint[3]; Gl.GenBuffers(names); VertexBufferName = names[0]; IndexBufferName = names[1]; WireIndexBufferName = names[2]; Gl.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferName); Gl.BufferData(BufferTarget.ArrayBuffer, (uint)(Vertices.Length * MeshVertex.Size), Vertices, BufferUsage.StaticDraw); Gl.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBufferName); Gl.BufferData(BufferTarget.ElementArrayBuffer, (uint)(Faces.Length * sizeof(int)), Faces, BufferUsage.StaticDraw); Gl.BindBuffer(BufferTarget.ElementArrayBuffer, WireIndexBufferName); Gl.BufferData(BufferTarget.ElementArrayBuffer, (uint)(Wires.Length * sizeof(int)), Wires, BufferUsage.StaticDraw); Vertices = null; Faces = null; Wires = null; } Gl.ShadeModel(ShadingModel.Smooth); Gl.Disable(EnableCap.CullFace); // Gl.CullFace(CullFaceMode.Back); Gl.Enable(EnableCap.DepthTest); Gl.Translate(-Center.x, -Center.y, -Center.z); Gl.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferName); Gl.EnableClientState(EnableCap.VertexArray); Gl.VertexPointer(3, VertexPointerType.Float, MeshVertex.Size, (IntPtr)MeshVertex.CoordOffset); Gl.EnableClientState(EnableCap.NormalArray); Gl.NormalPointer(NormalPointerType.Float, MeshVertex.Size, (IntPtr)MeshVertex.NormalOffset); Gl.Enable(EnableCap.PolygonOffsetFill); Gl.PolygonOffset(1f, 1f); Gl.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBufferName); Gl.DrawElements(PrimitiveType.Triangles, FaceIndexBufferCount, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.Disable(EnableCap.PolygonOffsetFill); Gl.Disable(EnableCap.Lighting); Gl.Color3(0f, 0.5f, 0f); Gl.DisableClientState(EnableCap.NormalArray); Gl.BindBuffer(BufferTarget.ElementArrayBuffer, WireIndexBufferName); Gl.DrawElements(PrimitiveType.Lines, WireIndexBufferCount, DrawElementsType.UnsignedInt, IntPtr.Zero); }
static void DrawJoystick(int index, int x, int y, int width, int height) { int axisHeight = 3 * height / 4; int buttonHeight = height / 4; var axes = Glfw.GetJoystickAxes(m_Joysticks[index]); if (axes != null) { int axis_width = width / axes.Length; for (int i = 0; i < axes.Length; i++) { float value = axes[i] / 2f + 0.5f; Gl.Color3(0.3f, 0.3f, 0.3f); Gl.Rect(x + i * axis_width, y, x + (i + 1) * axis_width, y + axisHeight); Gl.Color3(1f, 1f, 1f); Gl.Rect(x + i * axis_width, y + (int)(value * (axisHeight - 5)), x + (i + 1) * axis_width, y + 5 + (int)(value * (axisHeight - 5))); } } var buttons = Glfw.GetJoystickButtons(m_Joysticks[index]); if (buttons != null) { int button_width = width / buttons.Length; for (int i = 0; i < buttons.Length; i++) { if (buttons[i]) { Gl.Color3(1f, 1f, 1f); } else { Gl.Color3(0.3f, 0.3f, 0.3f); } Gl.Rect(x + i * button_width, y + axisHeight, x + (i + 1) * button_width, y + axisHeight + buttonHeight); } } }
private void glControl_Render(object sender, GlControlEventArgs e) { Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.Begin(PrimitiveType.Polygon); Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.5f, 0.1f); Gl.Color3(1.0f, 1.0f, 0.0f); Gl.Vertex2(0.333333f, 0.333333f); Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.333333f, 0.666666f); Gl.Color3(0.0f, 1.0f, 1.0f); Gl.Vertex2(0.5f, 0.9f); Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(0.666666f, 0.666666f); Gl.Color3(1.0f, 0.0f, 1.0f); Gl.Vertex2(0.666666f, 0.333333f); Gl.End(); }
public void DrawDistortedSprite(SegaSaturnDistortedSprite sprite) { if (sprite.TextureId.HasValue) { Gl.Enable(EnableCap.Texture2d); Gl.BindTexture(TextureTarget.Texture2d, sprite.TextureId.Value); } Gl.Color4(1.0f, 1.0f, 1.0f, sprite.UseHalfTransparency ? 0.5f : 1.0f); Gl.Begin(PrimitiveType.Quads); if (sprite.TextureId.HasValue) { Gl.TexCoord2(0.0, 0.0); } else { Gl.Color3(1.0f, 0.0f, 0.0f); } Gl.Vertex3(sprite.A.FloatX, sprite.A.FloatY, sprite.A.FloatZ); if (sprite.TextureId.HasValue) { Gl.TexCoord2(1.0, 0.0); } else { Gl.Color3(0.0f, 1.0f, 0.0f); } Gl.Vertex3(sprite.B.FloatX, sprite.B.FloatY, sprite.B.FloatZ); if (sprite.TextureId.HasValue) { Gl.TexCoord2(1.0, 1.0); } else { Gl.Color3(0.0f, 0.0f, 1.0f); } Gl.Vertex3(sprite.C.FloatX, sprite.C.FloatY, sprite.C.FloatZ); if (sprite.TextureId.HasValue) { Gl.TexCoord2(0.0, 1.0); } else { Gl.Color3(1.0f, 0.0f, 1.0f); } Gl.Vertex3(sprite.D.FloatX, sprite.D.FloatY, sprite.D.FloatZ); Gl.End(); if (sprite.TextureId.HasValue) { Gl.Disable(EnableCap.Texture2d); } }
public void draw() { if (available) { image_handler.draw(); // If the Positional tracking is good, we can draw the mesh over the current image Gl.Disable(EnableCap.Texture2d); if (tracking_state == POSITIONAL_TRACKING_STATE.OK) { // Send the projection and the Pose to the GLSL shader to make the projection of the 2D image. Matrix4x4.Invert(pose, out Matrix4x4 pose_inv); Matrix4x4 vpMatrix = projection_ * pose_inv; Gl.UseProgram(meshObject.shader.it.getProgramId()); Gl.UniformMatrix4f((int)meshObject.shader.MVP_Mat, 1, true, vpMatrix); float3 clrPlane = getPlaneColor(meshObject.type); Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); Gl.Uniform3f(meshObject.shader.shColorLoc, 1, clrPlane); meshObject.draw(); Gl.LineWidth(0.5f); Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); Gl.Uniform3f(meshObject.shader.shColorLoc, 1, clrPlane); meshObject.draw(); Gl.UseProgram(0); Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } float cx = userAction.hitCoord.X * 2.0f - 1.0f; float cy = (userAction.hitCoord.Y * 2.0f - 1.0f) * -1.0f; float lx = 0.02f; float ly = lx * (wnd_w / (1.0f * wnd_h)); Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); Gl.LineWidth(2.0f); Gl.Color3(0.2f, 0.45f, 0.9f); Gl.Begin(PrimitiveType.Lines); Gl.Vertex3(cx - lx, cy, 0.0f); Gl.Vertex3(cx + lx, cy, 0.0f); Gl.Vertex3(cx, cy - ly, 0.0f); Gl.Vertex3(cx, cy + ly, 0.0f); Gl.End(); Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } }
protected override void OnGlPaint(ref PaintStruct ps) { Gl.Clear(ClearBufferMask.ColorBufferBit); var size = this.GetClientSize(); Gl.Viewport(0, 0, size.Width, size.Height); Gl.Begin(PrimitiveType.Triangles); Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f); Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f); Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f); Gl.End(); this.DeviceContext.SwapBuffers(); }
private static void RenderOsd(int w, int h) { Gl.Viewport(0, 0, w, h); Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.MatrixMode(MatrixMode.Projection); Gl.LoadIdentity(); Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0); Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); Gl.Begin(PrimitiveType.Triangles); Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f); Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f); Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f); Gl.End(); }
public override void Render() { if (!Visible) { return; } Gl.Color3(textColor.R, textColor.G, textColor.B); lock (chars) foreach (UIChar c in chars) { if (c != null) { c.Render(); } } Gl.Color3(1f, 1f, 1f); }
static void Main() { Init(); Gl.Initialize(); if (!Glfw.Init()) { Environment.Exit(1); } var window = Glfw.CreateWindow(200, 200, "Clipboard Test"); if (!window) { Glfw.Terminate(); Environment.Exit(1); } Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetKeyCallback(window, KeyCallback); Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback); Gl.MatrixMode(MatrixMode.Projection); Gl.Ortho(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0); Gl.MatrixMode(MatrixMode.Modelview); Gl.ClearColor(0.5f, 0.5f, 0.5f, 0); while (!Glfw.WindowShouldClose(window)) { Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.Color3(0.8f, 0.2f, 0.4f); Gl.Rect(-0.5f, -0.5f, 0.5f, 0.5f); Glfw.SwapBuffers(window); Glfw.WaitEvents(); } Glfw.Terminate(); }
private bool SwapBuffersHook(IntPtr hdc) { //var context = Wgl.CreateContext(hdc); Prepare2D(); //// Do drawing Gl.Color3(255, 0, 0); Gl.Begin(PrimitiveType.Quads); Gl.Vertex2(150, 150); Gl.Vertex2(500, 150); Gl.Vertex2(500, 500); Gl.Vertex2(150, 500); Gl.End(); RestoreOpenGl(); return(SwapBuffers(hdc)); }
private void GlControl_Render(object sender, OpenGL.GlControlEventArgs e) { Control senderControl = (Control)sender; // FIXME I wonder why the viewport is affected when the GlControl is hosted in WPF windows. int vpx = -senderControl.ClientSize.Width; int vpy = -senderControl.ClientSize.Height; int vpw = senderControl.ClientSize.Width * 2; int vph = senderControl.ClientSize.Height * 2; Gl.Viewport(vpx, vpy, vpw, vph); Gl.Clear(ClearBufferMask.ColorBufferBit); if (Gl.CurrentVersion >= Gl.Version_110) { // Old school OpenGL 1.1 // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition)) using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor)) { // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address); Gl.EnableClientState(EnableCap.VertexArray); Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address); Gl.EnableClientState(EnableCap.ColorArray); Gl.DrawArrays(PrimitiveType.Triangles, 0, 3); } } else { // Old school OpenGL Gl.Begin(PrimitiveType.Triangles); Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f); Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f); Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f); Gl.End(); } }
private void RenderControl_Render_GL(object sender, GlControlEventArgs e) { Control senderControl = (Control)sender; Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height); Gl.Clear(ClearBufferMask.ColorBufferBit); // Animate triangle Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f); if (Gl.CurrentVersion >= Gl.Version_110) { // Old school OpenGL 1.1 // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition)) using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor)) { // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address); Gl.EnableClientState(EnableCap.VertexArray); Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address); Gl.EnableClientState(EnableCap.ColorArray); Gl.DrawArrays(PrimitiveType.Triangles, 0, 3); } } else { // Old school OpenGL Gl.Begin(PrimitiveType.Triangles); Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f); Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f); Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f); Gl.End(); } }
public override void Paint(Rectangle visibleTiles, MapLocation mouseLocationOnMap) { int size = Math.Max(0, Size); var minimum = mouseLocationOnMap.Move(MapDirection.South | MapDirection.West, size); var maximum = mouseLocationOnMap.Move(MapDirection.North | MapDirection.East, size); var area = Rectangle.Union(Owner.GetMapLocationOnClient(minimum), Owner.GetMapLocationOnClient(maximum)); Gl.Begin(PrimitiveType.Lines); Gl.Color3(0.0f, 0.0f, 0.0f); Gl.Vertex2(area.X, area.Y); Gl.Vertex2(area.Right, area.Y); Gl.Vertex2(area.Right, area.Y); Gl.Vertex2(area.Right, area.Bottom); Gl.Vertex2(area.Right, area.Bottom); Gl.Vertex2(area.X, area.Bottom); Gl.Vertex2(area.X, area.Bottom); Gl.Vertex2(area.X, area.Y); Gl.End(); }
public void DrawAxis(bool x, bool y, bool z) { const float arrowLength = 1.0f; const float arrowTopLength = 0.1f; Gl.Begin(PrimitiveType.Lines); if (x) { Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex3(-arrowLength, 0.0f, 0.0f); Gl.Vertex3(arrowLength, 0.0f, 0.0f); Gl.Vertex3(arrowLength - arrowTopLength, arrowTopLength, 0.0f); Gl.Vertex3(arrowLength, 0.0f, 0.0f); Gl.Vertex3(arrowLength - arrowTopLength, -arrowTopLength, 0.0f); Gl.Vertex3(arrowLength, 0.0f, 0.0f); } if (y) { Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex3(0.0f, -arrowLength, 0.0f); Gl.Vertex3(0.0f, arrowLength, 0.0f); Gl.Vertex3(arrowTopLength, arrowLength - arrowTopLength, 0.0f); Gl.Vertex3(0.0f, arrowLength, 0.0f); Gl.Vertex3(-arrowTopLength, arrowLength - arrowTopLength, 0.0f); Gl.Vertex3(0.0f, arrowLength, 0.0f); } if (z) { Gl.Color3(1.0f, 0.0f, 1.0f); Gl.Vertex3(0.0f, 0.0f, -arrowLength); Gl.Vertex3(0.0f, 0.0f, arrowLength); Gl.Vertex3(0.0f, arrowTopLength, arrowLength - arrowTopLength); Gl.Vertex3(0.0f, 0.0f, arrowLength); Gl.Vertex3(0.0f, -arrowTopLength, arrowLength - arrowTopLength); Gl.Vertex3(0.0f, 0.0f, arrowLength); } Gl.End(); }
/// <summary> /// Delegate used for executing animation drawing. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for drawing. /// </param> /// <param name="animationTime"> /// A <see cref="TimeSpan"/> that specifies the animation time. /// </param> /// <param name="data"> /// A <see cref="Object"/> used to pass information to animation drawing delegate. /// </param> protected void AnimationDraw(GraphicsContext ctx, TimeSpan animationTime, object data) { const float DEG_PER_SEC = 45.0f; // Clear surface Surface.Clear(_Context); // Set modelview matrix Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); // Animation: rotate triangle Gl.Rotate(Angle.Normalize360(animationTime.TotalSeconds * DEG_PER_SEC), 0.0f, 0.0f, 1.0f); // Red triangle Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Begin(PrimitiveType.Triangles); Gl.Vertex2(-1.0f, -1.0f); Gl.Vertex2(0.0f, 1.0f); Gl.Vertex2(+1.0f, -1.0f); Gl.End(); }
public static void SetDrawingColor2() { Gl.Color3(1.0f, 0.1f, .1f); }
public static void SetDrawingColor1() { Gl.Color3(.7f, .7f, .7f); }
public void Main(string[] args) { Init(); int width, height; Glfw.Window window; Glfw.Monitor monitor = Glfw.Monitor.None; var options = new Options(); if (Parser.Default.ParseArguments(args, options)) { if (options.Fullscreen) { monitor = Glfw.GetPrimaryMonitor(); } } if (!Glfw.Init()) { Environment.Exit(1); } if (monitor) { var mode = Glfw.GetVideoMode(monitor); Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate); Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits); Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits); Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits); width = mode.Width; height = mode.Height; } else { width = 200; height = 200; } window = Glfw.CreateWindow(width, height, "Gamma Test", monitor, Glfw.Window.None); if (!window) { Glfw.Terminate(); Environment.Exit(1); } SetGamma(window, 1f); Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetKeyCallback(window, KeyCallback); Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback); Gl.MatrixMode(MatrixMode.Projection); //Gl.Ortho(-1f, 1f, -1f, 1f, -1f, 1f); Gl.MatrixMode(MatrixMode.Modelview); Gl.ClearColor(0.5f, 0.5f, 0.5f, 0); while (!Glfw.WindowShouldClose(window)) { Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.Color3(0.8f, 0.2f, 0.4f); Gl.Rect(-0.5f, -0.5f, 0.5f, 0.5f); Glfw.SwapBuffers(window); Glfw.WaitEvents(); } Glfw.Terminate(); }
/// <summary> /// Method that gets called to render each frame /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenderControl_Render_GL(object sender, GlControlEventArgs e) { if (!contextCreated) { return; } if (updateFullscreen) { FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; updateFullscreen = false; } else if (updateResize) { ResizeE(sender, e); updateResize = false; } Gl.LoadIdentity(); if (OrthoUpdate != null) { OrthoUpdate.Invoke(); OrthoUpdate = null; } Gl.Ortho(OrthoLeft, OrthoRight, OrthoBottom, OrthoTop, -0.1, 10.0); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); if (GameState.CurrentState == GameState.GameStates.Paused || GameState.WindowOpen) { Gl.Color3(.5f, .5f, .5f); } //Render World Objects WorldData.WorldRender(); if (GameState.CurrentState == GameState.GameStates.Paused || GameState.WindowOpen) { Gl.Color3(1f, 1f, 1f); } //Load a separete projection for GUI rendering that doesn't move with the character Gl.LoadIdentity(); Gl.Ortho(-320, 320, -180, 180, -0.1, 10.0); Screen.RunQueue(); lock (Screen.currentWindows) { foreach (HashSet <GUI.UIBase> b in Screen.currentWindows.Values) //Render the GUI Objects { foreach (GUI.UIBase u in b) { u.Render(); } } } Gl.BindTexture(TextureTarget.Texture2d, 0); //Other updates needed each frame Input.UpdateKeys(); if (dragged != null) { if (Math.Abs(Input.MouseX) < 320f && Math.Abs(Input.MouseY) < 180f) { dragged.positionUpdate.Invoke(); } } }
public void TestLineShaderRender() { using (ShaderProgram shaderProgram = ShadersLibrary.Instance.CreateProgram("OpenGL.Line")) { Assert.DoesNotThrow(delegate() { shaderProgram.Create(_Context); }); using (VertexArrayObject vao = new VertexArrayObject()) { List <Vertex2f> vertices = new List <Vertex2f>(); for (float y = 0.375f; y < _Framebuffer.Height; y += 2.0f) { vertices.Add(new Vertex2f(0.0f, y)); vertices.Add(new Vertex2f(_Framebuffer.Width, y)); } // Setup ABO (Position) ArrayBufferObject abo = new ArrayBufferObject(VertexBaseType.Float, 2, BufferObjectHint.StaticCpuDraw); abo.Create(vertices.ToArray()); // Setup VAO vao.SetArray(abo, VertexArraySemantic.Position); vao.SetElementArray(PrimitiveType.Lines); vao.Create(_Context); // Draw test Image feedbackImageFixed = null, feedbackImageShader = null; try { Gl.Viewport(0, 0, (int)_Framebuffer.Width, (int)_Framebuffer.Height); #region Fixed pipeline _Framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f)); _Framebuffer.Clear(_Context); Gl.MatrixMode(MatrixMode.Projection); Gl.LoadMatrix(new OrthoProjectionMatrix(0.0f, _Framebuffer.Width, 0.0f, _Framebuffer.Height).ToArray()); Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); Gl.Color3(1.0f, 1.0f, 1.0f); Gl.LineWidth(1.0f); vao.Draw(_Context); feedbackImageFixed = _Framebuffer.ReadColorBuffer(_Context, 0, 0, 0, _Framebuffer.Width, _Framebuffer.Height, PixelLayout.R8); ImageCodec.Instance.Save( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "LineProgram.Fixed.png"), feedbackImageFixed, ImageFormat.Png, null ); #endregion #region Shader pipeline _Framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f)); _Framebuffer.Clear(_Context); _Context.Bind(shaderProgram); shaderProgram.SetUniform(_Context, "hal_ModelViewProjection", RenderProjectionMatrix); shaderProgram.SetUniform(_Context, "hal_UniformColor", new ColorRGBA(1.0f, 1.0f, 1.0f)); shaderProgram.SetUniform(_Context, "hal_LineWidth", 1.0f); shaderProgram.SetUniform(_Context, "hal_ViewportSize", new Vertex2f(_Framebuffer.Width, _Framebuffer.Height)); vao.Draw(_Context, shaderProgram); feedbackImageShader = _Framebuffer.ReadColorBuffer(_Context, 0, 0, 0, _Framebuffer.Width, _Framebuffer.Height, PixelLayout.R8); ImageCodec.Instance.Save( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "LineProgram.Shader.png"), feedbackImageShader, ImageFormat.Png, null ); #endregion // Compare results } finally { if (feedbackImageFixed != null) { feedbackImageFixed.Dispose(); } if (feedbackImageShader != null) { feedbackImageShader.Dispose(); } } } //// Get rendering feedback //using (Image feedbackImage = _Framebuffer.ReadColorBuffer(_Context, 0, 0, 0, _Framebuffer.Width, _Framebuffer.Height, PixelLayout.GRAY8)) { // // Drawn only even lines // for (uint y = 0; y < _Framebuffer.Height; y++) { // for (uint x = 0; x < _Framebuffer.Width; x++) { // ColorGRAY8 fragment = (ColorGRAY8)feedbackImage[x, y]; // Assert.AreEqual((y % 2) == 0 ? 255 : 0, fragment.Level, String.Format("Color mismatch at {0}x{1}", x, y)); // } // } //} } }
private void renderGl() { ParticleEditModel md = MainModel.ins.particleEditModel; if (md == null || md.width == 0 || md.height == 0) { return; } float x = slbX + (boxWidth - md.width) / 2 + 0.5f; float y = slbY + (boxHeight - md.height) / 2 + 0.5f; var w = boxWidth; var h = boxHeight; //int vpx = 0; //int vpy = 0; //int vpw = w; //int vph = h; //Gl.Viewport(vpx, vpy, vpw, vph); //Gl.Clear(ClearBufferMask.ColorBufferBit); //Gl.MatrixMode(MatrixMode.Projection); //Gl.LoadIdentity(); //Gl.Ortho(0.0, w, 0.0, h, 0.0, 1.0); //Gl.MatrixMode(MatrixMode.Modelview); //Gl.LoadIdentity(); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); renderInitMatrix(w, h); //line 1 float xl1 = x; float yl1 = y; Gl.LineWidth(1f); Gl.Begin(PrimitiveType.LineLoop); Gl.Color3(1.0f, 1.0f, 1.0f); Gl.Vertex2(xl1, yl1); Gl.Vertex2(xl1 + md.width, yl1); Gl.Vertex2(xl1 + md.width, yl1 + md.height); Gl.Vertex2(xl1, yl1 + md.height); Gl.End(); //line 2 float xl2 = x - 1; float yl2 = y - 1; Gl.Begin(PrimitiveType.LineLoop); Gl.Color3(0.0f, 0.0f, 0.0f); Gl.Vertex2(xl2, yl2); Gl.Vertex2(xl2 + md.width + 2, yl2); Gl.Vertex2(xl2 + md.width + 2, yl2 + md.height + 2); Gl.Vertex2(xl2, yl2 + md.height + 2); Gl.End(); //mask if (md.isMaskBox) { Gl.Enable(EnableCap.ScissorTest); Gl.Scissor((int)x, (int)y, md.width, md.height); } //emitter for (int i = 0; i < lstEmitter.Count; ++i) { lstEmitter[i].setStartPos((int)x, (int)y); lstEmitter[i].render(mMVP, renderTime); } //mask if (md.isMaskBox) { Gl.Disable(EnableCap.ScissorTest); } }