Category: OpenGL

some updates

It’s been a while since i did one of these, but i really like you to get up to date on a few of these things so first things first, it’s been like six months since my surgery and im doing great, i have already lost like 40Kg (88Lbs) and can really start moving around a lot more, i mean when your at 197Kg (434Lbs) just sitting down is hard not to mention standing up or walking and now i walk like 3-4Km a day, so thats good. 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 »

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 »

Screenshots

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(header), sizeof (char)*18);
File.write (reinterpret_cast(data), sizeof (char)*imageSize);
File.close();

delete[] data;
data=NULL;
}

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
glGetUniformLocation
glUniformMatrix4fv

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

in vec3 Normal;

add

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

gl_Position=projMat*pos;

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.
glVertexAttribPointer
glBindAttribLocation
glDisableVertexAttribArray
glEnableVertexAttribArray
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 http://www.opengl.org/documentation/specs/ and download the 3.0 specification and then check under the section called “The Deprecation Model”, but here are some highlights Read more »

WordPress Themes