Started updating tools to C++

This commit is contained in:
2023-02-06 20:28:55 -08:00
parent eacbaa54fe
commit dda126d338
6 changed files with 447 additions and 441 deletions

View File

@ -8,7 +8,7 @@ project(texturegen VERSION 1.0)
add_executable(texturegen)
target_sources(texturegen
PRIVATE
main.c
main.cpp
../../utils/file.c
../../utils/image.c
)

View File

@ -5,9 +5,11 @@
* https://opensource.org/licenses/MIT
*/
extern "C" {
#include "../../utils/common.h"
#include "../../utils/file.h"
#include "../../utils/image.h"
}
int main(int argc, char *argv[]) {
FILE *file;
@ -57,7 +59,7 @@ int main(int argc, char *argv[]) {
// Convert to floating points
len = STBI_rgb_alpha * w * h;
dataImage = malloc(sizeof(float) * len);
dataImage = (float *)malloc(sizeof(float) * len);
for(i = 0; i < len; i++) {
dataIn = dataImageRaw[i];
dataImage[i] = ((float)dataIn) / 255.0f;
@ -73,7 +75,7 @@ int main(int argc, char *argv[]) {
}
// Write info
headerBufferLength = sprintf(headerBuffer, "%i|%i|", w, h);
headerBufferLength = sprintf((char *)headerBuffer, "%i|%i|", w, h);
fwrite(headerBuffer, sizeof(uint8_t), headerBufferLength, file);
// Write texture

View File

@ -8,7 +8,7 @@ project(tilesetgen VERSION 1.0)
add_executable(tilesetgen)
target_sources(tilesetgen
PRIVATE
main.c
main.cpp
../../utils/file.c
../../utils/image.c
)

View File

@ -5,9 +5,11 @@
* https://opensource.org/licenses/MIT
*/
extern "C" {
#include "../../utils/common.h"
#include "../../utils/file.h"
#include "../../utils/image.h"
}
int main(int argc, char *argv[]) {
char *in;
@ -113,7 +115,7 @@ int main(int argc, char *argv[]) {
float tdivY = (float)divY / (float)h;
// Output buffer prep
char *buffer = malloc(sizeof(char) * (cols * rows * 48 + 48 + 48));
char *buffer = (char *)malloc(sizeof(char) * (cols * rows * 48 + 48 + 48));
buffer[0] = '\0';
sprintf(buffer, "%i|%i|%i|%i|", cols, rows, divX, divY);

View File

@ -8,7 +8,7 @@ project(truetypegen VERSION 1.0)
add_executable(truetypegen)
target_sources(truetypegen
PRIVATE
main.c
main.cpp
../../utils/file.c
../../utils/image.c
)

View File

@ -5,6 +5,7 @@
* https://opensource.org/licenses/MIT
*/
extern "C" {
#include "../../utils/common.h"
#include "../../utils/file.h"
#include "../../utils/image.h"
@ -12,6 +13,7 @@
#define STB_TRUETYPE_IMPLEMENTATION
#include <stb_truetype.h>
#endif
}
#define TRUETYPE_FIRST_CHAR 32
#define TRUETYPE_NUM_CHARS 96
@ -84,7 +86,7 @@ int main(int argc, char *args[]) {
fseek(file, 0, SEEK_SET);
// Read in all data
char *ttfData = malloc(sizeof(char) * fileSize);
char *ttfData = (char*)malloc(sizeof(char) * fileSize);
size_t readSize = fread(ttfData, 1, fileSize, file);
fclose(file);
if(readSize < fileSize) {
@ -95,12 +97,12 @@ int main(int argc, char *args[]) {
// Create bitmap data. This is a single channel color (alpha).
textureSize = width * height;
stbi_uc *bitmapData = malloc(sizeof(stbi_uc) * textureSize);
stbi_uc *bitmapData = (stbi_uc*)malloc(sizeof(stbi_uc) * textureSize);
stbtt_bakedchar characterData[TRUETYPE_NUM_CHARS];
// Now parse the TTF itself.
stbtt_BakeFontBitmap(
ttfData, 0, (float)fontSize, bitmapData,
(uint8_t*)ttfData, 0, (float)fontSize, bitmapData,
width, height,
TRUETYPE_FIRST_CHAR, TRUETYPE_NUM_CHARS,
characterData