Toggle-able AA
button Q toggles anti-aliasing (handled in RenderSystem)
This commit is contained in:
parent
0e8e98026c
commit
53810dd99f
@ -48,7 +48,7 @@ void renderQuad()
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
class RenderSystem : public EntitySystem {
|
class RenderSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
||||||
public:
|
public:
|
||||||
struct RenderObject {
|
struct RenderObject {
|
||||||
RenderObject(const glm::mat4 &matrix, const glm::vec3 &origin, unsigned int textureId, unsigned int normalId, const Mesh &mesh, float distance, const Material &material)
|
RenderObject(const glm::mat4 &matrix, const glm::vec3 &origin, unsigned int textureId, unsigned int normalId, const Mesh &mesh, float distance, const Material &material)
|
||||||
@ -63,6 +63,7 @@ public:
|
|||||||
void render(Shader shader) const {
|
void render(Shader shader) const {
|
||||||
glm::mat4 model_matrix = matrix;
|
glm::mat4 model_matrix = matrix;
|
||||||
model_matrix[3] = glm::vec4(origin, 1.0);
|
model_matrix[3] = glm::vec4(origin, 1.0);
|
||||||
|
|
||||||
shader.setMat4("model", model_matrix);
|
shader.setMat4("model", model_matrix);
|
||||||
|
|
||||||
// 0 can't be a valid texture name, so we use it for meshes without textures here
|
// 0 can't be a valid texture name, so we use it for meshes without textures here
|
||||||
@ -167,6 +168,28 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderSystem() {
|
RenderSystem() {
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void configure(World *pWorld) override {
|
||||||
|
myWorld = pWorld;
|
||||||
|
|
||||||
|
myWorld->subscribe<InputEvent>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void receive(World *pWorld, const InputEvent &event) override {
|
||||||
|
if (event.key == GLFW_KEY_Q) {
|
||||||
|
if (event.action == GLFW_PRESS) {
|
||||||
|
if (glIsEnabled(GL_MULTISAMPLE)) {
|
||||||
|
glDisable(GL_MULTISAMPLE);
|
||||||
|
} else {
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
// Configure depth map
|
// Configure depth map
|
||||||
glGenFramebuffers(1, &depthMapFBO);
|
glGenFramebuffers(1, &depthMapFBO);
|
||||||
|
|
||||||
@ -274,6 +297,8 @@ public:
|
|||||||
|
|
||||||
unsigned int depthMap;
|
unsigned int depthMap;
|
||||||
unsigned int depthMapFBO;
|
unsigned int depthMapFBO;
|
||||||
|
|
||||||
|
World *myWorld;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ECSGAME_RENDERSYSTEM_H
|
#endif //ECSGAME_RENDERSYSTEM_H
|
||||||
|
5
main.cpp
5
main.cpp
@ -46,6 +46,9 @@ int main() {
|
|||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// Anti Aliasing
|
||||||
|
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||||
|
|
||||||
/* Create a windowed mode window and its OpenGL context */
|
/* Create a windowed mode window and its OpenGL context */
|
||||||
window = glfwCreateWindow(1280, 720, "ECSGame", NULL, NULL);
|
window = glfwCreateWindow(1280, 720, "ECSGame", NULL, NULL);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
@ -204,7 +207,7 @@ int main() {
|
|||||||
renderSystem->render(world, defaultShader, shadowShader, debugShader);
|
renderSystem->render(world, defaultShader, shadowShader, debugShader);
|
||||||
|
|
||||||
ring->get<Transform>()->rotate(delta * 100.0, glm::vec3(0.0, 1.0, 0.0));
|
ring->get<Transform>()->rotate(delta * 100.0, glm::vec3(0.0, 1.0, 0.0));
|
||||||
sun->get<DirectionalLight>()->direction = glm::normalize(glm::vec3(glm::rotate(glm::mat4(1), (float)elapsed_time * 0.3f, glm::vec3(0.0, 1.0, 0.0)) * glm::vec4(1.0, 1.0, 1.0, 0.0)));
|
sun->get<DirectionalLight>()->direction = glm::normalize(glm::vec3(glm::rotate(glm::mat4(1), (float)elapsed_time * 0.5f, glm::vec3(0.0, 1.0, 0.0)) * glm::vec4(1.0, 1.0, 1.0, 0.0)));
|
||||||
|
|
||||||
/* Swap front and back buffers */
|
/* Swap front and back buffers */
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user