- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT);
- glLoadIdentity();
- camera.Render; //set the camera position
- //set light position
- glLightfv(GL_LIGHT0, GL_POSITION, @lp); //position light
- //get the light position
- objlightpos2.x:=lp[0];
- objlightpos2.y:=lp[1];
- objlightpos2.z:=lp[2];
- objlightpos2.w:=lp[3];
- // Get the inverse model matrix
- glPushMatrix;
- glLoadIdentity;
- glGetFloatv(GL_MODELVIEW_MATRIX, @InvMatrix);
- glPopMatrix;
- //Get the object space light vector
- ObjLightPos2 := vectortransform4f(objlightpos2,InvMatrix);
- // Draw the light
- glDisable(GL_LIGHTING);
- glPushMatrix();
- glTranslatef(LP[0], LP[1], LP[2]);
- glColor3f(1, 1, 0);
- gluSphere(LightObj, 0.2, 8, 8);
- glPopMatrix();
- glEnable(GL_LIGHTING);
- //now on to rendering...
- glrotatef(270,1,0,0); //rotate the scene...
- //fill the depth buffer (ambient pass)
- glenable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- //ambientmode:=true;
- drawscene;
- //prepare for shadows
- glDepthMask(FALSE);
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE,GL_ONE);
- //for each light
- glDisable(GL_LIGHT0);
- glClear(GL_STENCIL_BUFFER_BIT);
- glColorMask(FALSE,FALSE,FALSE,FALSE);
- glEnable(GL_STENCIL_TEST);
- glStencilFunc(GL_ALWAYS, 0, byte(not 0));
- glStencilMask(byte(not 0));
- makeshadows; //determine face visibility...
- //zfail
- glEnable(GL_CULL_FACE);
- glCullFace(GL_FRONT);
- glStencilOp(GL_KEEP, GL_INCR_WRAP, GL_KEEP);
- drawshadows;
- glCullFace(GL_BACK);
- glStencilOp(GL_KEEP, GL_DECR_WRAP, GL_KEEP);
- drawshadows;
- glEnable(GL_LIGHT0);
- //end for each light
- glCullFace(GL_BACK);
- //draw diffuse part
- glStencilFunc(GL_EQUAL, 0, byte(not 0));
- glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
- gldepthfunc(GL_EQUAL);
- glColorMask(TRUE,TRUE,TRUE,TRUE);
- //ambientmode:=false;
- drawscene;
- //restore render settings
- glDepthFunc(GL_LESS);
- glDisable(GL_BLEND);
- glDisable(GL_STENCIL_TEST);
- glDepthMask(TRUE);
- //render the gui
- gldisable(GL_TEXTURE_2D);
- glActiveTexture(GL_TEXTURE0); //go back to texture0 (just to be save)
- rendergui;
- //Flush the OpenGL Buffer
- glFlush(); //is it needed?