Sunday, May 23, 2010

Yet Another Discovery (OpenGL2.0)

Adrian has been receiving a face lift with fancy glsl opengl stuff. Now I've seen good number of problems with using the GLSL shaders. But what i found today was a little more annoying. So today i thought i'd update the display drivers to a latest version because its' been a while and it's always good to have the latest ones... because all the other users might be using them. Now Adrian which was working fine starting showing a colored screen instead of the actual game, I was shocked because i haven't changed anything but a working code stopped working now.

Apparently iv'e assumed something that i shouldn't have.. see.. the vertex shader that we use has a line which goes something like this:
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
This looks fine.. if we dont' set the texture matrix, it should ideally be and identity matrix .. or so i thought. Any way... Now .. after digging through all the code.. making modifications everywhere i could think off.. I finally figured .. i just had to get rid of the gl_TextureMatrix[0].. from the above line. Now i know i shouldn't be using it if im' not initializing it.. but cmon!! it worked before what happened now?. Is it defined somewhere that the default texture matrix is not ensured to be an Identity matrix?..

Sunday, May 09, 2010


I know OpenGL2.0 has been out for a while now and i have been developing small example programs for learning purpose, But I've been putting off developing using OpenGL2.0 (GLSL) etc because I wasn't sure if people would be able to play them because of hardware issues. I wanted to develop a game which used OpenGL2.0 features. I wanted to try it out for Last PyWeek but most of the people participating did not have compatible graphics hardware so i scraped that idea. But after having looked at a couple of game engine related blog posts at, I decided i have to write a game with Graphics Engine using GLSL shaders.

So Instead of writing from scratch, I thought it would be best if I tried out on an already developed game and "Adrian" was the obvious choice. We have been updating the game since last year during our free time (yes.... this isn't a solo effort... ) and so updating graphics engine came up. I wanted to start small and so started off with the implementation of Post-Processing pipeline for the game engine. Here are the results..

You can Grab Source Code at
You can Follow Adrian Dev Blog

Toon Shading

Depth Of Field (well kinda)

Bloom (My Fav)
Normal Rendering

hope you like it :D Im' totally excited about this.. keep tracking for further updates ..

Saturday, May 08, 2010

Minute Mistakes Franatic Frustration

I've been working on updating our good old game "Adrian". Trying to update the graphics engine to use shaders, frame buffers and all that stuff. Actually the other day i found a wonderful game dev blog which discussed various graphics engine tweaks, implementations etc. I've been eager to work on something with shaders.. thought Adrian might be the best bet. So i quickly started writing some basic code for handling multiple pass rendering and some basic code for handling frame buffer objects etc. I've read a lot about glsl .. even done some examples (simple ones) before so i did not think it would hard to get stuff running.. boy was i wrong.. I struggled to get multiple textures to work in my shaders.. and the reason?.. well let me put it in code...
//vertex shader
void main()
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexcoord0;

//fragment shader
uniform sampler2D tex0;
uniform sampler2D tex1;
void main()
gl_FragColor = texture2D(tex0, gl_TexCooord[0].st) * texture2D(tex1, glTexCoord[0].st);
Looks simple right?? now how do you send / bind the uniform variables to two different textures from host program??
glBindTexture(GL_TEXTURE_2D, tex0_id);
glBindTexture(GL_TEXTURE_2D, tex1_id);

GLint h0 = glGetUniformLocation(program, "tex0");
glUniform1i(h0, 0);
GLint h1 = glGetUniformLocation(program, "tex1");
glUniform1i(h1, 1);

now the most obscure stuff is setting the sampler handle values to 0, 1, .. corresponding to the texture you bind it to..(GL_TEXTURE0, 1.. ) instead of the texture id itself.. and now most ridiculously frustrating part.. you need to call glUseProgram(program) before you can set these variables. Most people got the other stuff wrong.. but i was stuck with this problem for like 12hrs or so... actually i just figured out about this problem and thought i should document it somewhere before i forget it again.. so there you go.. if you want to tread in the glsl waters.. you better be careful.. they are very .very.. weird.. :D