PDA

View Full Version : Spotlight Texturing



AndrewJJ
06-14-2002, 01:04 AM
Hi,
I need to simulate a projected spotlight beam on a floor plane ... I've got a texture tiled plane and I blend a spotlight texture on to it ... neither texture has an associated alpha channel but I found that the code snippet below worked fine ...

glNewList(fGenList, GL_COMPILE);
glColor3ub(80, 80, 80);

glBindTexture(GL_TEXTURE_2D, GLTextures[cSpotLight]);
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-100.0, -17.0, -100.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-100.0, -17.0, 100.0);
glTexCoord2f(1.0, 1.0); glVertex3f( 100.0, -17.0, 100.0);
glTexCoord2f(1.0, 0.0); glVertex3f( 100.0, -17.0, -100.0);
glEnd;

glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR);
glDepthFunc(GL_EQUAL);
glBindTexture(GL_TEXTURE_2D, GLTextures[cCarpet]);
glBegin(GL_QUADS);
glNormal3f( 0.0, 1.0, 0.0);
glTexCoord2f( 0.0, 0.0); glVertex3f(-100.0, -17.0, -100.0);
glTexCoord2f( 0.0, 20.0); glVertex3f(-100.0, -17.0, 100.0);
glTexCoord2f(20.0, 20.0); glVertex3f( 100.0, -17.0, 100.0);
glTexCoord2f(20.0, 0.0); glVertex3f( 100.0, -17.0, -100.0);
glEnd;
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
glEndList;

(Delphi - so please don't tell me that the closing bracket syntax is wrong !)

But ... here's a lesson to all ... The code only works on my GeForce2 ... other cards ... well, the 'blue screen' of death was all that happened ! Reason ... it seems to be caused by the glBlendFunc setting that uses GL_DST_COLOR ...

So how do I do this thing properly ? Is there an easy way of doing it without alpha or is there a way of emulating the needed alpha from the spotlight texture ? Or how do I do it using alpha ?

And ... my tip ... disable hardware acceleration from time to time to see how compatible your project is ... I found that I was also binding textures after a gLBegin ... my driver / card didn't object ... others did by crashing !!!

Many thanks

Andrew

06-16-2002, 06:01 AM
It seems like GL_ONE_MINUS_DST_COLOR is not allowed as the second argument to glBlendFunc. See the man page http://techpubs.sgi.com/library/tpl/cgi-...rch=glBlendFunc (http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/g_man/cat3/OpenGL/glblendfunc.z&srch=glBlendFunc)

NVidia has a presentation about projective textures for among other things spotlight effects with examples .

AndrewJJ
06-16-2002, 01:34 PM
Zico,

Many thanks ... just call me stupid ! I've always had problems glBlend and I usually resort to trial and error until it does what I want ... I forgot that src and dst do not have common parameter settings.

Andrew