Compare commits
No commits in common. "78ba3331649c7f9a616b3c871f259e1fc67bee7c" and "8350b85aa1230bfaff3c97685b72c8389a7de223" have entirely different histories.
78ba333164
...
8350b85aa1
@ -10,7 +10,6 @@ public:
|
|||||||
void setRotate(float yaw, float pitch);
|
void setRotate(float yaw, float pitch);
|
||||||
glm::mat4 getView();
|
glm::mat4 getView();
|
||||||
glm::mat4 getProjection();
|
glm::mat4 getProjection();
|
||||||
float aspect;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update();
|
void update();
|
||||||
@ -21,5 +20,6 @@ private:
|
|||||||
float yaw;
|
float yaw;
|
||||||
float pitch;
|
float pitch;
|
||||||
float fov;
|
float fov;
|
||||||
|
float aspect;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
|
|
||||||
Camera::Camera(glm::vec3 pos, float yaw, float pitch, float fov, float aspect)
|
Camera::Camera(glm::vec3 pos, float yaw, float pitch, float fov, float aspect)
|
||||||
: aspect(aspect), up(glm::vec3(0, 1, 0)), pos(pos), yaw(yaw), pitch(pitch),
|
: up(glm::vec3(0, 1, 0)), pos(pos), yaw(yaw), pitch(pitch), fov(fov),
|
||||||
fov(fov) {
|
aspect(aspect) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19
src/main.cpp
19
src/main.cpp
@ -2,8 +2,9 @@
|
|||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include <shader.hpp>
|
#include <shader.hpp>
|
||||||
#include <shapes.h>
|
#include <shapes.h>
|
||||||
#include <texture.hpp>
|
#include <texture.hpp>
|
||||||
@ -61,25 +62,26 @@ int main(void) {
|
|||||||
|
|
||||||
Camera *cam =
|
Camera *cam =
|
||||||
new Camera(glm::vec3(0.0, 0.0, 5.0), -90.0f, 0.0f, 45.0, 800.0 / 600);
|
new Camera(glm::vec3(0.0, 0.0, 5.0), -90.0f, 0.0f, 45.0, 800.0 / 600);
|
||||||
glfwSetWindowUserPointer(window, cam);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
shaderProgram->use();
|
shaderProgram->use();
|
||||||
|
shaderProgram->setInt("Tex0", 0);
|
||||||
shaderProgram->setMat4("view", cam->getView());
|
shaderProgram->setMat4("view", cam->getView());
|
||||||
shaderProgram->setMat4("projection", cam->getProjection());
|
shaderProgram->setMat4("projection", cam->getProjection());
|
||||||
|
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
texture->bind(GL_TEXTURE0);
|
|
||||||
texture2->bind(GL_TEXTURE1);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
for (unsigned int i = 0; i < 10; i++) {
|
for (unsigned int i = 0; i < 10; i++) {
|
||||||
shaderProgram->setInt("tex0", i%2);
|
if (i % 2 == 0) {
|
||||||
|
texture->bind(GL_TEXTURE0);
|
||||||
|
} else {
|
||||||
|
texture2->bind(GL_TEXTURE0);
|
||||||
|
}
|
||||||
glm::mat4 model = glm::mat4(1.0f);
|
glm::mat4 model = glm::mat4(1.0f);
|
||||||
model = glm::translate(model, cubePositions[i]);
|
model = glm::translate(model, cubePositions[i]);
|
||||||
|
|
||||||
@ -111,7 +113,4 @@ void processInput(GLFWwindow *window) {
|
|||||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
||||||
UNUSED(window);
|
UNUSED(window);
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
Camera *cam = (Camera *)glfwGetWindowUserPointer(window);
|
|
||||||
if (cam)
|
|
||||||
cam->aspect = (float)width/height;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Texture::Texture(GLenum type, const char *path) : type(type) {
|
|||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture::~Texture() {glDeleteTextures(1, &ID);}
|
Texture::~Texture() {}
|
||||||
|
|
||||||
void Texture::bind(GLenum texture) {
|
void Texture::bind(GLenum texture) {
|
||||||
glActiveTexture(texture);
|
glActiveTexture(texture);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user