No shadows in OpenGL?
No shadows in OpenGL?
I looked at the demo of the Irrlicht engine and saw that in the OpenGL renderer there are no realtime shadows. Why is that? And when will it become fixed? I would be very thankful for the answer, because I plan to use Irrlicht (with Dev-C++ where it is complicated to use DirectX) in a private project, but do like the realtime shadows of the demo.
-
- Posts: 61
- Joined: Mon Oct 25, 2004 12:11 am
Code: Select all
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CVideoOpenGL::drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail)
{
if (!StencilBuffer || !count)
return;
// unset last 3d material
if (CurrentRenderMode == ERM_3D &&
Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
MaterialRenderers[Material.MaterialType]->OnUnsetMaterial();
ResetRenderStates = true;
}
// store current OpenGL state
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT |
GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT );
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDepthMask(GL_FALSE);
glDepthFunc(GL_LEQUAL);
glEnable(GL_STENCIL_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); // no color buffer drawing
glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFFL );
glColorMask(0, 0, 0, 0);
glEnable(GL_CULL_FACE);
if (!zfail)
{
// ZPASS Method
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glCullFace(GL_BACK);
glBegin(GL_TRIANGLES);
s32 i;
for(i = 0; i < count; ++i)
glVertex3f(triangles[i].X, triangles[i].Y, triangles[i].Z);
glEnd();
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glCullFace(GL_FRONT);
glBegin(GL_TRIANGLES);
for(i = 0; i < count; ++i)
glVertex3f(triangles[i].X, triangles[i].Y, triangles[i].Z);
glEnd();
}
else
{
// ZFAIL Method
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
glCullFace(GL_FRONT);
glBegin(GL_TRIANGLES);
s32 i;
for(i = 0; i < count; i++)
glVertex3f(triangles[i].X, triangles[i].Y, triangles[i].Z);
glEnd();
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
glCullFace(GL_BACK);
glBegin(GL_TRIANGLES);
for(i = 0; i < count; i++)
glVertex3f(triangles[i].X, triangles[i].Y, triangles[i].Z);
glEnd();
}
glPopAttrib();
}
void CVideoOpenGL::drawStencilShadow(bool clearStencilBuffer, video::SColor leftUpEdge,
video::SColor rightUpEdge, video::SColor leftDownEdge, video::SColor rightDownEdge)
{
if (!StencilBuffer)
return;
setTexture(0,0);
setTexture(1,0);
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT );
glDisable( GL_LIGHTING );
glDepthMask(GL_FALSE);
glDepthFunc( GL_LEQUAL );
glEnable( GL_STENCIL_TEST );
glFrontFace( GL_CCW );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFFL);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glDisable(GL_FOG);
glPushMatrix();
glLoadIdentity();
glBegin(GL_TRIANGLE_STRIP);
glColor4ub (leftUpEdge.getRed(), leftUpEdge.getGreen(), leftUpEdge.getBlue(), leftUpEdge.getAlpha() );
glVertex3f(-10.1f, 10.1f,0.90f);
glColor4ub (leftDownEdge.getRed(), leftDownEdge.getGreen(), leftDownEdge.getBlue(), leftDownEdge.getAlpha() );
glVertex3f(-10.1f,-10.1f,0.90f);
glColor4ub (rightUpEdge.getRed(), rightUpEdge.getGreen(), rightUpEdge.getBlue(), rightUpEdge.getAlpha() );
glVertex3f( 10.1f, 10.1f,0.90f);
glColor4ub (rightDownEdge.getRed(), rightDownEdge.getGreen(), rightDownEdge.getBlue(), rightDownEdge.getAlpha() );
glVertex3f( 10.1f,-10.1f,0.90f);
glEnd();
glPopMatrix();
glPopAttrib();
if (clearStencilBuffer)
glClear(GL_STENCIL_BUFFER_BIT);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
}
Sorry about posting the whole functions, but I couldn't remember what was changed.
-
- Posts: 61
- Joined: Mon Oct 25, 2004 12:11 am
np
You may also find problems with some of the materials in OpenGL. Take a look at the SpecialFX demo, and see if it matches the screenshots. If it isn't working right, I have a fix for that as well, modified from nx++. OpenGL can work just as well as DX in Irrlicht, it just needs a little prod here and there
You may also find problems with some of the materials in OpenGL. Take a look at the SpecialFX demo, and see if it matches the screenshots. If it isn't working right, I have a fix for that as well, modified from nx++. OpenGL can work just as well as DX in Irrlicht, it just needs a little prod here and there
-
- Posts: 38
- Joined: Mon May 31, 2004 7:55 am
- Contact:
It's not a matter of them being enabled, it's a matter of Irrlicht's OpenGL code not being as tuned as its DirectX code -- I think Niko mostly uses DirectX. So it works on some systems, but not on others. Shadows worked fine in OpenGL on my old GeForce, but on my new Radeon, they don't.firefly2442 wrote:Is this changed in irrlicht 0.8? It seems strange to me that shadows are enabled by default in DirectX and not OpenGL.