208 lines
6.0 KiB
C#
208 lines
6.0 KiB
C#
using StgSharp.Geometries;
|
|
using StgSharp.Graphics;
|
|
using StgSharp.Math;
|
|
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 Main(string[] args)
|
|
{
|
|
internalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
|
|
|
|
Graphic.InitGL(4, 6);
|
|
|
|
Form f = Graphic.CreateWindow(
|
|
800, 600, "Test STG#!", IntPtr.Zero, null
|
|
);
|
|
Graphic.MakeContexCurrent(f);
|
|
Graphic.SetFrameBufferSizeCallback(f, FormSizeCallback);
|
|
|
|
GetApiRep();
|
|
Graphic.InitGLManager(Graphic.GetProcAddress);
|
|
|
|
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);
|
|
vao.Bind();
|
|
|
|
/*
|
|
uint VAO;
|
|
Graphic.glGenVertexArrays(1, &VAO);
|
|
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VAO);
|
|
Graphic.glBindVertexArray(VAO);
|
|
/**/
|
|
|
|
|
|
/*
|
|
// for triangle rendering
|
|
uint VBO;
|
|
Graphic.glGenBuffers(1, &VBO);
|
|
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VBO);
|
|
fixed (void* data = &tri.vertexMap)
|
|
{
|
|
Graphic.glBufferData(GLFW.GL_ARRAY_BUFFER, 12 * sizeof(float), data, GLFW.GL_STATIC_DRAW);
|
|
}
|
|
|
|
Graphic.glVertexAttribPointer(0, 3, GLFW.GL_FLOAT, false, 4 * sizeof(float), (void*)0);
|
|
Graphic.glEnableVertexAttribArray(0);
|
|
|
|
/**/
|
|
|
|
/**/
|
|
// for rectangle rendering
|
|
|
|
VertexBuffer vbo = new VertexBuffer(1);
|
|
vbo.Bind();
|
|
vbo.SetData(polygon.VertexBuffer, BufferReadType.STATIC_DRAW);
|
|
|
|
/*
|
|
uint VBO;
|
|
Graphic.glGenBuffers(1, &VBO);
|
|
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, VBO);
|
|
Graphic.SetBufferData(BufferType.ARRAY_BUFFER, polygon.VertexBuffer, BufferReadType.STATIC_DRAW);
|
|
/**/
|
|
|
|
|
|
/*
|
|
fixed (void* data = &rec.vertexMat)
|
|
{
|
|
Graphic.glBufferData(GLFW.GL_ARRAY_BUFFER, 16 * sizeof(float), data, GLFW.GL_STATIC_DRAW);
|
|
}
|
|
/**/
|
|
|
|
|
|
ElementBuffer ebo = new ElementBuffer(1);
|
|
ebo.Bind();
|
|
ebo.SetData(polygon.Indices, BufferReadType.STATIC_DRAW);
|
|
|
|
/*
|
|
uint EBO;
|
|
Graphic.glGenBuffers(1, &EBO);
|
|
Graphic.glBindBuffer(GLFW.GL_ELEMENT_ARRAY_BUFFER, EBO);
|
|
|
|
Graphic.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, polygon.Indices, BufferReadType.STATIC_DRAW);
|
|
/**/
|
|
|
|
|
|
Graphic.glVertexAttribPointer(0, 3, GLFW.GL_FLOAT, false, 4 * sizeof(float), (void*)0);
|
|
Graphic.glEnableVertexAttribArray(0);
|
|
|
|
/**/
|
|
|
|
Graphic.glBindBuffer(GLFW.GL_ARRAY_BUFFER, 0);
|
|
Graphic.glBindVertexArray(0);
|
|
|
|
|
|
while (internalIO.glfwWindowShouldClose(f.windowID) == 0)
|
|
{
|
|
ProcessInput(f.windowID);
|
|
|
|
Graphic.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
Graphic.glClear(GLFW.GL_COLOR_BUFFER_BIT);
|
|
|
|
shader.Use();
|
|
|
|
Graphic.glBindVertexArray(vao._bufferID);
|
|
|
|
//Graphic.glDrawArrays(GLFW.GL_TRIANGLES, 0, 3);
|
|
Graphic.glDrawElements(GLFW.GL_TRIANGLES, 9, GLFW.GL_UNSIGNED_INT, (void*)0);
|
|
|
|
Graphic.glBindVertexArray(0);
|
|
|
|
internalIO.glfwSwapBuffers(f.windowID);
|
|
internalIO.glfwPollEvents();
|
|
}
|
|
|
|
vao.Dispose();
|
|
vbo.Dispose();
|
|
ebo.Dispose();
|
|
|
|
/*
|
|
Graphic.glDeleteVertexArrays(1, &VAO);
|
|
Graphic.glDeleteBuffers(1, &VBO);
|
|
Graphic.glDeleteBuffers(1, &EBO);
|
|
/**/
|
|
|
|
internalIO.glfwTerminate();
|
|
|
|
}
|
|
|
|
public static void FormSizeCallback(IntPtr window, int width, int height)
|
|
{
|
|
Graphic.glViewport(0, 0, width, height);
|
|
}
|
|
|
|
public static void ProcessInput(IntPtr windowPtr)
|
|
{
|
|
if (internalIO.glfwGetKey(windowPtr, (int)Control.Key.ESCAPE)
|
|
== KeyStatus.PRESS)
|
|
{
|
|
internalIO.glfwSetWindowShouldClose(windowPtr, 1);
|
|
}
|
|
}
|
|
|
|
[DllImport(internalIO.SSGC_libname, EntryPoint = "getApiReporter",
|
|
CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
internal extern static void internal_getApiReporter(IntPtr reporter);
|
|
|
|
internal static void GetApiRep()
|
|
{
|
|
showApiHandler handle = new showApiHandler(ShowApiAddress);
|
|
internal_getApiReporter(Marshal.GetFunctionPointerForDelegate(handle));
|
|
}
|
|
internal delegate void showApiHandler(ulong add);
|
|
internal static void ShowApiAddress(ulong address)
|
|
{
|
|
Console.WriteLine(address);
|
|
}
|
|
|
|
[DllImport(internalIO.SSGC_libname, EntryPoint = "printShaderCode",
|
|
CallingConvention = CallingConvention.Cdecl)]
|
|
internal extern unsafe static void PrintShader(byte** shadercode);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|