Home

Advertisement

Customize

Some Code - GLUT Application, Simple Texture Mapping

Oct. 30th, 2005 | 10:55 pm
mood: geeky

Coding - Finally

Trying to code a small glut application which will load two small shaders to perform displacement mapping. Finally got a small glut program working. pitiful result for a couple of hours work. But there was some funny issue with the texture setup.

This is the code I had for texture setup :

glGenTextures(1,&texName);
glBindTexture(GL_TEXTURE_2D,texName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,8,8,0,GL_RGBA,GL_INT,NMap);

NMap was a 4x4x3 arrays of ints which held the texture ( just plane blue square where I had used 1 as the blue component). No matter what I did, I ended up with a blank screen. The problem was this. OpenGL maps ints to color values in such a way that only the maximum value stored by an int to 1 and the minimum value stored by it is mapped to -1 (or 0 if its an unsigned int) ... for example, for a 4 byte signed int, the value 2147483647 is mapped to 1.0 and the negative of that is mapped to -1. So, the value 1 which I was using is so teeny that it was just being mapped to 0 and I was getting the blank screen ! ... one hour to figure that out ... and I had help from John.

GLUT API Version 3
http://www.opengl.org/resources/libraries/glut/spec3/spec3.html

Parallax Mapping - ATI
http://www.ati.com/developer/gdc/Tatarchuk-ParallaxOcclusionMapping-FINAL_Print.pdf

Another one on Parallax Mapping from ATI
http://www.ati.com/developer/SIGGRAPH05/Tatarchuk-ParallaxOcclusionMapping-Sketch-print.pdf

Overview of Bump Mapping from Delphi3D
http://www.delphi3d.net/articles/viewarticle.php?article=bumpmapping.htm

Link | Leave a comment | Add to Memories | Tell a Friend