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