GLZ toolkit – Textures, shaders, math and stuff

In this part we will discuss the various tools regarding textures and shaders but i will also touch a little on the “math” library which is not really a math library  but rather a collection of small neat little helper functions, a lot of which i have written over the last 15 years and still use pretty regularly.

Textures (ztool-tex.h/ztool-tex.cpp)

currently there is two ways of making a texture first you can call the glzLoadTexture function or load the header, data and make the texture separatly (having the raw data can be useful at times).

But normally you would only want to use
unsigned int glzLoadTexture(char filename[255], glzTexFilter filter);

Simply give it a filename and a filter mode and it will return the texture handle, couldn’t be simpler.
For now it only reads TGA files but i plan on adding other formats later.

As for the texture filter i normally use glzTexFilter::ANSIO_MAX for textures that are used on 3D objects and glzTexFilter::LINEAR for 2d such as text.
And speaking of text, sometimes when i generate new fonts the image origin is not the default one (i get top left corner instead of bottom left), in that case use glzReadTgaHead to read the header which contains the image origin the texture is using

Now the ztool-tex.h/cpp files also contains a screenshot tool
void glzScreenShot(char filename[255], int x, int y, glzTexCompression type);
void glzScreenShotADV(char filename[255], int xoffset, int yoffset, int x, int y, int lossy, glzTexCompression type);
They work pretty much the same, input filename, width, height and compression mode and it saves the current framebuffer to that file.
The glzScreenShotADV function adds the ability to offset the image and add a lossy component to the compression (btw. never use lossy compression in a animation, it produces horrible artifacts visible in a video but not a still picture).

Shaders (ztool-shader.h/ztool-shader.cpp)

The process for loading shaders is simple, just load the shader and ling the program, there are two overloads, one with geometry shaders and one without

GLhandleARB  ProgramObject;
ProgramObject = glzShaderLoad(“data\\glsl.vert”, “data\\glsl.frag”, glzVAOType::AUTO);

glzVAOType::AUTO indicates that if your rendering any object either generated or otherwise with glzVAOType::AUTO it will work well if the shader has these tree lines is it

in vec3 Position;
in vec2 TexCoord;
in vec3 Normal;

There is not much more i can say about it, but i will add more and possibly redo and improve on a lot of this.

Math (ztool-glz.h/ztool-glz.cpp)

The glz library is hard to explain properly since it contains such a large(and growing) amount of functions, so take a look into the file as they are pretty well commented.
But a brief summary is in order

Various random function
Various modulo functions or modulo related functions
Vector functions (dot product, magnitude, normalize and so on)
Image coordinate remapping and image reading functions.
Color conversion
Remap to range
Various atlas generation functions
Complete set of openGL matrix replacement code
Qanternion addition to the above code
And a few thing s more

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment


WordPress Themes