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