using StgSharp.Geometries; using StgSharp.Graphics; using StgSharp.Math; using StgSharp.Math.Linear; using System; using System.Diagnostics; using System.IO; using System.Numerics; using System.Runtime.InteropServices; using System.Text; namespace StgSharp { internal static class Program { internal unsafe static void DebugMain(string[] args) { InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info); InternalIO.InternalWriteLog($"{typeof(vec3d).Name}", LogType.Info); Graphic.InitGL(4, 6); //GL.glfw->WindowHint(GLFW.GLFW_DECORATED, GLFW.GL_FALSE); //Form f = Graphic.CreateWindow(800, 600, "Test STG#!", IntPtr.Zero, null); Form f = new Form(800, 600, "Hello,STG#!", IntPtr.Zero, null); f.MakeAsCurrentContext(); f.SetSizeLimit(800, 600, 800, 600); GL.SetFrameBufferSizeCallback(f, FormSizeCallback); f.LoadGlapi(GL.LoadGLfunc); Shader shader = new Shader(); shader.CompileVertexShader( File.ReadAllText("Shader\\vertex.vert") ); shader.CompileFragmentShader( File.ReadAllText("Shader\\fragment.frag") ); 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.4f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f, 0.6f, -0.5f, 0.0f, -0.7f, -0.5f, 0.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 ); VertexArray vao = new VertexArray(1); VertexBuffer vbo = new VertexBuffer(1); ElementBuffer ebo = new ElementBuffer(1); GL.glBindVertexArray(vao[0]); vbo.SetData(0, polygon.VertexBuffer, BufferUsage.STATIC_DRAW); ebo.SetData(0, polygon.Indices, BufferUsage.STATIC_DRAW); GL.glVertexAttribPointer(0, 3, GLconst.FLOAT, false, 4 * sizeof(float), (void*)0); GL.glEnableVertexAttribArray(0); /**/ GL.glBindBuffer(GLconst.ARRAY_BUFFER, 0); GL.glBindVertexArray(0); /**/ while (InternalIO.glfw_WindowShouldClose(f.windowID) == 0) { ProcessInput(f.windowID); GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f); GL.glClear(GLconst.COLOR_BUFFER_BIT); shader.Use(); GL.glBindVertexArray(vao._bufferID[0]); GL.DrawElements(GepmetryType.TRIANGLES, 9, typeof(uint), IntPtr.Zero); GL.glBindVertexArray(0); InternalIO.glfw_SwapBuffers(f.windowID); InternalIO.glfw_PollEvents(); InternalIO.glfw_PollEvents(); } /**/ vao.Dispose(); vbo.Dispose(); ebo.Dispose(); /**/ /* Graphic.glDeleteVertexArrays(1, &vao); Graphic.glDeleteBuffers(1, &vao); Graphic.glDeleteBuffers(1, &vao); /**/ InternalIO.glfw_Terminate(); } internal unsafe static void Main(string[] args) { try { DebugMain(args); } catch (Exception ex) { InternalIO.InternalWriteLog( ex.Message + "\n" + ex.StackTrace, LogType.Error); } } public static unsafe void FormSizeCallback(IntPtr window, int width, int height) { GL.glViewport(0, 0, width, height); } public static unsafe void ProcessInput(IntPtr windowPtr) { if (InternalIO.glfw_GetKey(windowPtr, (int)Control.Key.ESCAPE) == KeyStatus.PRESS) { InternalIO.glfw_SetWindowShouldClose(windowPtr, 1); } } [DllImport(InternalIO.SSGC_libname, EntryPoint = "printShaderCode", CallingConvention = CallingConvention.Cdecl)] internal extern unsafe static void PrintShader(byte** shadercode); } }