daily update
This commit is contained in:
34
main.cpp
34
main.cpp
@@ -3,19 +3,12 @@
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <functional>
|
||||
#include <glm/fwd.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void process_input(GLFWwindow* window) {
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
}
|
||||
|
||||
class GLWidget {
|
||||
|
||||
@@ -24,7 +17,8 @@ public:
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
GLWidget(ViewPort port) : viewport_(port) {
|
||||
GLWidget(ViewPort port) : viewport_(port),
|
||||
window_(nullptr, [](GLFWwindow* w){if(w) glfwDestroyWindow(w);}) {
|
||||
lastX_ = port.width / 2;
|
||||
lastY_ = port.height / 2;
|
||||
}
|
||||
@@ -36,20 +30,21 @@ public:
|
||||
}
|
||||
|
||||
bool initGeometry() {
|
||||
window = std::make_unique(glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL));
|
||||
if (window == NULL) {
|
||||
// window_ = std::make_unique<GLFWwindow*>(glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL));
|
||||
window_.reset(glfwCreateWindow(800, 600, "3dviewer", nullptr, nullptr));
|
||||
if (!window_) {
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwMakeContextCurrent(window_.get());
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
std::cout << "Failed to initialize GLAD" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
glViewport(0, 0, 800, 600);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetFramebufferSizeCallback(window_.get(), &GLWidget::framebuffer_size_callback);
|
||||
}
|
||||
public:
|
||||
bool initBgProgram(const std::string& vpath, const std::string fpath) {
|
||||
@@ -109,9 +104,20 @@ public:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||
glViewport(0, 0, viewport_.width, viewport_.height);
|
||||
}
|
||||
|
||||
void process_input(GLFWwindow* window) {
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::unique_ptr<LOpenGLProgram> bgProg_;
|
||||
std::unique_ptr<GLFWwindow> window_;
|
||||
std::unique_ptr<GLFWwindow, std::function<void(GLFWwindow*)>> window_;
|
||||
unsigned int bgVao_;
|
||||
unsigned int bgVbo_;
|
||||
ViewPort viewport_{800, 600};
|
||||
|
||||
Reference in New Issue
Block a user