将被注释的blending enabling更改为选择性编译

This commit is contained in:
pointer-to-bios 2024-04-27 02:39:11 +08:00
parent 121fb7a687
commit 5b99adfe38
2 changed files with 25 additions and 15 deletions

View File

@ -21,6 +21,10 @@ add_subdirectory(./deps/glm)
##test target## ##test target##
add_executable(jungle ./test/main.cpp ./deps/glad/src/glad.c) add_executable(jungle ./test/main.cpp ./deps/glad/src/glad.c)
target_include_directories(jungle PRIVATE ./test/) target_include_directories(jungle PRIVATE ./test/)
if (${BLENDING})
add_definitions(-DBLENDING=1)
message("开启BLENDING")
endif()
#glfw dep #glfw dep
add_dependencies(jungle glfw) add_dependencies(jungle glfw)
target_include_directories(jungle PRIVATE ./deps/glfw/include/ ./deps/glad/include/ ./inc) target_include_directories(jungle PRIVATE ./deps/glfw/include/ ./deps/glad/include/ ./inc)

View File

@ -40,7 +40,9 @@ int main()
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glEnable(GL_BLEND); #ifdef BLENDING
glEnable(GL_BLEND);
#endif
#ifdef __APPLE__ #ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
@ -73,8 +75,10 @@ int main()
// configure global opengl state // configure global opengl state
// ----------------------------- // -----------------------------
// glEnable(GL_BLEND); #ifdef BLENDING
// glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
#endif
// glEnable(GL_DEPTH_TEST); // glEnable(GL_DEPTH_TEST);
// build and compile our shader zprogram // build and compile our shader zprogram
@ -296,19 +300,21 @@ int main()
// glDepthMask(GL_FALSE); // glDepthMask(GL_FALSE);
// render transparent objects with blending enabled // render transparent objects with blending enabled
// glEnable(GL_BLEND); #ifdef BLENDING
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND);
// for (unsigned int i = 5; i < 10; i++) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// { for (unsigned int i = 5; i < 10; i++)
// ourShader.setIVec2("index", cubeTextures[i]); {
ourShader.setIVec2("index", cubeTextures[i]);
// // calculate the model matrix for each object and pass it to shader before drawing // calculate the model matrix for each object and pass it to shader before drawing
// glm::mat4 model = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first glm::mat4 model = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
// model = glm::translate(model, glm::vec3(cubePositions[i])); model = glm::translate(model, glm::vec3(cubePositions[i]));
// ourShader.setMat4("model", model); ourShader.setMat4("model", model);
// glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
// } }
// glDisable(GL_BLEND); glDisable(GL_BLEND);
#endif
// glDisable(GL_DEPTH_TEST); // glDisable(GL_DEPTH_TEST);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)