2D lighting

Started by
13 comments, last by medevilenemy 11 years, 11 months ago
I think you're missing the fact that subtracting the alpha after its already been drawn will not reveal what was below that pixel. Once you have drawn to a pixel, whatever was there before hand is gone - a texture only stores 1 colour per pixel. To get more information per pixel you have to manually store it in other render targets.
Advertisement
That... is a really good point that didn't occur to me <smacks forhead>. So, I suppose now the question becomes: How do I do that?
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
I found an example which, with some tweaking (since i'm not using shaders and since I need to load up an appropropriate extension -- I suppose GL_ARB_framebuffer_object) should do the trick (render the opaque "blanket" to a texture, then the light template onto that -- assuming it would let me draw a texture onto the texture -- then draw the framebuffer texture over my scene). I am attempting to build with GLEW in order to make GL_ARB_framebuffer_object accessable, but unfortunately I get the following error when I try to test for the extension's availability:

undefined reference to `__GLEW_ARB_framebuffer_object'

The relevant code is:

GLenum err = glewInit();
if (GLEW_OK != err)
{
}
else // This is not permanent... just a way for me to test to see if glew is working.
{
if (GLEW_ARB_framebuffer_object)
{
}
}

I have added glew32.lib to the linker options for my project -- but I suppose it isn't playing nice with the linker. I am using the newest version of glew and building in Code::Blocks 10.05 with a mingw backend.
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
Purely on a hunch, I tried linking against glew32.dll rather than glew32.lib, and it seems to link now... and it seems the extension I want is available! (I already knew it was, but its nice to see that glew agrees).
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
I've made some progress... I can now render to a texture, which I can then draw to the screen... but I can't seem to get blending and/or depth (can't really tell which) to work within that texture. I'm basing my code on the bottom example in http://www.songho.ca...gl/gl_fbo.html. My setup code is pretty much exactly the same, with the drawing code replaced with the following (for testing purposes):


glPushMatrix();
// set rendering destination to FBO
glBindFramebuffer(GL_FRAMEBUFFER, 92);

// clear buffers
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glOrtho(-0.5 * width, 0.5*width, -1, 1, 1, 0);
glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // function for blending
glColor4d(0.0, 1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex3d(-1.0, 0.0, 0.01);
glVertex3d(0.1, 0.0, 0.01);
glVertex3d(0.1, -1.0, 0.01);
glVertex3d(-1.0, -1.0, 0.01);
glEnd();

glColor4d(1.0, 1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex3d(-0.9, 0.0, 0.0);
glVertex3d(0.0, 0.0, 0.0);
glVertex3d(0.0, -0.9, 0.0);
glVertex3d(-0.9, -0.9, 0.02);
glEnd();

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glPopMatrix();

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 90);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1,-0.1,0.01); // Bottom-Left Vertex
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.1,-0.1,0.01); // Bottom-Right Vertex
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.1,0.1,0.01); // Top-Right Vertex
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.1,0.1,0.01); // Top-Left Vertex
glEnd();
glDisable(GL_TEXTURE_2D);


In fact.. Nothing I do seems to make any difference (even making the first quad bigger and a different color than the first and playing with texcoords, it always just shows the second box.

Does anyone know what I might need to change in the setup or in the drawing code to get the depth/alpha blending working?
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.

This topic is closed to new replies.

Advertisement