Move texture creation to Renderer.c

This commit is contained in:
MrFloor
2022-01-30 11:36:44 +01:00
parent 84b1a9a186
commit cc2801dcc8
3 changed files with 46 additions and 39 deletions

View File

@@ -3,7 +3,6 @@
#include <math.h>
#include <stdbool.h>
#include "stb_image.h"
#include <linmath.h>
#include "Renderer.h"
@@ -22,11 +21,12 @@ int main() {
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 1.0f
};
// Compile Shader
// CreateShader
char* vertex1 = "../assets/shaders/vertex3.glsl\0";
char* fragment1 = "../assets/shaders/fragment3.glsl\0";
unsigned int shader1;
shader1 = loadCompileShader(vertex1, fragment1);
shader1 = createShader(vertex1, fragment1);
// Initialise VBO and VAO
unsigned int VAO, VBO;
@@ -45,41 +45,9 @@ int main() {
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
// Set texture parametes
float borderColor[] = { 1.0f, 1.0f, 0.0f, 1.0f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Generate Texture
// Create Texture
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
//Set Texture Parametes
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Load Texture image
int width, height, channels;
unsigned char *data = stbi_load("../assets/textures/wall.jpg", &width, &height, &channels, 0);
if(data) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
} else {
printf("failed to load texture\n");
}
stbi_image_free(data);
texture = createTexture("../assets/textures/wall.jpg");
while(!glfwWindowShouldClose(window)) {