glColorMask / STENCIL problem in LWJGL

Started by chibitotoro, January 30, 2009, 08:48:58

Previous topic - Next topic

chibitotoro

Original Link: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=27

QUESTION: How to get Shadows working in LWJGL using Nehe Lesson 27 Example?

DESCRIPTION:
I've been trying to work with shadows and I found many methods. I tried using the original C++ code from the Nehe tutorials and C code works fine. So I tried to take the code as is and ported it to my own LWJGL project.

Apparently something goes wrong when using glColorMask(false,false,false,false); as no shadows become rendered.

I tried changing Display.create() to Display.create(new PixelFormat(0,24,8)) and Display.create(new PixelFormat(0,16,1)) both of which do not work.

If I comment out that line, the shadow volume is rendered (thus nothing really wrong with the calculations). I'm speculating that something has not been enabled in my project so I tried using the LWJGL port provided by Nehe at the bottom of their lesson 27 page and same thing, no shadows. What's worse is the port to LWJGL no longer draws the light in the proper location (maybe thats why theres no shadow).

I was wondering if anyone can point me in the direction as to how to fix the provided source code so I can take it apart to learn how to do it properly.

NOTE: I tried porting the provided C code to my old projects and at first it did the same thing as LWJGL where no shadows are drawn but the shadow volume shows if I comment out glColorMask(0,0,0,0); However, in my init code, if I add GLUT_STENCIL to glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);, the shadow renders perfectly.

This is why I speculate that it's a GL thing that hasn't been set in LWJGL.

Source Code Link (Slightly modified for LWJGL2.0's GLU): http://clix.dynalias.net/public/Lesson27.java

Data Link (provided by Nehe Tutorials):  http://clix.dynalias.net/public/Data

Make sure to put these in a folder called "Data" (without quotes) when compiling.

LWJGL Page: http://www.lwjgl.org

broumbroum

I can tell you the NeHe Tutorials are, part of them, VERY HARD to impl. if you ain't no Nvidia or ATI developer, let's be launghing... Hence I looked around and found a book on openGL that helped me very much. Indeed a small tutorial about shadow mapping/proj. is inside.
Quote from: chibitotoro on January 30, 2009, 08:48:58
Original Link: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=27
(...)
Apparently something goes wrong when using glColorMask(false,false,false,false); as no shadows become rendered.

I tried changing Display.create() to Display.create(new PixelFormat(0,24,8)) and Display.create(new PixelFormat(0,16,1)) both of which do not work.
(,,,)
Anyway, I should provide you this trick : set PixelFormat :
new PixelFormat(8, 8, 8);

If you understanf a bit of French,  I recently wrote a small, but complete, doc about shadow projections (quite the same as NeHE tuto but without the init var's commonly used in C code). Here it is : http://membres.lycos.fr/b23prodtm/mambo/index.php?option=com_remository&Itemid=13&func=startdown&id=52
NOTICE : It turns out to be a poor service there at Multimania.lycos.tripod.... they claimed to close all their services. The link may be found later at www.b23prodtm.com.

chibitotoro

Thanks for the reply!

Did u try PixelFormat(8,8,8) with the Lesson27.java I provided above? I tried it and there's no difference.

Likewise I tried it in my other project that I tried to port my self and it didn't work either.

I'll take a look at your code as I know there are many ways to do shadows. I also found another C glut example that I'm trying to port to LWJGL to see if it works. Although this one uses a different algorithm. I'll keep looking into it. I want to use LWJGL because for some reason my OBJ/ColladaParser works ALOT faster in java than C. I always though C file IO was faster but I guess I was wrong in some sense.

broumbroum

Quote from: chibitotoro on January 30, 2009, 08:48:58
Original Link: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=27
(...)
NOTE: I tried porting the provided C code to my old projects and at first it did the same thing as LWJGL where no shadows are drawn but the shadow volume shows if I comment out glColorMask(0,0,0,0); However, in my init code, if I add GLUT_STENCIL to glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);, the shadow renders perfectly.

This is why I speculate that it's a GL thing that hasn't been set in LWJGL.
(...)
Yes, LWJGL is good, but the team isn't suppposed to impl de GLUT stuff. No, I'm not talking about testing the 27 lesson. However, GLUT are utilities that can be substituted with a gl display list or some GL coding. Instead of the glutInitDisplayMode, you can use
glEnable(GL_STENCIL), glClear(GL_COLOR..., GL_STENCIL..., GL_DEPTH_BUFFER_BIT) and on...
I can't be very accurate, because it's a bit more coding to impl shadowing in Java. You noticed there are different ways, and you have to choose a way that fits your interests. I think NeHe gives part of the solution but since C is older than Java, there are ways to void long coding.
As of NeHE 27, some of the features I'd retain are the following :
- drawObject()
// Draw An Object - Simply Draw Each Triangular Face.
void drawObject( const ShadowedObject& object )
{//(...)
}

and
- calculatePlane
void calculatePlane( const ShadowedObject& object, Face& face )
{//(...)
}

- at last,
void doShadowPass( ShadowedObject& object, GLfloat *lightPosition ){//(...)}

I think it is worth to simplify the lighting effects as well as shadow casting... Think I'm not perfect english-reader and these concepts may be unaccurate in my mind !

broumbroum

I omitted to tell you you can try the sf3jswing.sf.net/JIGAXtended.jnlp demo and if it runs ok, tell me about it ! (actually should only run on Linux yet, but in a few days I'll build the Windows rel.)
For example, the shadow mapping I make is solely intended for 2 dim. Sprites, but has 3D features like the eq. plane.