Started updating tools to C++
This commit is contained in:
@ -8,7 +8,7 @@ project(texturegen VERSION 1.0)
|
|||||||
add_executable(texturegen)
|
add_executable(texturegen)
|
||||||
target_sources(texturegen
|
target_sources(texturegen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.c
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.c
|
||||||
../../utils/image.c
|
../../utils/image.c
|
||||||
)
|
)
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/common.h"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/file.h"
|
||||||
#include "../../utils/image.h"
|
#include "../../utils/image.h"
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
@ -57,7 +59,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// Convert to floating points
|
// Convert to floating points
|
||||||
len = STBI_rgb_alpha * w * h;
|
len = STBI_rgb_alpha * w * h;
|
||||||
dataImage = malloc(sizeof(float) * len);
|
dataImage = (float *)malloc(sizeof(float) * len);
|
||||||
for(i = 0; i < len; i++) {
|
for(i = 0; i < len; i++) {
|
||||||
dataIn = dataImageRaw[i];
|
dataIn = dataImageRaw[i];
|
||||||
dataImage[i] = ((float)dataIn) / 255.0f;
|
dataImage[i] = ((float)dataIn) / 255.0f;
|
||||||
@ -73,7 +75,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write info
|
// Write info
|
||||||
headerBufferLength = sprintf(headerBuffer, "%i|%i|", w, h);
|
headerBufferLength = sprintf((char *)headerBuffer, "%i|%i|", w, h);
|
||||||
fwrite(headerBuffer, sizeof(uint8_t), headerBufferLength, file);
|
fwrite(headerBuffer, sizeof(uint8_t), headerBufferLength, file);
|
||||||
|
|
||||||
// Write texture
|
// Write texture
|
@ -8,7 +8,7 @@ project(tilesetgen VERSION 1.0)
|
|||||||
add_executable(tilesetgen)
|
add_executable(tilesetgen)
|
||||||
target_sources(tilesetgen
|
target_sources(tilesetgen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.c
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.c
|
||||||
../../utils/image.c
|
../../utils/image.c
|
||||||
)
|
)
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/common.h"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/file.h"
|
||||||
#include "../../utils/image.h"
|
#include "../../utils/image.h"
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *in;
|
char *in;
|
||||||
@ -113,7 +115,7 @@ int main(int argc, char *argv[]) {
|
|||||||
float tdivY = (float)divY / (float)h;
|
float tdivY = (float)divY / (float)h;
|
||||||
|
|
||||||
// Output buffer prep
|
// 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';
|
buffer[0] = '\0';
|
||||||
|
|
||||||
sprintf(buffer, "%i|%i|%i|%i|", cols, rows, divX, divY);
|
sprintf(buffer, "%i|%i|%i|%i|", cols, rows, divX, divY);
|
@ -8,7 +8,7 @@ project(truetypegen VERSION 1.0)
|
|||||||
add_executable(truetypegen)
|
add_executable(truetypegen)
|
||||||
target_sources(truetypegen
|
target_sources(truetypegen
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.c
|
main.cpp
|
||||||
../../utils/file.c
|
../../utils/file.c
|
||||||
../../utils/image.c
|
../../utils/image.c
|
||||||
)
|
)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#include "../../utils/common.h"
|
#include "../../utils/common.h"
|
||||||
#include "../../utils/file.h"
|
#include "../../utils/file.h"
|
||||||
#include "../../utils/image.h"
|
#include "../../utils/image.h"
|
||||||
@ -12,6 +13,7 @@
|
|||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
#include <stb_truetype.h>
|
#include <stb_truetype.h>
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#define TRUETYPE_FIRST_CHAR 32
|
#define TRUETYPE_FIRST_CHAR 32
|
||||||
#define TRUETYPE_NUM_CHARS 96
|
#define TRUETYPE_NUM_CHARS 96
|
||||||
@ -84,7 +86,7 @@ int main(int argc, char *args[]) {
|
|||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
|
|
||||||
// Read in all data
|
// 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);
|
size_t readSize = fread(ttfData, 1, fileSize, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if(readSize < fileSize) {
|
if(readSize < fileSize) {
|
||||||
@ -95,12 +97,12 @@ int main(int argc, char *args[]) {
|
|||||||
|
|
||||||
// Create bitmap data. This is a single channel color (alpha).
|
// Create bitmap data. This is a single channel color (alpha).
|
||||||
textureSize = width * height;
|
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];
|
stbtt_bakedchar characterData[TRUETYPE_NUM_CHARS];
|
||||||
|
|
||||||
// Now parse the TTF itself.
|
// Now parse the TTF itself.
|
||||||
stbtt_BakeFontBitmap(
|
stbtt_BakeFontBitmap(
|
||||||
ttfData, 0, (float)fontSize, bitmapData,
|
(uint8_t*)ttfData, 0, (float)fontSize, bitmapData,
|
||||||
width, height,
|
width, height,
|
||||||
TRUETYPE_FIRST_CHAR, TRUETYPE_NUM_CHARS,
|
TRUETYPE_FIRST_CHAR, TRUETYPE_NUM_CHARS,
|
||||||
characterData
|
characterData
|
Reference in New Issue
Block a user