I am looking to store texture information in a database file (Or a file where the user cannot readily edit or open it). I want to save an array of 4 textures to a .dat file, I do not want the program to have to open a bitmap file every time it is run. The file export code is towards the end, is this the proper way to store such information?
char *image_path = "Gui_bkgd.bmp";
char *image_path2 = "1.bmp";
char *image_path3 = "2.bmp";
char *image_path4 = "3.bmp";
SDL_Surface *image = IMG_Load (image_path);
if(!image)
{
std::cout << "Error Cannot load image Gui_bkgd.bmp
";
}
SDL_Surface *image2 = IMG_Load (image_path2);
if (!image2)
{
std::cout << "Error Cannot load image 1.bmp
";
}
SDL_Surface *image3 = IMG_Load (image_path3);
if (!image3)
{
std::cout << "Error Cannot load image 2.bmp
";
}
SDL_Surface *image4 = IMG_Load (image_path3);
if (!image4)
{
std::cout << "Error Cannot load image 3.bmp
";
}
glEnable(GL_TEXTURE_2D);
static GLuint textures[4];
glGenTextures(4, textures); //Number of textures stored in array name specified
//Background texture
glBindTexture(GL_TEXTURE_2D, textures[0]);//Texture 0 is the background
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Map the surface to the texture in video memory
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, image->w, image->h, 0, GL_BGR, GL_UNSIGNED_BYTE, image->pixels); //GL_BITMAP
//Assigning texture pads their data
//arbitrary textures 1 - 4
for(int i = 1; i < 4; i++ )
{
glBindTexture(GL_TEXTURE_2D, textures[i]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, image->w, image->h, 0, GL_BGR, GL_UNSIGNED_BYTE, image->pixels); //GL_BITMAP
}
SDL_FreeSurface ( image );
SDL_FreeSurface ( image2 );
SDL_FreeSurface ( image3 );
SDL_FreeSurface ( image4 );
/*Database Export*/
FILE *file;
int n = 4;
file = fopen("Data.dat", "w");
fprintf(file, "%u
", textures[0]);
for (int i = 0; i > n; i++)
{
fprintf(file, "%u
", textures[i]);
}
fclose(file);
glDisable(GL_TEXTURE_2D);