Author Topic: How to implement anaglyph 3D object by jPCT?  (Read 2974 times)

Offline wruiwr

  • byte
  • *
  • Posts: 6
    • View Profile
How to implement anaglyph 3D object by jPCT?
« on: July 15, 2014, 12:08:23 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to implement anaglyph 3D object by jPCT?
« Reply #1 on: July 15, 2014, 08:43:23 am »
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.

Offline wruiwr

  • byte
  • *
  • Posts: 6
    • View Profile
Re: How to implement anaglyph 3D object by jPCT?
« Reply #2 on: July 15, 2014, 11:42:17 am »
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?
Code: [Select]
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)
    }


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to implement anaglyph 3D object by jPCT?
« Reply #3 on: July 15, 2014, 09:51:53 pm »
Can you post a screen shot or some video of that problem? I'm not sure if i understand what you mean by "blinking".

Offline wruiwr

  • byte
  • *
  • Posts: 6
    • View Profile
Re: How to implement anaglyph 3D object by jPCT?
« Reply #4 on: July 15, 2014, 11:59:07 pm »
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:
Code: [Select]
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]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to implement anaglyph 3D object by jPCT?
« Reply #5 on: July 16, 2014, 07:52:57 am »
Remove the first block of

Code: [Select]
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.

Offline wruiwr

  • byte
  • *
  • Posts: 6
    • View Profile
Re: How to implement anaglyph 3D object by jPCT?
« Reply #6 on: July 16, 2014, 09:55:36 am »
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]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to implement anaglyph 3D object by jPCT?
« Reply #7 on: July 17, 2014, 08:39:44 pm »
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.