Category: Tutorials

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.

Read more »

GLZ toolkit – basecode

The basecode is the real glue between your system and the your project itself, the goal is to never expose system specific code to your project.
Sadly i wasn’t able to get the momentous task to include things like device input (keyboard,mouse gamepad, joystick and such) or any networking started for version 2 of my basecode, but is in the planning stage at least.
The goal of this specific tutorial is to get a single  blank project up and running in at least visual studio 2013 express, but with little or no actual graphics code running (except for glClear), in short we will be replicating the zeobase2_blank project that already exists in the codebase, but it does apply to all projects.
Read more »

GLZ toolkit – installing

So its finally here version 1.0 of the GLZ toolkit, in these tutorials i am going to describe how it works is some detail.
I will do this in several parts
1. installing (this page)
2. GLZ basecode and starting up a blank project
3. textures, shaders, math and stuff
4. text and other 2d stuff
5. geometry generation
6. future and how to help

Now keep in mind that the entire project and especially the basecode was written in VC++ 2013 for windows and i am using more and more c++11 features, but the toolkit itself should be cross platform (using the latest compilers) and with any luck other platforms will be added in the future.
Read more »

Gamepads and joysticks

So i went toying around with my old sixaxis gamepad on my pc and decided to add gamepad support to one of my apps, turns out it’s not that hard so i thought i would add a quick tutorial about it.

First of all it’s worth noting that a gamepad and a joystick is the same thing from a technical perspective. secondly the specific setup is using windows own built in joystick interface which means that we are limited to 6 analog axis and 32 buttons, which is plenty as the classic playstation dualshock controller (which almost every other controller is based on in some way) only has 4 analog axis and 17 buttons (gyros and accelerometers does not count as we can’t use them). Read more »

Geometry shaders part 3

Transform feedback, is one of the tools of the trade not often discussed on the net, in fact i couldn’t find a single tutorial, so i better write one. the essential function of this little feature is to enable you to do very complicated stuff in the geometry shader, stuff that would inevitably make things run slowly, or to assemble a vbo using tiny little parts and then save it to a buffer for later use, or for that matter constant use. Read more »

Geometry shaders part 2

In this part we will be doing a bit of simple geometry instancing with a minecraft twist, basically what we are going to do is first generate a volumetric landscape of sorts, then render it using cubes, but not the usual way, we are going to do it as a particle system, which is i guess a little bit more than usual as it involves other stuff than strictly openGL, and since there are a few things i want to try out in this field you will be seeing more of it.
This tutorial assumes that you have all the stuff needed for part 1 and in addition texturing available. Read more »

Geometry shaders part 1

New in OpenGL 3.2 is so called geometry shaders, if you don’t know what they are then what the essentially do is allow you to create new or duplicate geometry. Like instead of drawing a bunch of cubes one after another you could just render a point cloud and let the geometry shader “upgrade” them to cubes, which is probably how i would render minecraft if i where it’s creator, which i would if i had a hat half as awesome as notch does.
Read more »


Hi, here is a little Yule gift for all you GL junkies out there, it’s a short quick and easy tool for taking a screen shot into the tga format, sure it’s uncompressed and doesn’t increment the file name, but it’s pretty slick.

void screenshot (char filename[160],int x, int y)
{// get the image data
long imageSize = x * y * 3;
unsigned char *data = new unsigned char[imageSize];
glReadPixels(0,0,x,y, GL_BGR,GL_UNSIGNED_BYTE,data);// split x and y sizes into bytes
int xa= x % 256;
int xb= (x-xa)/256;int ya= y % 256;
int yb= (y-ya)/256;//assemble the header
unsigned char header[18]={0,0,2,0,0,0,0,0,0,0,0,0,(char)xa,(char)xb,(char)ya,(char)yb,24,0};

// write header and data to file
fstream File(filename, ios::out | ios::binary);
File.write (reinterpret_cast<char *>(header), sizeof (char)*18);
File.write (reinterpret_cast<char *>(data), sizeof (char)*imageSize);

delete[] data;

Usage: screenshot (“test.tga”,800,600);
Just call the function with the correct window size just before SwapBuffers and it will take a screen shot of everything in the frame buffer, easy.

Running OpenGL3.0 – part3

In our third installment we are looking into replacing all the matrix math previously built into openGL, what I am going to show you replaces most of it almost exactly like openGL used to work, naturally if your doing something a bit more advanced like a game or so, I would suggest that you use your scene graph to generate new matrices.

It’s really quite simple though, and as with the previous part we have to do some changes a bit here and there, so I am going to start with the most generalized bit and work my way down, and finally end up with the classic rotating cube.
But first the prerequisites, I am assuming that you started where part 2 left off, we will also need the following functions made to work

Step 1 – the shader
it’s really not that much but after

in vec3 Normal;


uniform mat4 projMat;

this will be where we send our new matrix to.
Then later in the code you need to do something like this to use our matrix


You could use and I almost recommend that you use two matrices one for the camera and one for the model transformation, but I leave that task to you.
Please note that the order of the multiplication is important. Read more »

Running OpenGL3.0 – part2

In this part I will show you what you must do to render even the smallest speck of graphical garbage on the screen in the openGL 3.0 API, it’s somewhat simple once you have all the tools.
First you need a good GLSL shader implementation because nothing will render without it, you can use mine if you want but just remember that we are gonna modify it a bit so it can’t be to abstracted.
Next you need to take a look at the VAO tutorial since well be using that too, naturally since we are using VAO well also be using VBO and in this example I have 3 buffers with the vertex, texture and normal coordinates for a cube, you could use anything, but I am using a cube.
We are also going to use 4 new functions so go ahead am make them work as well.
Finally remove anything that has to do with matrices, well discuss those in part 3, in fact remove or comment out any deprecated function (you can find them in part 1).

Now then, there are about four steps to this, that is there are 4 things you need to change in your already existing code for things to work, so I will explain them in order. Read more »

WordPress Themes