Compare commits

..

No commits in common. "1409eb78ae1f55b130c69a6dbe72c1632bb4edf9" and "c085fdbf5ad10f57788a5fc50a5c05945d7da08c" have entirely different histories.

9 changed files with 24 additions and 8077 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.direnv .direnv
*.o *.o
ogl ogl
*~

View File

@ -18,14 +18,6 @@ unsigned int sqr_indices[] = {
1, 2, 3 /*br triangle*/ 1, 2, 3 /*br triangle*/
}; };
float sqr_tex_vertices[] = {
/*positions*colors*texture coords*/
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, /*top right*/
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*bottom right*/
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, /*bottom left*/
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f /*top left*/
};
const char *basicVertexShaderSource = const char *basicVertexShaderSource =
"#version 330 core\n" "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n" "layout (location = 0) in vec3 aPos;\n"
@ -63,8 +55,7 @@ const char *rgbFragmentShaderSource = "#version 330 core\n"
" FragColor = vec4(color, 1.0);\n" " FragColor = vec4(color, 1.0);\n"
"}\0"; "}\0";
const char *rgbPulseFragmentShaderSource = const char *rgbPulseFragmentShaderSource = "#version 330 core\n"
"#version 330 core\n"
"out vec4 FragColor;\n" "out vec4 FragColor;\n"
"in vec3 color;\n" "in vec3 color;\n"
"uniform float u_time;" "uniform float u_time;"

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
#version 330 core
out vec4 FragColor;
in vec3 ourColor;
in vec2 TexCoord;
uniform sampler2D tex0;
void main()
{
FragColor = texture(Tex0, TexCoord) * vec4(ourColor, 1.0);
}

View File

@ -1,14 +0,0 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;
out vec3 ourColor;
out vec2 TexCoord;
void main()
{
gl_Position = vec4(aPos, 1.0);
ourColor = aColor;
TexCoord = aTexCoord;
}

View File

@ -2,15 +2,15 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#include <shader.hpp>
#include <shapes.h> #include <shapes.h>
#include <stb_image.h> #include <shader.hpp>
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
void processInput(GLFWwindow *window); void processInput(GLFWwindow *window);
void framebuffer_size_callback(GLFWwindow *window, int width, int height); void framebuffer_size_callback(GLFWwindow *window, int width, int height);
int main(void) { int main(void) {
int tmp = 0; int tmp = 0;
@ -36,48 +36,20 @@ int main(void) {
glGenBuffers(1, &VBO); glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(sqr_tex_vertices), sqr_tex_vertices, glBufferData(GL_ARRAY_BUFFER, sizeof(tri_rgb_vertices), tri_rgb_vertices,
GL_STATIC_DRAW); GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)(3 * sizeof(float)));
(void *)(3 * sizeof(float)));
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), /*
(void *)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
glGenBuffers(1, &EBO); glGenBuffers(1, &EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sqr_indices), sqr_indices, glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sqr_indices), sqr_indices, GL_STATIC_DRAW);
GL_STATIC_DRAW); */
Shader *shaderProgram = Shader* shaderProgram = new Shader("./shaders/rgbPulseVert.glsl","./shaders/rgbPulseFrag.glsl");
new Shader("./shaders/TexVert.glsl", "./shaders/TexFrag.glsl");
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
stbi_set_flip_vertically_on_load(true);
int width, height, nrChannels;
unsigned char *data =
stbi_load("./texture/container.jpg", &width, &height, &nrChannels, 0);
if (data) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
} else {
std::cout << "Failed to load texture" << std::endl;
}
stbi_image_free(data);
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
processInput(window); processInput(window);
@ -86,12 +58,11 @@ int main(void) {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
shaderProgram->use(); shaderProgram->use();
shaderProgram->setInt("Tex0",0); shaderProgram->setFloat("u_time",glfwGetTime());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(VAO); glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();

View File

@ -1,2 +0,0 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 KiB