Render STRAIGHT to texture

Started by Java Cool Dude, March 22, 2004, 17:08:25

Previous topic - Next topic

Java Cool Dude

How is that accomplished?
I find glCopyTex... a bit slow for my taste, and reading Nvidia's papers, I found out that we can bypass that part and render straight to texture.
Question is, how is that accomplished in LWJGL?

spasi

There are two "fast" ways. With both you have to render sth on a pbuffer.

With the first, you have 2 contexts that share the same textures and display lists. So you just CopyTexSubImage from the pbuffer to a texture, then use that texture in your framebuffer rendering. It's fast enough for most uses. And the most supported way to do it. Pbuffers automatically share textures with the window context in LWJGL.

With the second, render-to-texture, you use the pbuffer memory as a texture. This saves you the copy. The catch is that it's win32 only. And render-to-depth-texture (for shadow mapping) is supported only by nvidia (check out the capabilities). To use it in LWJGL pass a RenderTexture object to the pbuffer constructor. It's quite easy, just check the parameters. Then, after rendering to the pbuffer, use pbuffer.bindTexImage(), with the right buffer target as a parameter. Don't forget to releaseTexImage before rendering again to the pbuffer.

Java Cool Dude

Well thanks, I wrote a routine that checks wheither we're using Windows or not, and switch to the correct rendering method accordingly


   pixelBuffer.makeCurrent();

    if(WIN_DETECTED)
      pixelBuffer.releaseTexImage(pixelBuffer.FRONT_LEFT_BUFFER);
 
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT |GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glPushMatrix();
    ....
    ....
    ....

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureMirrorID);

    if(WIN_DETECTED){
       pixelBuffer.bindTexImage(pixelBuffer.FRONT_LEFT_BUFFER);
    }
    else
      GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512,512);


   try{
      RenderTexture rt = new RenderTexture(true, false, false, false,
                                           RenderTexture.RENDER_TEXTURE_2D, 0);
      pixelBuffer  =  new Pbuffer(512, 512, 32, 0, 0, 0, 0, rt);
      pixelBuffer.makeCurrent();
      GL11.glClearColor(0,0,0,0);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      GL11.glShadeModel(GL11.GL_SMOOTH);
      GL11.glEnable(GL11.GL_CULL_FACE);
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      GL11.glViewport(0,0, 512, 512);
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GLU.gluPerspective(90.0f, 1, 0.001f, 1500.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
    }
    catch(Exception e){}

    WIN_DETECTED = System.getProperty("os.name").indexOf("Windows") != -1;


However, if I attempt to create a dynamic cube map, basically nothing gets rendered

here's the code
   try{
      RenderTexture rt = new RenderTexture(true, false, false, false,
                                           RenderTexture.RENDER_TEXTURE_CUBE_MAP, 0);
      pixelBuffer  =  new Pbuffer(512, 512, 32, 0, 0, 0, 0, rt);
      pixelBuffer.makeCurrent();
      GL11.glClearColor(1,0,0,0);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      GL11.glShadeModel(GL11.GL_SMOOTH);
      GL11.glEnable(GL11.GL_CULL_FACE);
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      GL11.glViewport(0,0, 512, 512);
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GLU.gluPerspective(90.0f, 1, 0.001f, 1500.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
    }
    catch(Exception e){}
  }


   pixelBuffer.makeCurrent();
    pixelBuffer.releaseTexImage(pixelBuffer.FRONT_LEFT_BUFFER);

    for(int i = 0, face = 0; i < 6; i++){
      switch(i){
        case 0: face = pixelBuffer.TEXTURE_CUBE_MAP_POSITIVE_X; break;
        case 1: face = pixelBuffer.TEXTURE_CUBE_MAP_NEGATIVE_X; break;
        case 2: face = pixelBuffer.TEXTURE_CUBE_MAP_POSITIVE_Y; break;
        case 3: face = pixelBuffer.TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
        case 4: face = pixelBuffer.TEXTURE_CUBE_MAP_POSITIVE_Z; break;
        case 5: face = pixelBuffer.TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
      }
      pixelBuffer.setAttrib(pixelBuffer.CUBE_MAP_FACE, face);
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT |GL11.GL_DEPTH_BUFFER_BIT);
      GL11.glLoadIdentity();
      GLU.gluLookAt(position.x     , position.y     , position.z     ,
                    directions[0].x, directions[0].y, directions[0].z,
                                 0f,              1f,              0f);
      GLParticles.drawParticles();
    }
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, cubemapID);
    pixelBuffer.bindTexImage(pixelBuffer.FRONT_LEFT_BUFFER);



Any idea on what I'm doing wrong?

Java Cool Dude

Never mind me, I'm an idiot  :roll:
cough ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB

Java Cool Dude

That statement above excludes the case where I wanna use a pBuffer to accomplish the said effect.
I had success in using the regular glCopyTexSubImage