daily update on 20230521 by nitload youmu, problem on coloring
This commit is contained in:
@@ -11,22 +11,7 @@
|
||||
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;
|
||||
@@ -45,23 +30,65 @@ STGSHARPGRAPHICS_API IOpackage initPackage(void)
|
||||
return pack;
|
||||
}
|
||||
|
||||
STGSHARPGRAPHICS_API int initWindow(int width, int height)
|
||||
STGSHARPGRAPHICS_API int initWindow(basicWindowInfo info)
|
||||
{
|
||||
printf("%f,%f,%f,%f,", info.backgroundColor[0], info.backgroundColor[1], info.backgroundColor[2], info.backgroundColor[3]);
|
||||
|
||||
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"
|
||||
;
|
||||
|
||||
float triangle[] =
|
||||
{
|
||||
0,0.5f,0,
|
||||
-0.5f,-0.5f,0,
|
||||
0.5f,-0.5f,0,
|
||||
};
|
||||
|
||||
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
#endif // __APPLE__
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(info.width, info.height, info.name, NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
printf("Failed to create GLFW window");
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
printf("Failed to initialize GLAD");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//编译顶点着色器
|
||||
|
||||
unsigned int vertexShader;
|
||||
vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertexShader,1,&vertexShaderSource,NULL);
|
||||
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);
|
||||
}
|
||||
|
||||
//编译片段着色器
|
||||
|
||||
@@ -91,7 +118,7 @@ STGSHARPGRAPHICS_API int initWindow(int width, int height)
|
||||
unsigned int VBO;
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangleVertices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangle, GL_STATIC_DRAW);
|
||||
|
||||
//创建顶点数组实例
|
||||
|
||||
@@ -100,67 +127,53 @@ STGSHARPGRAPHICS_API int initWindow(int width, int height)
|
||||
glBindVertexArray(VAO);
|
||||
// 2. 把顶点数组复制到缓冲中供OpenGL使用
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangleVertices, GL_STATIC_DRAW);
|
||||
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);
|
||||
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
/**/
|
||||
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
#endif // __APPLE__
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// input
|
||||
// -----
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(width, height, "LearnOpenGL", NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
printf("Failed to create GLFW window");
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
// render
|
||||
// ------
|
||||
glClearColor(
|
||||
info.backgroundColor[0],
|
||||
info.backgroundColor[1],
|
||||
info.backgroundColor[2],
|
||||
info.backgroundColor[3]
|
||||
);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
printf("Failed to initialize GLAD");
|
||||
return -1;
|
||||
}
|
||||
// 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, 3);
|
||||
//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);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// input
|
||||
// -----
|
||||
// glfw: terminate, clearing all previously allocated GLFW resources.
|
||||
// ------------------------------------------------------------------
|
||||
glfwTerminate();
|
||||
|
||||
// render
|
||||
// ------
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
/**/
|
||||
//glDeleteVertexArrays(1, &VAO);
|
||||
glDeleteBuffers(1, &VBO);
|
||||
//glDeleteBuffers(1, &EBO);
|
||||
glDeleteProgram(shaderProgram);
|
||||
/**/
|
||||
|
||||
// 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);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// glfw: terminate, clearing all previously allocated GLFW resources.
|
||||
// ------------------------------------------------------------------
|
||||
glfwTerminate();
|
||||
|
||||
//glDeleteVertexArrays(1, &VAO);
|
||||
glDeleteBuffers(1, &VBO);
|
||||
//glDeleteBuffers(1, &EBO);
|
||||
glDeleteProgram(shaderProgram);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,3 +181,6 @@ void renderTriangle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
extern STGSHARPGRAPHICS_API int* versionInfo;
|
||||
|
||||
STGSHARPGRAPHICS_API int fnStgSharpGraphics(void);
|
||||
STGSHARPGRAPHICS_API int initWindow(int width, int height);
|
||||
STGSHARPGRAPHICS_API int initWindow(basicWindowInfo info);
|
||||
STGSHARPGRAPHICS_API IOpackage initPackage(void);
|
||||
|
||||
STGSHARPGRAPHICS_API TriangleVertexHandler initTriangle(void);
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(projectdir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@@ -155,6 +156,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(projectdir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -13,5 +13,13 @@ typedef struct internalIO
|
||||
void (*InitWindow)(int width,int height);
|
||||
}IOpackage;
|
||||
|
||||
typedef struct basicWindowInfo
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
float backgroundColor[4];
|
||||
char name[];
|
||||
}basicWindowInfo;
|
||||
|
||||
|
||||
|
||||
|
||||
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user