# Trying to implement forward rendering in OpenGL

I'm working on implementing forward rendering in my 2D engine, as far as I'm aware everything should be set up correctly, I've ran into some issues earlier but I'm sure I've fixed those at this point.

So what I'm doing to achieve this (May or may not be the correct way of going about this) is that I'm rendering the object first with ambient light (Which works), and then for each light affecting the object, I render it once again using a different shader for point lights. I've set that shader to only output the color red atm, but nothing shows up apart from the first render of the object (The one with the ambient light).

Here are some pieces of my code.

Rendering of the object

        shader.Use();

VertexAttributePointer.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 5, (System.IntPtr)0);
VertexAttributePointer.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 5, (System.IntPtr)(3 * sizeof(float)));

//Render sprite

GL.Enable(EnableCap.Blend);

//Transparency
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);

//Draw object

//Forward rendering
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);

GL.DepthFunc(DepthFunction.Equal);

{

foreach (Light l in Light.lights)
{

}
}

GL.DepthFunc(DepthFunction.Lequal);
GL.Disable(EnableCap.Blend);

texture.Unbind();


Note that it is temporarily set to only output red, which should globally tint all objects if it works.

#version 330 core

struct Light {
vec3 position;
vec3 color;
};

uniform vec3 _CameraPos;
uniform vec3 _Color;
uniform sampler2D _Diffuse;
uniform Light _PointLight;

out vec4 color;
in vec2 TexCoords;
in vec3 FragPos;

void main()
{
vec4 diffuse = texture(_Diffuse, TexCoords);

float distance = length(_PointLight.position - FragPos);
float attenuation = 1.0;

vec3 finalLight = _PointLight.color * attenuation;

color = vec4(1.0, 0.0, 0.0, 1.0);
}

• What happen if you change glDepthFunc to always passes? – Greffin28 Jun 20 '16 at 2:09
• Tried that earlier, same result. It doesn't seem to be a depth issue. I even tried not drawing to the depth buffer at all so it shouldn't be that. @Greffin28 – Lym Jun 20 '16 at 2:10
• If i were you, i would leave glDepthFunc to always passes and then do debugging, such as trying to render just 1 light. Or test it to render not from the light variables (Input the variables manually). If that renders, then bit by bit try to reconstruct the code. – Greffin28 Jun 20 '16 at 8:05
• That's what I've been doing, I just changed it to Equal before I posted this since it technically is my actual value for it. I've tried changing around a lot of values while having it set to always pass with no luck, so I'm thinking it might be another issue. – Lym Jun 20 '16 at 14:54
• Silly me, I forgot to mention you in my comment. @Greffin28 Is there anything else you can think of that might be causing the problem? – Lym Jun 21 '16 at 0:46

Here is a short list of things to check:

• Does Forward-Point shader compiles successfully?
• Do you call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) before rendering?
• Have you enabled depth test (glEnable(GL_DEPTH_TEST))?