Category: OpenGL

work in progress

A early gpu rendering of the buddaprot Read more »

OpenGL wishlist 4.0: the slot model

Time for a fourth wish-list this time i will go into more detail about one specific thing i like OpenGL to adopt, while clarifying a few things about two oldies, perhaps for openGL 5.0 but who knows.

The slot model

This model should be seen as a vision on how to unify Data and shader management within openGL, especially regarding texturing as a lot of details is actually already implemented on the geometry side, this is mostly written against the new openGL 4 specification but i make no promises of conformity.

There are three main bits to this model, these are data, slots and shaders.
Each part are separate but still connected, especially the first two.
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 »

Running OpenGL3.0 – part1

Welcome to a series I have planned on OpenGL 3.0 regarding the forward compatible mode, or in layman’s terms, using OpenGLwithout all the stuff that got cut.
It’s quite a different beast to work with, even I have problems getting my head around it since so much things that you used for every other line has to be done differently, I find myself adding the line glTranslatef(…. only to suddenly stop thinking “o, right, doesn’t work anymore”.

It’s a bit harder also as you have to use shaders or it won’t be drawn, you cant just use a VBO like before but instead you have to bind it to a input variable.
In short everything is different, but I will try to guide you trough the basic stuff, but look at it from the bright side, now you have no more excuse not to code the way it should be done.

So what got cut well quite a bit, take a look at and download the 3.0 specification and then check under the section called “The Deprecation Model”, but here are some highlights Read more »

Vertex array objects

With openGL 3 came a few cool features most of these are pretty small and quick to learn, VAOs are among these, I really didn’t want to write a full fledged tutorial about it before, but seeing as I’m changing the format to promote shorter and more article like posts, it seemed like as good as place as any to start.

There hasn’t been that much written about the vertex_array_object extension, also there is some confusion on where to use it and how.
Simply put it couldn’t be simpler, it’s used to make the daily life of using VBOs easier and the code prettier, earlier you had to call these three functions for each buffer to set up rendering, normally that would be at least 3.

glTexCoordPointer Read more »

Recent updates

Ok, a lot has happened recently, so let me update you on things and thoughts I had.
First, I finally got a real job, I am now a professional web programmer, not exactly my first choice but hey you can’t get it all, well at least it allows me to develop some ideas I have while I’m getting paid for doing things, and the upside is that it’s a pretty flexible job, being deadline based and all, I can take an extra long lunch if I need to as long as I get things done on time.
Fortunately I do a lot of back end work so deadlines and jobs are reasonably evenly spaced and phased, most of the time.

Anyway moving on to anime, my current anime viewing list is

Slayers revolution
Zero no tsukaima 3
Nogizaka Haruka no Himitsu
ToLoveRu – Trouble

See at least some of them or forfeit you license to be of the ruling class when I take over the world. Read more »

OpenGL whish list 3.0

It’s been a while, and no it’s not because of the computer, it’s because of time, time and lack of things to write about, though not this time, this is something I wanted to write all this year.
In the beginning I was just collecting my thoughts, though I really should have written it down somewhere, then as months progressed I had less and less time to think about this.
However a few things lately caught my eye that made me rethink.

1. A while back Nvidia acquired Aegia, the physics chips maker, at first I thought “great now they will add a physics sub processor to every graphics card”.
No, they added it trough cuda, and I didn’t get it since although the gpu can do it well, any use of the gpu limits your frame rate, and that is generally considered bad.
In essence computing more objects means you can render less objects. Read more »

Playing catch up

This post will be the last one I write… on this computer, the reason being the pile of assorted powerful computer parts on the floor, though it will take some time before it can permanently turn this computer off, but it’s worth it.
I chose an Intel core 2 quad cpu and the new 9600gt (which is so hot of the manufacturing floor it’s still sort of luke warm) series among other things.
But for now prepare for another composite post.

I suggest these series (in no apparent order), see them or fail as a human being.

Lucky star
Minami-ke Okawari
You’re Under Arrest! Full Throttle
Goshuushou-sama Ninomiya-kun
Hayate no Gotoku
Rosario + Vampire Read more »

WordPress Themes