Opengl simple blending problem

Stuck on things I shouldn't be stuck on as always :D.

I have been messing around with glBlendFunc to create a flashlight/spotlight effect on a tilemap, everything works exactly how I would expect apart from it always creates a white background color where no tiles exist (regardless of my glClearColor which is what I would expect it to show?).

Here is a picture to show what I mean http://puu.sh/2SS1C.png
(see the background above the trees is white whatever I seem to do, I am guessing my first blending call is wrong). I would like it to be black to match the texture without actually having to put tiles there.

http://puu.sh/2SSsN.png Texture to make everything darker
http://puu.sh/2SSu9.png "Light" texture (white square)

1
2
3
4
5
6
7
8
9
10
11
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);

glBlendFunc(GL_ONE, GL_ZERO);  // Might be the problem but not sure what else to set it as 

ApplySurface(0,0,Dark); 
ApplySurface(320,380,Light);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
map.Show();

SDL_GL_SwapBuffers();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//map.Show Function
for(int j = (PlayerCamera.x) / 32; j < (PlayerCamera.x + PlayerCamera.w + 32) / 32; j++)
{
	for(int i = (PlayerCamera.y) / 32; i < (PlayerCamera.y + PlayerCamera.h + 32) / 32; i++)
	{
		if(i < Layers[a].size())
		{
			if(j < Layers[a][i].size())
			{
				if(Layers[a][i][j]->ID != -1)  // Tiles not shown
				{
					ApplySurface(Layers[a][i][j]->x -(PlayerCamera.x), Layers[a][i][j]->y - PlayerCamera.y, Layers[a][i][j]->image, &Layers[a][i][j]->B);
				}
			}

		}
	}
}


Of course I left a lot of other code out but none of it should influence that (let me know if you need to see anything else).
Last edited on
Might not do anything for you, but try doing something like this :

1
2
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER, 0.2f);
Last edited on
Tried replacing my first blend function with that, didn't seem to change anything. Will try experimenting more with the AlphaFunc but I think it's a result of my dark texture reacting with the background...but not 100%.

Let me know if anyone has any more ideas as well, thanks.
Last edited on
Seems to work fairly well basing everything off of alpha values instead of colors (so the background wont get involved). Thanks for the advice as well.
Last edited on
You're very welcome, glad it's working!
Topic archived. No new replies allowed.