-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextura.cpp
More file actions
62 lines (47 loc) · 1.94 KB
/
textura.cpp
File metadata and controls
62 lines (47 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//read unsigned char from file c++: http://stackoverflow.com/questions/11214782/how-to-read-in-binary-data-and-cast-to-unsigned-char-c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "textura.hpp"
using namespace std;
GLuint textureID = -1;
int LoadBitmap(string filename)
{
void* imgData;
int imgWidth, imgHeight;
cout << "Cargando texturas\n";
textureID++;
imgData = 0;
FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilename(filename.c_str());
if (format == FIF_UNKNOWN) {
cout << "Tipo desconocido de imagen para " << filename << endl;
}
FIBITMAP* bitmap = FreeImage_Load(format, filename.c_str(), 0);
if (!bitmap) {
cout << "Fallo en la carga de imagen " << filename << endl;
}
FIBITMAP* bitmap2 = FreeImage_ConvertTo24Bits(bitmap);
FreeImage_Unload(bitmap);
imgData = FreeImage_GetBits(bitmap2);
imgWidth = FreeImage_GetWidth(bitmap2);
imgHeight = FreeImage_GetHeight(bitmap2);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //Con esto arreglamos lo de los bordes en el Skybox
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // (Actually, this one is the default)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
int formato = (FI_RGBA_RED == 0) ? GL_RGB : GL_BGR;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imgWidth, imgHeight, 0, formato, GL_UNSIGNED_BYTE, imgData);
if (imgData) {
cout << "Textura cargada del fichero " << filename << " con tamano " << imgWidth << "x" << imgHeight << endl;
}
else {
cout << "Fallo en la obtencion de datos de la imagen " << filename << endl;
return (-1);
}
cout << "Hecho\n";
return textureID;
}