From 0d25c81cb35b2e271b3e343baa4f6c5bb4efb71c Mon Sep 17 00:00:00 2001 From: ZtRXR Date: Fri, 28 Jun 2024 21:17:11 +0800 Subject: [PATCH] update --- CMakeLists.txt | 3 ++- include/glpy.h | 5 +++++ src/main.cpp | 47 +++++++++------------------------------------ src/test_window.cpp | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 include/glpy.h create mode 100644 src/test_window.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ab6a893..59d7038 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,4 +10,5 @@ pybind11_add_module(${PROJECT_NAME} ${SRC}) add_subdirectory(glfw) target_link_libraries(${PROJECT_NAME} PRIVATE glfw) find_package(OpenGl REQUIRED) -target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL) \ No newline at end of file +target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL) diff --git a/include/glpy.h b/include/glpy.h new file mode 100644 index 0000000..5cd15bb --- /dev/null +++ b/include/glpy.h @@ -0,0 +1,5 @@ +#pragma once + +namespace tests{ + int glfw_window(unsigned width,unsigned height, std::string title); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b04402b..7f150bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,46 +1,17 @@ #include #include -#include - -int pytest_glfw_window() -{ - GLFWwindow* window; - - /* Initialize the library */ - if (!glfwInit()) - return -1; - - /* Create a windowed mode window and its OpenGL context */ - window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); - if (!window) - { - glfwTerminate(); - return -1; - } - - /* Make the window's context current */ - glfwMakeContextCurrent(window); - - /* Loop until the user closes the window */ - while (!glfwWindowShouldClose(window)) - { - /* Render here */ - glClear(GL_COLOR_BUFFER_BIT); - - /* Swap front and back buffers */ - glfwSwapBuffers(window); - - /* Poll for and process events */ - glfwPollEvents(); - } - - glfwTerminate(); - return 0; -} +#include +namespace py = pybind11; PYBIND11_MODULE(glpy, m) { m.doc() = "glpy a python opengl project"; // optional module docstring - m.def("pytest_glfw_window",pytest_glfw_window); + auto tests = m.def_submodule("tests","the tests module"); + + tests.def("glfw_window",&tests::glfw_window, + py::arg("width"), + py::arg("height"), + py::arg("title") + ); } \ No newline at end of file diff --git a/src/test_window.cpp b/src/test_window.cpp new file mode 100644 index 0000000..fead158 --- /dev/null +++ b/src/test_window.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +int tests::glfw_window(unsigned width,unsigned height, std::string title) +{ + GLFWwindow* window; + + /* Initialize the library */ + if (!glfwInit()) + return -1; + + /* Create a windowed mode window and its OpenGL context */ + window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL); + if (!window) + { + glfwTerminate(); + return -1; + } + + /* Make the window's context current */ + glfwMakeContextCurrent(window); + + /* Loop until the user closes the window */ + while (!glfwWindowShouldClose(window)) + { + /* Render here */ + glClear(GL_COLOR_BUFFER_BIT); + + /* Swap front and back buffers */ + glfwSwapBuffers(window); + + /* Poll for and process events */ + glfwPollEvents(); + } + + glfwTerminate(); + return 0; +} \ No newline at end of file