update
This commit is contained in:
parent
82ed26c165
commit
0d25c81cb3
@ -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)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
|
||||
|
5
include/glpy.h
Normal file
5
include/glpy.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace tests{
|
||||
int glfw_window(unsigned width,unsigned height, std::string title);
|
||||
}
|
47
src/main.cpp
47
src/main.cpp
@ -1,46 +1,17 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
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 <glpy.h>
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
39
src/test_window.cpp
Normal file
39
src/test_window.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <pybind11/stl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glpy.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user