This commit is contained in:
ZtRXR 2024-06-29 11:15:57 +08:00
parent ddcec9cb64
commit 2e69327371
10 changed files with 85 additions and 16 deletions

2
.gitignore vendored
View File

@ -26,7 +26,7 @@ build
# Compiled Static libraries
*.lai
*.la
*.a
# *.a
# Executables
*.exe

View File

@ -16,7 +16,7 @@ pybind11_add_module(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_link_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/libs)
target_link_libraries(${PROJECT_NAME} PRIVATE glew32.lib)
target_link_libraries(${PROJECT_NAME} PRIVATE glew)
add_subdirectory( ${PROJECT_SOURCE_DIR}/glfw )
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)

View File

@ -1,5 +1,9 @@
#pragma once
#include<pybind11/pybind11.h>
#include<pybind11/stl.h>
namespace py = pybind11;
namespace tests{
int glfw_window(unsigned width,unsigned height, std::string title);
int glfw_black_window(unsigned width,unsigned height,std::string title);
}

Binary file not shown.

Binary file not shown.

BIN
libs/libglew-shared.dll.a Normal file

Binary file not shown.

BIN
libs/libglew.a Normal file

Binary file not shown.

67
src/glfw_black_window.cpp Normal file
View File

@ -0,0 +1,67 @@
#include <glpy.h>
#include <pybind11/stl.h>
// #include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
int tests::glfw_black_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);
std::cout<<"-- OPEN_GL_VERSION: "<<glGetString(GL_VERSION)<<std::endl;
// float positions[6] = {
// -0.5f,-0.5f,
// 0.0f, 0.5f,
// 0.5f,-0.5f,
// };
// unsigned int buffer;
// glGenBuffers(1,&buffer);
// glBindBuffer(GL_ARRAY_BUFFER,buffer);
// glBufferData(GL_ARRAY_BUFFER,6 * sizeof(float),positions,GL_STATIC_DRAW);
// glEnableVertexAttribArray(0);
// glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,2*sizeof(float),0);
// glBindBuffer(GL_ARRAY_BUFFER,0);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
// glClear(GL_COLOR_BUFFER_BIT);
//create a triangle
// glDrawArrays(GL_TRIANGLES,0, 3);
// glBegin(GL_TRIANGLES);
// glVertex2f(-0.5f,-0.5f);
// glVertex2f(0.0f,0.5f );
// glVertex2f(0.5f,-0.5f);
// glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}

View File

@ -1,18 +1,18 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <glpy.h>
namespace py = pybind11;
PYBIND11_MODULE(glpy, m) {
m.doc() = "glpy a python opengl project"; // optional module docstring
auto tests = m.def_submodule("tests","the tests module");
tests.def("glfw_window",&tests::glfw_window,
tests.def("glfw_black_window",&tests::glfw_black_window,
py::arg("width"),
py::arg("height"),
py::arg("title")
);
// tests.def("glfw_window",&tests::glfw_window,
// py::arg("width"),
// py::arg("height"),
// py::arg("title")
// );
}

View File

@ -1,8 +1,8 @@
#include <pybind11/stl.h>
#include <glpy.h>
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glpy.h>
static int CreateShader(const std::string& vertexShader, const std::string& fragmentShader){
unsigned int program = glCreateProgram();
@ -17,8 +17,6 @@ int tests::glfw_window(unsigned width,unsigned height, std::string title)
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
if (!window)