How to use pBuffer for Cube Mapping ?

Started by Vifani83, November 04, 2004, 18:23:12

Previous topic - Next topic

Vifani83

Hi guys,

I want to realize a Dynamic Environmental Cube Map material with a render to texture using pBuffer. I have used the PbufferTest demos as example and I have realize a render to a GL_TEXTURE_2D, but how can I use a GL_TEXTURE_CUBE_MAP with pBuffer?

I have bind the pBuffer to a GL_TEXTURE_CUBE_MAP and after I have render to the pBuffer I have realized a copy from the current pBuffer to the current cube map axis:

GL11.glCopyTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X+axis, 0, GL11.GL_RGB, 0, 0, width, height, 0);


And so on for all others axis, but I have no success :(

Can anyone help me ?

spasi

Why copy when you're rendering-to-texture? :)

Take a look at the Pbuffer.setAttrib() comments. Use Pbuffer.CUBE_MAP_FACE as the first argument, choose a face and render accordingly (repeat for each face). It's straightforward after that.

Vifani83

Quote from: "spasi"Why copy when you're rendering-to-texture? :)

Take a look at the Pbuffer.setAttrib() comments. Use Pbuffer.CUBE_MAP_FACE as the first argument, choose a face and render accordingly (repeat for each face). It's straightforward after that.

The demo render to texture using glCopyTexImage2D :(

FOR TEXTURE 2D
So, I must declare the pBuffer in the following mode to render to a texture 2D:

PBuffer pbuffer=new Pbuffer(512,512,new PixelFormat(),new RenderTexture(true,false,false,false,RenderTexture.RENDER_TEXTURE_2D)


And now? How can I proceed ?


FOR TEXTURE CM
I must declare the pBuffer in the following mode to render to a texture CM:
PBuffer pbuffer=new Pbuffer(512,512,new PixelFormat(),new RenderTexture(true,false,false,false,RenderTexture.RENDER_TEXTURE_CM));
pbuffer.makecurrent();
glBindTexture(GL_TEXTURE_CUBE_MAP,id);
for (int i=0;i<6;i++)
{
pbuffer.setAttrib(Pbuffer.CUBE_MAP_FACE,
TEXTURE_CUBE_MAP_POSITIVE_X+i);

// rendering the face
}
Display.makecurrent();

//Now can I use the cube map generated


Is it correct ?

spasi

Ah, that's because the PbufferTest demo does not use render-to-texture. Have you tried org.lwjgl.test.opengl.pbuffers.UniqueRendererRTT?

Your code is correct, except for not using bindTexImage & releaseTexImage. These two are necessary for using rtt. The first binds the current texture to the pbuffer contents and then you can use the texture as usual. The second releases the texture binding so that you can render again to the pbuffer. You CAN'T update the pbuffer unless releasing first.

PS: If you think OpenGL's render-to-texture approach sucks...well yeah, it does. But this is going to change (hopefully soon :evil:). When the new extensions are out, you can expect a quick LWJGL update...

elias

Quote from: "spasi"

PS: If you think OpenGL's render-to-texture approach sucks...well yeah, it does. But this is going to change (hopefully soon :evil:). When the new extensions are out, you can expect a quick LWJGL update...

Amen to that! In Tribal Trouble we generate islands on-the-fly and use OpenGL as a fast image composition engine. Except there's all sorts of driver f*ckup with Pbuffers, and in the worst case we have to use the back buffer and risk back buffer corruption (not detectable).

- elias

spasi

Brrrrrr...:shock:

In Marathon, we're pretty satisfied with shadow map quality (using trapezoidal shadow maps), but it still fails in some extreme cases. I want to build some kind of scheme with multiple shadow maps, but I won't even try it with pbuffers!

Vifani: Tell us when you make it work, because I don't think anyone has tested cube-map render-to-texture with LWJGL before...:wink:

Vifani83

Quote from: "spasi"Brrrrrr...:shock:
Vifani: Tell us when you make it work, because I don't think anyone has tested cube-map render-to-texture with LWJGL before...:wink:

I work to Iupiter an opensource project. Basically is a 3D engine Java + OpenGL using LWJGL so I am implementing the Render To Texture.

https://sourceforge.net/projects/iupiter

When it will work I report ;)

Vifani83

This is my active render to texture function:

   public void ActiveRenderTotexture(int face)
    {
    	if (pbuffer.isBufferLost()) {
            System.out.println("Buffer contents lost - will recreate the buffer");
            pbuffer.destroy();
    	try {
    		pbuffer=new Pbuffer(width, height, new PixelFormat(), new RenderTexture(true,false,false,false,RenderTexture.RENDER_TEXTURE_CUBE_MAP,0));
            	init();
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
        }
    	try {
	    	pbuffer.makeCurrent();
		} catch (Exception e) {
			e.printStackTrace();
		}
		GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
		pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);
    	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    	pbuffer.setAttrib(Pbuffer.CUBE_MAP_FACE, Pbuffer.TEXTURE_CUBE_MAP_POSITIVE_X+face);
    }


Now I render and call the deactivate function:

   public void DeactiveRenderTotexture(int axis)
    {
    	GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
    	//GL11.glCopyTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL11.GL_RGB, 0, 0, width, height, 0);
    	pbuffer.bindTexImage(Pbuffer.FRONT_LEFT_BUFFER);
    		try {
		Display.makeCurrent();
		} catch (Exception e) {
		e.printStackTrace();
		}
    }


What's wrong ?

Vifani83

It's all ok.

You can see the Cube Environmental Mapping with pbuffer and render to texture in Iupiter 0.2.

https://sourceforge.net/projects/iupiter/

Chman

Very nice !
I'm gonna take a closer look to the source...

Chman