Move texture creation to Renderer.c
This commit is contained in:
@@ -22,6 +22,13 @@ GLFWwindow* initOpenGL() {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// Set Global Texture Parameters
|
||||
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);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -76,7 +83,7 @@ unsigned int compileShaderProgram(const char** vertexSrc, const char** fragmentS
|
||||
|
||||
}
|
||||
|
||||
unsigned int loadCompileShader(char* vertexPath, char* fragmentPath) {
|
||||
unsigned int createShader(char* vertexPath, char* fragmentPath) {
|
||||
FILE* vertex_file = fopen(vertexPath, "r");
|
||||
FILE* fragment_file = fopen(fragmentPath, "r");
|
||||
if( vertex_file == NULL || fragment_file == NULL ) {
|
||||
@@ -115,3 +122,32 @@ unsigned int loadCompileShader(char* vertexPath, char* fragmentPath) {
|
||||
|
||||
return shaderProgram;
|
||||
}
|
||||
|
||||
unsigned int createTexture(char* path){
|
||||
// Generate Texture
|
||||
unsigned int texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
// Set Texure Parameters
|
||||
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_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Load texture image
|
||||
int width, height, channels;
|
||||
unsigned char *data = stbi_load(path, &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 %s", path);
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user