Thanks for the replies! Although I am going to use the old opengl(probably 2.1) I dont want to use the fixed-function functionality, and I have sucessfully implemented lighting by shaders. The thing is that I want to do per fragment lighting, wich I found to be slow when using multiple lights.
I've done some research about deferred rendering and it seams to be my best option. I've sucessfuly made the G-Buffer but i'm having trouble doing the light pass. I'm not sure if I should create another topic about that or not, but i will post part of my code and stuff.
normals
position
diffuse
I think those are okay. Here is my shader that generates those:
varying vec4 color;
varying vec2 texCoords;
varying vec3 N;
varying vec3 pos;
void main() {
color = gl_Color.rgba;
gl_Position = ftransform();
texCoords = gl_MultiTexCoord0.xy;
N = normalize(gl_NormalMatrix * gl_Normal);
pos = vec4(ftransform()).xyz;
}
varying vec4 color;
varying vec2 texCoords;
uniform sampler2D textureSampler;
varying vec3 N;
varying vec3 v;
varying vec3 pos;
void main()
{
gl_FragData[0] = color * texture2D(textureSampler, texCoords);
gl_FragData[1] = vec4(N, 1.0);
gl_FragData[2] = vec4(pos, 1.0);
gl_FragData[3] = vec4(texCoords, 0.0, 1.0);
}
and here is my lighting shader
varying vec2 texCoords;
void main() {
gl_Position = ftransform();
texCoords = gl_MultiTexCoord0.xy;
}
varying vec2 texCoords;
uniform sampler2D DSampler;//Diffuse
uniform sampler2D NSampler;//Normals
uniform sampler2D PSampler;//Positions
void main(){
vec3 lpos = vec3(0, 0, 52);
vec3 v = texture2D(PSampler, texCoords).rgb;
vec3 N = texture2D(NSampler, texCoords).rgb;
vec3 L = normalize(lpos - v);
vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
Idiff = clamp(Idiff, 0.0, 1.0);
gl_FragColor = Idiff * texture2D(DSampler, texCoords);
}
What is wrong with those. Everything is black.
Thanks.