daily upsate on 20230517 by nitload youmu
This commit is contained in:
@@ -8,6 +8,26 @@
|
||||
#include "stdio.h"
|
||||
#include "internal.h"
|
||||
|
||||
extern float* triangleVertexes;
|
||||
|
||||
|
||||
const char *vertexShaderSource =
|
||||
"#version 460 core\n"
|
||||
"layout (location = 0) in vec3 aPos\n"
|
||||
"void main()\n"
|
||||
"(\n"
|
||||
"gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||
")\n";
|
||||
|
||||
const char* fragmentShaderSource =
|
||||
"#version 460 core\n"
|
||||
"out vec4 FragColor\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
"FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
int version[4] = { 0,0,0,0 };
|
||||
STGSHARPGRAPHICS_API int* versionInfo = &version;
|
||||
|
||||
@@ -27,6 +47,63 @@ STGSHARPGRAPHICS_API IOpackage initPackage(void)
|
||||
|
||||
STGSHARPGRAPHICS_API int initWindow(int width, int height)
|
||||
{
|
||||
|
||||
//编译顶点着色器
|
||||
|
||||
unsigned int vertexShader;
|
||||
vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertexShader,1,&vertexShaderSource,NULL);
|
||||
glCompileShader(vertexShader);
|
||||
int success;
|
||||
char infoLog[512];
|
||||
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
|
||||
printf("\i",infoLog);
|
||||
}
|
||||
|
||||
//编译片段着色器
|
||||
|
||||
unsigned int fragmentShader;
|
||||
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
|
||||
glCompileShader(fragmentShader);
|
||||
|
||||
//创建着色器程序
|
||||
|
||||
unsigned int shaderProgram;
|
||||
shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
glAttachShader(shaderProgram, fragmentShader);
|
||||
glUseProgram(shaderProgram);
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
// 链接顶点属性
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
|
||||
//创建顶点缓存实例
|
||||
|
||||
unsigned int VBO;
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangleVertices, GL_STATIC_DRAW);
|
||||
|
||||
//创建顶点数组实例
|
||||
|
||||
unsigned int VAO;
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
// 2. 把顶点数组复制到缓冲中供OpenGL使用
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangleVertices, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
@@ -61,6 +138,13 @@ STGSHARPGRAPHICS_API int initWindow(int width, int height)
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// draw our first triangle
|
||||
glUseProgram(shaderProgram);
|
||||
glBindVertexArray(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, 6);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
// glBindVertexArray(0); // no need to unbind it every time
|
||||
|
||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||
// -------------------------------------------------------------------------------
|
||||
glfwSwapBuffers(window);
|
||||
@@ -71,6 +155,11 @@ STGSHARPGRAPHICS_API int initWindow(int width, int height)
|
||||
// ------------------------------------------------------------------
|
||||
glfwTerminate();
|
||||
|
||||
//glDeleteVertexArrays(1, &VAO);
|
||||
glDeleteBuffers(1, &VBO);
|
||||
//glDeleteBuffers(1, &EBO);
|
||||
glDeleteProgram(shaderProgram);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,3 +25,6 @@ STGSHARPGRAPHICS_API int initWindow(int width, int height);
|
||||
STGSHARPGRAPHICS_API IOpackage initPackage(void);
|
||||
|
||||
STGSHARPGRAPHICS_API TriangleVertexHandler initTriangle(void);
|
||||
STGSHARPGRAPHICS_API void inputTriangle(TriangleVertexHandler triangle);
|
||||
STGSHARPGRAPHICS_API Polygon4VertexesHandler initPolygon4(void);
|
||||
STGSHARPGRAPHICS_API Polygon5VertexesHandler initPolygon5(void);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "StgSharpGraphics.h"
|
||||
|
||||
|
||||
extern float* triangleVertexes;
|
||||
|
||||
STGSHARPGRAPHICS_API TriangleVertexHandler initTriangle(void)
|
||||
{
|
||||
@@ -22,4 +23,68 @@ STGSHARPGRAPHICS_API TriangleVertexHandler initTriangle(void)
|
||||
return tri;
|
||||
}
|
||||
|
||||
STGSHARPGRAPHICS_API void inputTriangle(TriangleVertexHandler triangle)
|
||||
{
|
||||
triangleVertices = triangle.vertex1;
|
||||
}
|
||||
|
||||
STGSHARPGRAPHICS_API Polygon4VertexesHandler initPolygon4(void)
|
||||
{
|
||||
float vertex[12] =
|
||||
{
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
};
|
||||
|
||||
int triangleOrder[6] =
|
||||
{
|
||||
0,1,3,
|
||||
1,2,3,
|
||||
};
|
||||
|
||||
Polygon4VertexesHandler poly;
|
||||
|
||||
poly.vertex1 = &vertex[0];
|
||||
poly.vertex2 = &vertex[3];
|
||||
poly.vertex3 = &vertex[6];
|
||||
poly.vertex4 = &vertex[9];
|
||||
|
||||
poly.triangle1 = &triangleOrder[0];
|
||||
poly.triangle2 = &triangleOrder[3];
|
||||
|
||||
return poly;
|
||||
}
|
||||
|
||||
STGSHARPGRAPHICS_API Polygon5VertexesHandler initPolygon5(void)
|
||||
{
|
||||
|
||||
float vertex[15] =
|
||||
{
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
0,0,0,
|
||||
};
|
||||
|
||||
int triangleOrder[9] =
|
||||
{
|
||||
0,1,2,
|
||||
1,2,3,
|
||||
2,3,4
|
||||
};
|
||||
|
||||
Polygon5VertexesHandler poly;
|
||||
|
||||
poly.vertex1 = &vertex[0];
|
||||
poly.vertex2 = &vertex[3];
|
||||
poly.vertex3 = &vertex[6];
|
||||
poly.vertex4 = &vertex[9];
|
||||
|
||||
poly.triangle1 = &triangleOrder[0];
|
||||
poly.triangle2 = &triangleOrder[3];
|
||||
|
||||
return poly;
|
||||
}
|
||||
|
||||
@@ -8,3 +8,25 @@ typedef struct TriangleVertexHandler
|
||||
float* vertex2;
|
||||
float* vertex3;
|
||||
}TriangleVertexHandler;
|
||||
|
||||
typedef struct Polygon4VertexesHandler
|
||||
{
|
||||
float* vertex1;
|
||||
float* vertex2;
|
||||
float* vertex3;
|
||||
float* vertex4;
|
||||
|
||||
int* triangle1;
|
||||
int* triangle2;
|
||||
}Polygon4VertexesHandler;
|
||||
|
||||
typedef struct Polygon5VertexesHandler
|
||||
{
|
||||
float* vertex1;
|
||||
float* vertex2;
|
||||
float* vertex3;
|
||||
float* vertex4;
|
||||
|
||||
int* triangle1;
|
||||
int* triangle2;
|
||||
}Polygon5VertexesHandler;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "stdio.h"
|
||||
|
||||
#define init InitProgram;
|
||||
float* triangleVertices;
|
||||
|
||||
typedef struct internalIO
|
||||
{
|
||||
|
||||
@@ -4,9 +4,10 @@ d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharp
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharpgraphics\x64\debug\pch.obj
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharpgraphics\x64\debug\stgsharpgraphics.obj
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharpgraphics\x64\debug\glad.obj
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharpgraphics\x64\debug\geometryhandler.obj
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharpgraphics\x64\debug\dllmain.obj
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharp\stgsharpgraphics.dll
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharpgraphics\x64\debug\stgsharpgraphics.ilk
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharp\stgsharpgraphics.dll
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharp\stgsharpgraphics.pdb
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharp\stgsharpgraphics.lib
|
||||
d:\nitloadindustry\研究项目\1-flagship\th2020\projectfile\源代码\stgsharp\stgsharpgraphics.exp
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user