Hola, muy buenas a tod@s. Hoy tengo una duda sobre como cargar BMP en la RAM para pasarsela a OpenGL. Bueno, se podría decir que casi lo consigo, pero no!. Mejor vean por ustedes mismos el resultado, y a ver si alguien ve el error...
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:
(http://thumbs.subefotos.com/8154459b60fa07ce9859f6c75eb32f34o.jpg)
Imagen original:
(http://k33.kn3.net/C/B/A/4/0/C/DB2.bmp)
Código del Vertex Shader:
#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:
#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);
}
Espero que me puedan ayudar... ¡Gracias!
O esto es magia, o visual studio me está trolleando. Ahora si que funciona... Sinceramente, no se que pasaba...
No, o no habias recompilado o estas ejecutando manualmente una version antigua (compilaste relase x64 y ejecutaste debug x86 por ejemplo) o vaya uno a saber.
Cita de: Eternal Idol en 18 Mayo 2015, 11:04 AM
No, o no habias recompilado o estas ejecutando manualmente una version antigua (compilaste relase x64 y ejecutaste debug x86 por ejemplo) o vaya uno a saber.
A saber xD
Pero juraría no haber hecho nada, y no tengo versiones antiguas. tampoco recompilé xD