code

So you really want top get your hands dirty?
You know C++ by heart?

Be our guest!

Here is a sample of C++ code, on how to use our library:



#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "w3texlib.hpp"

// ---- Helper routines

// Various small support routines for .DDS saving and error reporting
// (not reproduced here for clarity)

// ---- Actual program

// Calc callback
static bool CalcCallback(int current,int max)
{
printf("rcalc... %3d%%",current*100/max);
return true; // return true unless you wish to abort calculation
}

int main()
{
static const char fileName[] = "demo.ktx";

W3TextureContext context;
unsigned char *data;

// load demo file
if(!(data = loadFile(fileName)))
errorExit("couldn't load data file '%s'!\n",fileName);

if(!context.Load(data))
errorExit("error in data file '%s'!\n",fileName);

// calculate everything
if(!context.Calculate(CalcCallback))
errorExit("error during calc.\n");

printf("\n");

// frees the document and associated data (only final images are left afterwards)
context.FreeDocument();

// save images
printf("saving images...\n"); for(int i=0;i<context.GetImageCount();i++)
{
const W3Image *img = context.GetImageByNumber(i);
char namebuf[512];

sprintf(namebuf,"%s.dds",context.GetImageName(i));
saveImageDDS(img,namebuf);

printf("%3d. %s\n",i+1,namebuf);
}

return 0;
}