Compare commits
2 Commits
4bd3c33eee
...
2a313fbc51
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a313fbc51 | |||
| 2c76e41fbd |
33
FullScreenQuad.hpp
Normal file
33
FullScreenQuad.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
class FullScreenQuad {
|
||||
private:
|
||||
unsigned int vao;
|
||||
public:
|
||||
FullScreenQuad();
|
||||
int getVAO() { return vao;}
|
||||
};
|
||||
|
||||
FullScreenQuad::FullScreenQuad(){
|
||||
float quadVertices[] = { // vertex attributes for a quad that fills the entire screen in Normalized Device Coordinates.
|
||||
// positions // texCoords
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
1.0f, 1.0f, 1.0f, 1.0f
|
||||
};
|
||||
unsigned int vbo;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
}
|
||||
15
main.cpp
15
main.cpp
@@ -1,6 +1,7 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdio>
|
||||
#include "FullScreenQuad.hpp"
|
||||
|
||||
float vertices[] = {
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
@@ -92,6 +93,10 @@ void linkVBO() {
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
@@ -100,7 +105,7 @@ int main(int argc, char** argv) {
|
||||
if (!glfwInit())
|
||||
return -1;
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
|
||||
window = glfwCreateWindow(800, 600, "Hello World", NULL, NULL);
|
||||
|
||||
if (!window)
|
||||
{
|
||||
@@ -119,9 +124,14 @@ int main(int argc, char** argv) {
|
||||
|
||||
glViewport(0, 0, 800, 600);
|
||||
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
unsigned int shaderProgramm = compShader();
|
||||
unsigned int VAO = initVAO();
|
||||
|
||||
FullScreenQuad fsq{};
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
processInput(window);
|
||||
@@ -136,6 +146,9 @@ int main(int argc, char** argv) {
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glBindVertexArray(fsq.getVAO());
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
/* Poll for and process events */
|
||||
glfwPollEvents();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user