//using StgSharp.Environment.Win32; using StgSharp.Geometries; using StgSharp.Graphics; using StgSharp.Math; using System; using System.Runtime.CompilerServices; namespace StgSharp { public class StgSharpDemoForm : Form { private Uniform color; private ElementBuffer ebo; private Uniform ourTexture; private Uniform ourTexture2; private ShaderProgram shader; private Texture texture; private VertexArray vao; private VertexBuffer vbo; private Camera camera; protected override unsafe void ProcessInput() { if (InternalIO.glfwGetKey(WindowID, (int)KeyboardKey.ESCAPE) == KeyStatus.PRESS) { InternalIO.glfwSetWindowShouldClose(WindowID, 1); } } protected override void DeInit() { /**/ vao.Dispose(); vbo.Dispose(); ebo.Dispose(); /**/ } protected override void Init() { InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info); SetMetadata(800, 800, "Hello, STG#!", IntPtr.Zero, null); MakeAsCurrentContext(); this.LoadGLapi(); SetSizeLimit(800, 800, 800, 800); FrameBufferSizeCallback = (IntPtr id, uint width, uint height) => { GL.Viewport(0, 0, width, height); }; shader = CreateShaderProgram(); var vertex = CreateShader(ShaderType.Vertex, 1); var fragment = CreateShader(ShaderType.Fragment, 1); vertex.Compile(0, File.ReadAllText("Shader\\vertex.vert")); vertex.AttachTo(0, shader); fragment.Compile(0, File.ReadAllText("Shader\\fragment.frag")); fragment.AttachTo(0, shader); shader.Link(); Triangle tri = new Triangle( -0.5f, -0.3f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f ); Rectangle rec = new Rectangle( -0.3f, 0.3f, 130.0f, 0.3f, 0.3f, 130.0f, 0.3f, -0.3f, 130.0f, -0.3f, -0.3f, 130.0f ); Polygon5 polygon = new Polygon5( -0.4f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f, 0.6f, -0.5f, 0.0f, 0, -1, 0, -0.7f, -0.5f, 0.0f ); vao = CreateVertexArray(1); vbo = CreateVertexBuffer(2); ebo = CreateElementBuffer(1); texture = CreateTexture(2); float[] texCoord = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; GL.BindVertexArray(vao[0]); ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW); vbo.SetValue(0, rec.VertexBuffer, BufferUsage.STATIC_DRAW); GL.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0); vbo.SetValueArray(1, texCoord, BufferUsage.STATIC_DRAW); GL.SetVertexAttribute(2, 2, TypeCode.Single, false, 2 * sizeof(float), 0); /**/ GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero); vao.BindNull(); /**/ texture.Bind2D(0); texture.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat); texture.Set2dFilterProperty(Filter.Nearest, Filter.Nearest); texture.LoadTexture(0, "Shader\\Image1.png", null); texture.Bind2D(1); texture.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat); texture.Set2dFilterProperty(Filter.Nearest, Filter.Nearest); texture.LoadTexture(1, "Shader\\awesomeface.png", null); shader.Use(); /**/ color = shader.GetUniform("color"); ourTexture = shader.GetUniform("ourTexture"); GL.SetValue(ourTexture, 0); ourTexture2 = shader.GetUniform("ourTexture2"); GL.SetValue(ourTexture2, 1); /**/ camera = new Camera( new vec3d(0,0,200), new vec3d(0,0,100), new vec3d(0,1,0) ); camera.SetViewRange(new Degree(5),Size,(0,0),(50f,50f)); camera.GainAllUniforms(shader, "camera"); camera.Test(); } protected override void Main() { float movement = 0.005f; GL.ClearColor(0.333f, 0.555f, 0.555f, 1.0f); GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH); /**/ vao.Bind(0); shader.Use(); /**/ /**/ texture.Activate(TextureUnit.Unit0); texture.Bind2D(0); texture.Activate(TextureUnit.Unit1); texture.Bind2D(1); /**/ /**/ float time = CurrentFrameCount / 60.0f; if (InternalIO.glfwGetKey(this.WindowID,GLconst.GLFW_KEY_UP) == KeyStatus.PRESS) { camera.Pitch(new Radius(movement)); } else if (InternalIO.glfwGetKey(this.WindowID, GLconst.GLFW_KEY_DOWN) == KeyStatus.PRESS) { camera.Pitch(new Radius(-movement)); } if (InternalIO.glfwGetKey(WindowID, GLconst.GLFW_KEY_LEFT) == KeyStatus.PRESS) { camera.Yaw(new Radius(-movement)); } else if (InternalIO.glfwGetKey(WindowID, GLconst.GLFW_KEY_RIGHT) == KeyStatus.PRESS) { camera.Yaw(new Radius(movement)); } GL.SetValue(color, 0.5f + MathF.Cos(time), 0.5f + MathF.Sin(time * 0.66667f + (2 * Scaler.Pi / 3)), 0.5f + MathF.Sin(time * 0.33333f + (Scaler.Pi / 3)), time ); camera.SetAllUniforms(); /**/ GL.DrawElements(GepmetryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero); //vao.BindNull(); /**/ } [MultiFrameActivity()] public void Beep() { if (CurrentFrameCount%60==0) { Console.Beep(); } } //[RenderActivity(RenderPriority.Pre_1)] public void NoOp() { int a = 1; } } internal static class Program { internal static unsafe void Main(string[] args) { try { //StgSharp.TryCreatWindow(); /**/ StgSharp.Init(); StgSharp.InitGL(4, 6); StgSharp.GlobalSetting.VSyncActivated = false; StgSharpDemoForm demoForm = new StgSharpDemoForm(); demoForm.Show(); StgSharp.Terminate(); /**/ } catch (Exception ex) { InternalIO.InternalWriteLog( ex.Message + "\n" + ex.StackTrace, LogType.Error); } } } }