Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Seyro97 en 17 Mayo 2015, 22:34 pm



Título: (Ayuda) Error al cargar BMP
Publicado por: Seyro97 en 17 Mayo 2015, 22:34 pm
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...

Código
  1. TEXTURE::TEXTURE(const char *path) {
  2. unsigned char header[54];
  3. unsigned int dataPos;
  4. unsigned int width, height, size;
  5. unsigned char *data;
  6. FILE *filePointer = fopen(path, "rb");
  7.  
  8. if(filePointer == NULL)
  9. printf_s("Error openning image file at '%s'!", path);
  10.  
  11. if(!fread(header, 1, 54, filePointer))
  12. printf_s("Error, file at '%s' isn't a real BMP file.", path);
  13.  
  14. if(header[0] != 'B' || header[1] != 'M')
  15. printf_s("Error, file at '%s' isn't a real BMP file.", path);
  16.  
  17. dataPos = *(int *)&header[0x0A];
  18. size    = *(int *)&header[0x22];
  19. width   = *(int *)&header[0x12];
  20. height  = *(int *)&header[0x16];
  21.  
  22. if(!size)
  23. size = width * height * 3;
  24.  
  25. if(!dataPos)
  26. dataPos = 54;
  27.  
  28. data = new unsigned char[size];
  29. fread(data, 1, size, filePointer);
  30.  
  31. fclose(filePointer);
  32.  
  33. glGenTextures(1, &texID);
  34.  
  35. glBindTexture(GL_TEXTURE_2D, texID);
  36.  
  37. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  38. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  39. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
  40.  
  41. glBindTexture(GL_TEXTURE_2D, 0);
  42. }

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:
Código
  1. #version 330 core
  2.  
  3. layout(location = 0) in vec4 position;
  4. layout(location = 1) in vec2 texCoords;
  5.  
  6. out DATA {
  7.    vec2 texCoords;
  8. } vs_out;
  9.  
  10. void main() {
  11.    gl_Position = position;
  12.  
  13.    vs_out.texCoords = texCoords;
  14. }

Código del Fragment Shader:
Código
  1. #version 330 core
  2.  
  3. layout(location = 0) out vec4 color;
  4.  
  5. in DATA {
  6.    vec2 texCoords;
  7. } fs_in;
  8.  
  9. uniform sampler2D sampler;
  10.  
  11. void main() {
  12.    color = texture(sampler, fs_in.texCoords);
  13. }
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...


Título: Re: (Ayuda) Error al cargar BMP
Publicado por: 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.


Título: Re: (Ayuda) Error al cargar BMP
Publicado por: Seyro97 en 18 Mayo 2015, 15:04 pm
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