Código
TEXTURE::TEXTURE(const char *path) { unsigned char header[54]; unsigned int dataPos; unsigned int width, height, size; unsigned char *data; FILE *filePointer = fopen(path, "rb"); if(filePointer == NULL) printf_s("Error openning image file at '%s'!", path); if(!fread(header, 1, 54, filePointer)) printf_s("Error, file at '%s' isn't a real BMP file.", path); if(header[0] != 'B' || header[1] != 'M') printf_s("Error, file at '%s' isn't a real BMP file.", path); dataPos = *(int *)&header[0x0A]; size = *(int *)&header[0x22]; width = *(int *)&header[0x12]; height = *(int *)&header[0x16]; if(!size) size = width * height * 3; if(!dataPos) dataPos = 54; data = new unsigned char[size]; fread(data, 1, size, filePointer); fclose(filePointer); glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_2D, texID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); glBindTexture(GL_TEXTURE_2D, 0); }
Resultado:
Imagen original:
Código del Vertex Shader:
Código
#version 330 core layout(location = 0) in vec4 position; layout(location = 1) in vec2 texCoords; out DATA { vec2 texCoords; } vs_out; void main() { gl_Position = position; vs_out.texCoords = texCoords; }
Código del Fragment Shader:
Código
Espero que me puedan ayudar... ¡Gracias!
#version 330 core layout(location = 0) out vec4 color; in DATA { vec2 texCoords; } fs_in; uniform sampler2D sampler; void main() { color = texture(sampler, fs_in.texCoords); }
O esto es magia, o visual studio me está trolleando. Ahora si que funciona... Sinceramente, no se que pasaba...