how does one use normal maps?

I have been searching the internet this weekend looking for information on using normal maps, but I am not having much luck on finding what I want. Mostly everything I came across is either in C, about making normal maps in image editing programs, or isn’t the effect I am looking for (i.e. bump maps in NeHe tutorial #22). I would like to be able to give things a rich textured look like this person had done in his first screen shot: http://www.java-gaming.org/index.php/topic,16180.0.html. I already have a regular texture and a normal map in dds format. I guess my question overall is how does one do normal maps in jogl?

Thanks

Most of the C code you’ve seen will apply, you just have to translate the GL calls into the Jogl equivilent. Basically you just need to bind the textures you want (including the normal map) and set up the right state to combine them. That means writing a suitable shader, or if you want to do it the hard way then setting up texture environments and register combiners.

Personally I’d go with a GLSL shader - any good graphics book should have the basic maths you’ll need to convert to shader code.

Having no experience in shaders, I would probably have to start with the basics first before I could move on to what I want to do. I have found a standard snippet of a vertex shader that supposedly is for doing bump maps. I am now trying to figure out how to have it interface with my jogl code. If anyone could point me to a source on how that is done, I would be most appreciative. In the meantime, I’ll just keep searching on the internet.

In that case you want this: http://www.amazon.com/OpenGL-R-Shading-Language-2nd/dp/0321334892

And you can’t do bump mapping in a vertex shader, by definition it has to be per-pixel and therefore done in a fragment shader (although you often have a vertex shader to feed inputs into the fragment shader).

Well, I have a set of both a vertex and fragment shader. At this point, I just want to see how to actually get anything running even if it is the wrong thing. Since I’m not in the computer science field, I would have trouble justifying the purchase of the orange book. Are there resources online for using jogl and shaders?

I still haven’t found any jogl shader resources, but I have been trying my best to work through the examples in C which is a little slow having never learned C. I seem to be in the same spot that I was when I last posted (I can’t figure out how to get the shader to interface with my jogl program).

Here is what I have in my attempt to color an otherwise red quad blue via a fragment shader:

I have made a class that implements GLEventListener and inside the init(GLAutoDrawable) method I have this among other things:

//SHADER CREATION
int shaderProgram = gl.glCreateProgram(); //this int is available to all methods in the class
int fragShader = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);
try
{
	BufferedReader fragShaderReader = new BufferedReader(new FileReader("fragShader.glsl"));
	String fragShaderSource = "", tempFragSCR;
	while((tempFragSCR = fragShaderReader.readLine()) != null)
	{
		fragShaderSource += tempFragSCR + "\n";
	}
	String[] fragSourceArray = {fragShaderSource};
	int[] strLength = {fragShaderSource.length()};
	gl.glShaderSource(fragShader,1,fragSourceArray,strLength,0);
}catch(Exception e){System.out.println(e);}
gl.glCompileShader(fragShader);
gl.glAttachShader(shaderProgram,fragShader);
gl.glLinkProgram(shaderProgram);

I am not certain if I am doing the glShaderSource method correctly.

In my display(GLAutoDrawable) method, I have these lines which successfully draws a red quad in the center of my canvas. I figured that the line “gl.glUseProgram(shaderProgram);” would apply the fragment shader and make all the pixels blue, but it seems to have no effect:

gl.glColor3f(1.0f,0.0f,0.0f);
gl.glUseProgram(shaderProgram);
gl.glPushMatrix();
gl.glBegin(GL.GL_QUADS);
	gl.glVertex3f(10.0f,10.0f,0.0f);
	gl.glVertex3f(-10.0f,10.0f,0.0f);
	gl.glVertex3f(-10.0f,-10.0f,0.0f);
	gl.glVertex3f(10.0f,-10.0f,0.0f);
gl.glEnd();
gl.glPopMatrix();

And finally my shader code which is in a text file called “fragShader.glsl”. I have not spent any time learning the actual glsl since I first have to figure out how to get a shader running in the first place. I took this code from the 3D lighthouse tutorial (it said it colors pixels a blue shade):

void main()
{
	gl_FragColor = vec4(0.4,0.4,0.8,1.0);
}

I don’t know if there should be more to this or not. Based on what I read, it seems to imply this these lines are all there is.

Perhaps someone can point out my error(s). Thanks

I wrote this overview a while back, although it covers LWJGL it might be of some help.

In particular you don’t seem to be validating your resulting program, and you should check the info log too and see if that spits out any helpful messages. At a guess you’re not loading the shader source correctly, but I don’t know the parameters jogl requires in this case so I can’t really guess anything further.

After the shader creation block of code I included these lines:

gl.glValidateProgram(shaderProgram);
			
IntBuffer log1 = IntBuffer.allocate(1);
gl.glGetShaderiv(fragShader,GL.GL_COMPILE_STATUS,log1);
System.out.println(log1.array()[0]);

IntBuffer log2 = IntBuffer.allocate(1);
gl.glGetProgramiv(shaderProgram,GL.GL_LINK_STATUS,log2);
System.out.println(log2.array()[0]);

IntBuffer log3 = IntBuffer.allocate(1);
gl.glGetProgramiv(shaderProgram,GL.GL_VALIDATE_STATUS,log3);
System.out.println(log3.array()[0]);

They each return the number 1 which is equivalent to GL.GL_TRUE

Is this what you meant? It seems to me that there isn’t any useful information in here or perhaps I just don’t know how to interpret it.

edit: After messing around with the code, I realized that the stuff in the init method is fine and I was doing something wrong with the ordering in the display method. Apparently I misunderstood how/when this fragment shader does what it does. Since there wasn’t much interest in this thread, I won’t bother posting the details. Thanks for the help you gave Orangy Tang.