daily update on 20230609 by nitload youmu, graphic arragement for better form init

This commit is contained in:
Nitload
2023-06-09 08:12:06 +08:00
parent 1874b32fb0
commit 50b4965e54
147 changed files with 8886 additions and 478 deletions
+35 -21
View File
@@ -50,7 +50,7 @@ STGSHARPGRAPHICS_API IOpackage initPackage(void)
return pack;
}
STGSHARPGRAPHICS_API basicWindowInfo* InitWindow(basicWindowInfo info)
STGSHARPGRAPHICS_API void InitGL()
{
glfwInit();
@@ -62,10 +62,14 @@ STGSHARPGRAPHICS_API basicWindowInfo* InitWindow(basicWindowInfo info)
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif // __APPLE__
}
STGSHARPGRAPHICS_API basicWindowInfo* InitWindow(basicWindowInfo info)
{
GLFWwindow* window = glfwCreateWindow(info.width, info.height, info.name, NULL, NULL);
if (window == NULL)
{
printf("Failed to create GLFW window");
glfwTerminate();
return -1;
}
@@ -73,15 +77,14 @@ STGSHARPGRAPHICS_API basicWindowInfo* InitWindow(basicWindowInfo info)
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
printf("Failed to initialize GLAD");
return -1;
return -2;
}
glfwSwapInterval(0);
return window;
}
STGSHARPGRAPHICS_API void ComppileShader(void)
STGSHARPGRAPHICS_API void CompileShader(shaderObject* shaderObj)
{
//编译顶点着色器
@@ -115,18 +118,20 @@ STGSHARPGRAPHICS_API void ComppileShader(void)
//创建顶点缓存实例
unsigned int VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glGenBuffers(1, shaderObj->VBO);
glBindBuffer(GL_ARRAY_BUFFER, shaderObj->VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangle, GL_STATIC_DRAW);
//创建顶点数组实例
unsigned int VAO;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenVertexArrays(1, shaderObj->VAO);
glBindVertexArray(shaderObj->VAO);
// 2. 把顶点数组复制到缓冲中供OpenGL使用
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindBuffer(GL_ARRAY_BUFFER, shaderObj->VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangle, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
@@ -134,8 +139,17 @@ STGSHARPGRAPHICS_API void ComppileShader(void)
/**/
}
STGSHARPGRAPHICS_API void RenderWindow(GLFWwindow* window, basicWindowInfo info)
STGSHARPGRAPHICS_API void RenderWindow
(
GLFWwindow* window,
basicWindowInfo info,
shaderObject* shaderObj
)
{
while (!glfwWindowShouldClose(window))
{
if (1)
@@ -160,9 +174,9 @@ STGSHARPGRAPHICS_API void RenderWindow(GLFWwindow* window, basicWindowInfo info)
glClear(GL_COLOR_BUFFER_BIT);
// draw our first triangle
/*
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
/**/
glUseProgram(shaderObj->shaderProgram);
glBindVertexArray(shaderObj->VAO);
// seeing as we only have a single VAO there's no need to bind it every time,
// but we'll do so to keep things a bit more organized
glDrawArrays(GL_TRIANGLES, 0, 3);
@@ -176,17 +190,17 @@ STGSHARPGRAPHICS_API void RenderWindow(GLFWwindow* window, basicWindowInfo info)
}
}
STGSHARPGRAPHICS_API void TerminateWindow(void)
STGSHARPGRAPHICS_API void TerminateWindow(shaderObject* shaderObj)
{
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
/*
//glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
/**/
//glDeleteVertexArrays(1, &(shaderObj->VAO));
glDeleteBuffers(1, &(shaderObj->VBO));
//glDeleteBuffers(1, &EBO);
glDeleteProgram(shaderProgram);
glDeleteProgram(shaderObj-> shaderProgram);
/**/
}
+19 -12
View File
@@ -1,31 +1,32 @@
// 下列 ifdef 块是创建使从 DLL 导出更简单的宏的标准方法。
// 此 DLL 中的所有文件都是用命令行上定义的 STGSHARPGRAPHICS_EXPORTS符号编译的。
// 在使用此 DLL 的任何项目上不应定义此符号。
// 这样,源文件中包含此文件的任何其他项目都会将
// STGSHARPGRAPHICS_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
// 符号视为是被导出的。
#ifndef StgSharpGraphic
#define StgSharpGraphic
#include "internal.h"
#include "geometryHandler.h"
#define STGSHARPGRAPHICS_API __declspec(dllexport)
#define STGSHARPGRAPHICS_EXPORTS
/*
#ifdef STGSHARPGRAPHICS_EXPORTS
#define STGSHARPGRAPHICS_API __declspec(dllexport)
#else
#define STGSHARPGRAPHICS_API __declspec(dllimport)
#endif
/**/
/**/
extern STGSHARPGRAPHICS_API int* versionInfo;
/**/
STGSHARPGRAPHICS_API void InitGL(void);
STGSHARPGRAPHICS_API basicWindowInfo* InitWindow(basicWindowInfo info);
STGSHARPGRAPHICS_API void ComppileShader(void);
STGSHARPGRAPHICS_API void RenderWindow(GLFWwindow* window, basicWindowInfo info);
STGSHARPGRAPHICS_API void TerminateWindow(void);
STGSHARPGRAPHICS_API void CompileShader(shaderObject* shaderObj);
STGSHARPGRAPHICS_API void RenderWindow
(
GLFWwindow* window,
basicWindowInfo info,
shaderObject* shaderObj
);
STGSHARPGRAPHICS_API void TerminateWindow(shaderObject* shaderObj);
STGSHARPGRAPHICS_API IOpackage initPackage(void);
@@ -33,3 +34,9 @@ STGSHARPGRAPHICS_API TriangleVertexHandler initTriangle(void);
STGSHARPGRAPHICS_API void inputTriangle(TriangleVertexHandler triangle);
STGSHARPGRAPHICS_API Polygon4VertexesHandler initPolygon4(void);
STGSHARPGRAPHICS_API Polygon5VertexesHandler initPolygon5(void);
STGSHARPGRAPHICS_API int isNextFrame(unsigned int fps);
#endif // !StgSharpGraphic
@@ -177,6 +177,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.c" />
<ClCompile Include="fpsControl.c" />
<ClCompile Include="geometryHandler.c" />
<ClCompile Include="glad.c" />
<ClCompile Include="pch.c">
@@ -192,6 +193,10 @@
<Library Include="glfw3dll.lib" />
<Library Include="glfw3_mt.lib" />
</ItemGroup>
<ItemGroup>
<Text Include="closecallback.txt" />
<Text Include="源.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
@@ -62,6 +62,9 @@
<ClCompile Include="geometryHandler.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="fpsControl.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Library Include="glfw3.lib">
@@ -74,4 +77,12 @@
<Filter>资源文件</Filter>
</Library>
</ItemGroup>
<ItemGroup>
<Text Include="源.txt">
<Filter>资源文件</Filter>
</Text>
<Text Include="closecallback.txt">
<Filter>资源文件</Filter>
</Text>
</ItemGroup>
</Project>
@@ -0,0 +1,40 @@
当然可以。下面是一个使用 glfwSetWindowCloseCallback 函数的代码示例
// 定义一个关闭回调函数
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE); // 设置窗口的关闭标记为真
}
int main()
{
// 初始化GLFW和创建窗口
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "My Title", NULL, NULL);
// 设置当前上下文和初始化GLAD
glfwMakeContextCurrent(window);
gladLoadGL(glfwGetProcAddress);
// 设置关闭回调函数
glfwSetWindowCloseCallback(window, key_callback);
// 主循环
while (!glfwWindowShouldClose(window))
{
// 渲染代码
// 交换缓冲区和处理事件
glfwSwapBuffers(window);
glfwPollEvents();
}
// 销毁窗口和终止GLFW
glfwDestroyWindow(window);
glfwTerminate();
}
这段代码会在用户按下ESC键时关闭窗口。
如果您想要隐藏窗口而不是关闭,您可以在关闭回调函数中使用 glfwHideWindow 函数
。如果您想要重新显示窗口,您可以在其他地方使用 glfwShowWindow 函数。
+16
View File
@@ -0,0 +1,16 @@
#include "glad/glad.h"
#include "GLFW/glfw3.h"
#include "stdio.h"
#include "StgSharpGraphics.h"
STGSHARPGRAPHICS_API int isNextFrame(unsigned int fps)
{
if (fps==0)
{
return 1;
}
else
{
}
}
+7
View File
@@ -29,5 +29,12 @@ typedef struct basicWindowInfo
char name[];
}basicWindowInfo;
typedef struct shaderObject
{
unsigned int VBO;
unsigned int VAO;
unsigned int shaderProgram;
}shaderObject;
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\StgSharpGraphics.dll</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0:
Release|x64|D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\|
@@ -0,0 +1 @@
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpGraphics\x64\Release\\_IsIncrementalBuild
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+93
View File
@@ -0,0 +1,93 @@
// A simple multi-window example using GLFW
// This code is based on https://github.com/glfw/glfw/blob/master/examples/windows.c
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
// A function to handle window resizing
void window_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
// A function to handle window closing
void window_close_callback(GLFWwindow* window)
{
printf("Window %p closed\n", window);
}
// A function to handle key input
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
int main(void)
{
// Initialize GLFW
if (!glfwInit())
{
printf("Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
// Create two windows with OpenGL contexts
GLFWwindow* window1 = glfwCreateWindow(640, 480, "Window 1", NULL, NULL);
if (!window1)
{
printf("Failed to create window 1\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
GLFWwindow* window2 = glfwCreateWindow(640, 480, "Window 2", NULL, NULL);
if (!window2)
{
printf("Failed to create window 2\n");
glfwDestroyWindow(window1);
glfwTerminate();
exit(EXIT_FAILURE);
}
// Set the callbacks for each window
glfwSetWindowSizeCallback(window1, window_size_callback);
glfwSetWindowCloseCallback(window1, window_close_callback);
glfwSetKeyCallback(window1, key_callback);
glfwSetWindowSizeCallback(window2, window_size_callback);
glfwSetWindowCloseCallback(window2, window_close_callback);
glfwSetKeyCallback(window2, key_callback);
// Set the clear colors for each window
const struct { float r, g, b; } colors[] =
{
{ 0.95f, 0.32f, 0.11f },
{ 0.50f, 0.80f, 0.16f }
};
// Loop until both windows are closed
while (!glfwWindowShouldClose(window1) && !glfwWindowShouldClose(window2))
{
// Clear and swap buffers for each window
for (int i = 0; i < 2; i++)
{
GLFWwindow* window = (i == 0) ? window1 : window2;
glfwMakeContextCurrent(window);
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
// Poll for and process events
glfwPollEvents();
}
// Destroy the windows and terminate GLFW
glfwDestroyWindow(window1);
glfwDestroyWindow(window2);
glfwTerminate();
}