This commit is contained in:
ZtRXR 2024-06-29 17:32:40 +08:00
parent 6b41ac50e9
commit 748e09a7c2
4 changed files with 63 additions and 5 deletions

View File

@ -4,6 +4,7 @@
namespace py = pybind11;
namespace tests{
int glfw_window(unsigned width,unsigned height, std::string title);
int glfw_shader(unsigned width,unsigned height, std::string title);
int glfw_black_window(unsigned width,unsigned height,std::string title);
int glfw_basic_triangle(unsigned width,unsigned height, std::string title);
}

View File

@ -0,0 +1,52 @@
#include <glpy.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
int tests::glfw_basic_triangle(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;
}
glfwMakeContextCurrent(window);
std::cout<<"-- OPEN_GL_VERSION: "<<glGetString(GL_VERSION)<<std::endl;
/* 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);
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

@ -9,7 +9,7 @@ static int CreateShader(const std::string& vertexShader, const std::string& frag
unsigned int vs = glCreateShader(GL_VERTEX_SHADER);
}
int tests::glfw_window(unsigned width,unsigned height, std::string title)
int tests::glfw_shader(unsigned width,unsigned height, std::string title)
{
GLFWwindow* window;

View File

@ -9,8 +9,13 @@ PYBIND11_MODULE(glpy, m) {
py::arg("height"),
py::arg("title")
);
tests.def("glfw_basic_triangle",&tests::glfw_basic_triangle,
py::arg("width"),
py::arg("height"),
py::arg("title")
);
tests.def("glfw_window",&tests::glfw_window,
tests.def("glfw_shader",&tests::glfw_shader,
py::arg("width"),
py::arg("height"),
py::arg("title")