Did anyone implemented anaglyph 3D by jPCT before so that the object can be seen by 3D glasses? I know opengl has glColorMask to do this, but I didn't find it in jPCT...if cannot use glColorMask, is it possible to use shaders? Any idea about this? So, how to implement anaglyph 3D by jPCT exactly?
If you want to, you can still use glColorMask(). Try something like set first camera, call glColorMask(). render scene, clear depth buffer, set second camera, call glColorMask again, render scene again. Either that way, or you can implement the IPaintListener interface and do the gl calls in that one. That might be the cleaner solution.
Thanks for your reply!!!
I tried the code below, and I can see red and cyan Cone now, but a problem is the red one is show on the left first and then cyan on the right, such as blinking. Is it because the camera setting problems or others?
while (!org.lwjgl.opengl.Display.isCloseRequested) {
buffer.clear()
cameraLeft = world.getCamera
cameraLeft.setPosition(0.2f, -0f, -10f)
//cameraLeft.lookAt(cone.getTranslation)
GL11.glColorMask(true,false,false,true)
world.renderScene(buffer)
world.draw(buffer)
buffer.update()
buffer.displayGLOnly()
Thread.sleep(10)
buffer.clearZBufferOnly()
cameraRight = world.getCamera
cameraRight.setPosition(-0.2f,-0f,-10f)
GL11.glColorMask(false,true,true,true)
world.renderScene(buffer)
world.draw(buffer)
buffer.update()
buffer.displayGLOnly()
Thread.sleep(10)
}
Can you post a screen shot or some video of that problem? I'm not sure if i understand what you mean by "blinking".
I set to sleep longer, so I can see, firstly, the red cone was shown up once on the left side and disappeared, then the cyan one was shown up on the right side once and disappeared, then red one again, so I can not get both red one and cyan one on the screen at the same time. Therefore, I attached two photos...
The tested code is simple as below:
import com.threed.jpct._
import org.lwjgl.opengl.GL11
class HelloWorld {
var world:World = null
var cameraLeft:Camera = null
var cameraRight:Camera = null
var cone:Object3D = null
def AnaglyphExample = {
world = new World
val tm: TextureManager = TextureManager.getInstance()
tm.addTexture("Cone", new Texture("textures/jplogo.jpg"))
cone = Primitives.getCone(32,1f)
cone.setTexture("Cone")
cone.setEnvmapped(Object3D.ENVMAP_ENABLED)
cone.build()
world.addObject(cone)
val buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL)
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE)
buffer.enableRenderer(IRenderer.RENDERER_OPENGL)
while (!org.lwjgl.opengl.Display.isCloseRequested) {
buffer.clear()
cameraLeft = world.getCamera
cameraLeft.setPosition(0.2f, -0f, -10f)
GL11.glColorMask(true,false,false,true)
world.renderScene(buffer)
world.draw(buffer)
buffer.update()
buffer.displayGLOnly()
Thread.sleep(1000)
buffer.clearZBufferOnly()
cameraRight = world.getCamera
cameraRight.setPosition(-0.2f,-0f,-10f)
GL11.glColorMask(false,true,true,true)
world.renderScene(buffer)
world.draw(buffer)
buffer.update()
buffer.displayGLOnly()
Thread.sleep(1000)
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL)
buffer.dispose()
System.exit(0)
}
}
object HelloWorld{
def main (args: Array[String]) {
val app = new HelloWorld
app.AnaglyphExample
}
}
[attachment deleted by admin]
Remove the first block of
buffer.update()
buffer.displayGLOnly()
You are rendering individual frames this way, which causes the blinking. Remove it make the code draw both images into the same frame.
Wow, right, I got it. Thank you! Now they are shown on the same screen ;D Another thing I was wondering now is to use applet and software rendering to implement Anaglyph 3d, any idea about how to do this? :)
[attachment deleted by admin]
For software rendering, you would have to render two seperate images, grab them both (via pixel data or via the associated image instance) and combine them somehow. The blit the resulting image into the framebuffer as the final image.