I hate my life
This commit is contained in:
@ -7,13 +7,10 @@ cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
SET(TOOL_NAME texture_generation)
|
||||
set(TOOL_TEXTURE_GENERATION_SOURCE_DIR)
|
||||
|
||||
# Build Tool
|
||||
project(${TOOL_NAME} VERSION 1.0)
|
||||
add_executable(${TOOL_NAME})
|
||||
target_sources(${TOOL_NAME}
|
||||
project(texture_generation VERSION 1.0)
|
||||
add_executable(texture_generation)
|
||||
target_sources(texture_generation
|
||||
PRIVATE
|
||||
texture_generation.c
|
||||
../utils/file.c
|
||||
@ -22,7 +19,7 @@ target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/../
|
||||
)
|
||||
target_link_libraries(${TOOL_NAME}
|
||||
target_link_libraries(texture_generation
|
||||
PUBLIC
|
||||
stb
|
||||
)
|
||||
@ -30,8 +27,8 @@ target_link_libraries(${TOOL_NAME}
|
||||
# Function for creating the target
|
||||
function(tool_texture target in out)
|
||||
add_custom_target(${target}
|
||||
COMMAND texture_generation "${ROOT_DIR}/${ASSETS_DIR}/${in}" "${ASSETS_DIR}/${out}"
|
||||
COMMAND texture_generation "${in}" "${ASSETS_BUILD_DIR}/${out}"
|
||||
COMMENT "Generating texture ${target} from ${in}"
|
||||
SOURCES ${TOOL_NAME}
|
||||
DEPENDS texture_generation ${ARGN}
|
||||
)
|
||||
endfunction()
|
@ -5,8 +5,10 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../utils/common.h"
|
||||
#include "../utils/file.h"
|
||||
#include "../utils/image.h"
|
||||
|
||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
@ -22,6 +24,7 @@ int RESIZE_SCALES[RESIZE_VARIANT_COUNT] = { 1, 2, 3, 4 };
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *file;
|
||||
char path[FILENAME_MAX + 1];
|
||||
char xml[2048];
|
||||
char *in;
|
||||
char *out;
|
||||
char pathSep;
|
||||
@ -38,7 +41,7 @@ int main(int argc, char *argv[]) {
|
||||
pathSep = FILE_PATH_SEP;
|
||||
in = argv[1];
|
||||
out = argv[2];
|
||||
|
||||
|
||||
// Normalize slashes
|
||||
fileNormalizeSlashes(in);
|
||||
fileNormalizeSlashes(out);
|
||||
@ -57,6 +60,13 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
// Begin XML buffering
|
||||
xml[0] = '\0';
|
||||
sprintf(xml,
|
||||
"<texture channels=\"%i\" width=\"%i\" height=\"%i\">",
|
||||
channels, w, h
|
||||
);
|
||||
|
||||
// For each scale.
|
||||
for(i = 0; i < RESIZE_VARIANT_COUNT; i++) {
|
||||
// Resize image
|
||||
@ -68,22 +78,15 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Determine output path
|
||||
path[0] = '\0';
|
||||
if(getcwd(path,sizeof(path)) == NULL) {
|
||||
printf("Failed to get current dir!\n");
|
||||
stbi_image_free(dataOriginal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Determine Output path
|
||||
sprintf(path, "%s%c%s_%i.texture", path, FILE_PATH_SEP, out, scale);
|
||||
printf("Writing %s\n", path);
|
||||
sprintf(path, "%s_%i.texture", out, scale);
|
||||
|
||||
// Open output file
|
||||
fileMkdirp(path);
|
||||
printf("OPOut %s\n", path);
|
||||
|
||||
file = fopen(path, "wb");
|
||||
if(file == NULL) {
|
||||
printf("Invalid file out!\n");
|
||||
printf("Invalid texture file out!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -93,10 +96,33 @@ int main(int argc, char *argv[]) {
|
||||
// Cleanup
|
||||
fclose(file);
|
||||
free(dataResized);
|
||||
|
||||
// Buffer XML info.
|
||||
sprintf(xml,
|
||||
"%s\n <texture-scale scale=\"%i\" width=\"%i\" height=\"%i\" asset=\"%s_%i.texture\" />",
|
||||
xml, scale, rw, rh, out, scale
|
||||
);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
stbi_image_free(dataOriginal);
|
||||
|
||||
// Finalize XML
|
||||
sprintf(xml, "%s\n</texture>", xml);
|
||||
|
||||
// Determine XML path
|
||||
path[0] = '\0';
|
||||
sprintf(path, "%s.xml", out);
|
||||
|
||||
// Write XML
|
||||
fileMkdirp(path);
|
||||
file = fopen(path, "w");
|
||||
if(file == NULL) {
|
||||
printf("Invalid XML File Out!\n");
|
||||
return 1;
|
||||
}
|
||||
fwrite(xml, sizeof(char), strlen(xml), file);
|
||||
fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user