35 glutInit(&argc, NULL);
36 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
37 glutCreateWindow(
"DXT");
43#define CHECK_EXTENSION(extension) \
44 if ( !glewIsSupported(extension) ) { \
45 fprintf(stderr, "OpenGL extension '%s' is missing!\n", extension); \
58 printf(
"Graphic Card: %s\n", glGetString(GL_RENDERER));
59 printf(
"OpenGL version: %s\n", glGetString(GL_VERSION));
60 printf(
"GLSL version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
70 file = fopen(filename,
"rb");
72 fprintf(stderr,
"Failed open %s for reading!\n", filename);
76 int data_size = width * height * 3;
77 unsigned char* data = (
unsigned char*)malloc(data_size *
sizeof(
unsigned char));
78 if ( (
size_t) data_size != fread(data,
sizeof(
unsigned char), data_size, file) ) {
79 fprintf(stderr,
"Failed to load image data [%d bytes] from file %s!\n", data_size, filename);
85 for (
int y = 0; y < height; y++ ) {
86 for (
int x = 0; x < width; x++ ) {
87 int index = 4 * ((y * width) + x);
88 int index_data = 3 * ((y * width) + x);
92 (*image)[index + 3] = 1.0;
99 printf(
"Load Image [file: %s, size: %d bytes, resolution: %dx%d]\n", filename, data_size, width, height);
110 file = fopen(filename,
"wb");
112 fprintf(stderr,
"Failed open %s for writing!\n", filename);
116 int data_size = width * height * 3;
117 unsigned char* data = (
unsigned char*)malloc(data_size *
sizeof(
unsigned char));
118 for (
int y = 0; y < height; y++ ) {
119 for (
int x = 0; x < width; x++ ) {
120 int index = 4 * ((y * width) + x);
121 int index_data = 3 * ((y * width) + x);
122 data[index_data + 0] = (
unsigned char)(image[index + 0]);
123 data[index_data + 1] = (
unsigned char)(image[index + 1]);
124 data[index_data + 2] = (
unsigned char)(image[index + 2]);
128 if ( (
size_t) data_size != fwrite(data,
sizeof(
unsigned char), data_size, file) ) {
129 fprintf(stderr,
"Failed to write image data [%d bytes] to file %s!\n", width * height * 3, filename);
137 printf(
"Save Image [file: %s, size: %d bytes, resolution: %dx%d]\n", filename, data_size, width, height);
148 file = fopen(filename,
"rb");
150 fprintf(stderr,
"Failed open %s for reading!\n", filename);
154 fseek(file, 0, SEEK_END);
155 *data_size = ftell(file);
157 *data = (
unsigned char*)malloc(*data_size *
sizeof(
unsigned char));
158 if ( (
size_t) *data_size != fread(*data,
sizeof(
unsigned char), *data_size, file) ) {
159 fprintf(stderr,
"Failed to load image data [%d bytes] from file %s!\n", *data_size, filename);
165 printf(
"Load Compressed Image [file: %s, size: %d bytes]\n", filename, *data_size);
176 file = fopen(filename,
"wb");
178 fprintf(stderr,
"Failed open %s for writing!\n", filename);
182 if ( (
size_t) image_size != fwrite(image,
sizeof(
unsigned char), image_size, file) ) {
183 fprintf(stderr,
"Failed to write image data [%d bytes] to file %s!\n", image_size, filename);
189 printf(
"Save Compressed Image [file: %s, size: %d bytes]\n", filename, image_size);
208 free(image_compressed);
int dxt_image_compressed_load_from_file(const char *filename, unsigned char **data, int *data_size)
int dxt_image_destroy(DXT_IMAGE_TYPE *image)
int dxt_image_load_from_file(const char *filename, int width, int height, DXT_IMAGE_TYPE **image)
int dxt_image_save_to_file(const char *filename, DXT_IMAGE_TYPE *image, int width, int height)
int dxt_image_compressed_destroy(unsigned char *image_compressed)
int dxt_image_compressed_save_to_file(const char *filename, unsigned char *image, int image_size)
#define CHECK_EXTENSION(extension)