-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "gibson2/core/render/pybind11"] | ||
path = gibson2/core/render/pybind11 | ||
url = https://github.com/pybind/pybind11.git | ||
[submodule "gibson2/core/render/glfw"] | ||
path = gibson2/core/render/glfw | ||
url = https://github.com/glfw/glfw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <stdio.h> | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#define GLFW_INCLUDE_NONE | ||
#include <GLFW/glfw3.h> | ||
#include <glad/gl.h> | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/numpy.h> | ||
#include <pybind11/stl.h> | ||
|
||
namespace py = pybind11; | ||
|
||
class GLFWRendererContext { | ||
public: | ||
GLFWRendererContext(int w, int h) :m_windowHeight(h), m_windowWidth(w) {}; | ||
|
||
int m_windowWidth; | ||
int m_windowHeight; | ||
|
||
int init() { | ||
// Initialize GLFW context and window | ||
if (!glfwInit()) { | ||
fprintf(stderr, "Failed to initialize GLFW.\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | ||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | ||
|
||
// Hide GLFW window by default | ||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); | ||
|
||
GLFWwindow* window = glfwCreateWindow(m_windowHeight, m_windowHeight, "Gibson VR Renderer", NULL, NULL); | ||
if (window == NULL) { | ||
fprintf(stderr, "Failed to create GLFW window.\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
glfwMakeContextCurrent(window); | ||
|
||
// Load all OpenGL function pointers through GLAD | ||
if (!gladLoadGL(glfwGetProcAddress)) | ||
{ | ||
fprintf(stderr, "Failed to load OpenGL function pointers through GLAD.\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
printf("Succesfully initialized GLFW context and window!\n"); | ||
|
||
return 0; | ||
} | ||
|
||
void release() { | ||
glfwTerminate(); | ||
} | ||
}; | ||
|
||
PYBIND11_MODULE(GLFWRendererContext, m) { | ||
m.doc() = "C++ GLFW bindings"; | ||
|
||
py::class_<GLFWRendererContext>(m, "GLFWRendererContext") | ||
.def(py::init<int, int>()) | ||
.def("init", &GLFWRendererContext::init) | ||
.def("release", &GLFWRendererContext::release); | ||
|
||
#ifdef VERSION_INFO | ||
m.attr("__version__") = VERSION_INFO; | ||
#else | ||
m.attr("__version__") = "dev"; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters