You may want to start with something simpler at first. You can render to the frame buffer, and copy the rendering to a texture, without using pbuffers at all. Pbuffers pose some problems of their own that you may want to avoid till you've got texturing down.
The technique is to create a blank texture, do some drawing to the frame buffer, then call glCopyTexSubImage2D() to copy a portion (or all) of the framebuffer to a texture. Then clear the framebuffer and render your scene. You can use the copied texture as you would any other texture. I use this technique to save and restore frame images.
Some code I've used to do this:
/**
* Allocate a texture (glGenTextures) and return the handle to it.
*/
public static int allocateTexture()
{
IntBuffer textureHandle = allocInts(1);
GL11.glGenTextures(textureHandle);
return textureHandle.get(0);
}
/**
* Create a texture from the given pixels in RGBA format. Set the texture
* to repeat in both directions and use LINEAR for magnification.
* @return the texture handle
*/
public static int makeTexture(ByteBuffer pixels, int w, int h)
{
// get a new empty texture
int textureHandle = allocateTexture();
// 'select' the new texture by it's handle
GL11.glBindTexture(GL11.GL_TEXTURE_2D,textureHandle);
// set texture parameters
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); //GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); //GL11.GL_NEAREST);
// Create the texture from pixels
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w, h, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels);
return textureHandle;
}
/**
* Copy the frame buffer to a texture. Texture must be big enough to
* hold entire screen and dimensions must be powers of 2, ie 1024x1024.
*/
public void frameSave(int txtrHandle)
{
// turn off alpha and color tints
GL11.glColor4f(1,1,1,1);
GL11.glReadBuffer(GL11.GL_BACK);
GL11.glBindTexture(GL11.GL_TEXTURE_2D,txtrHandle);
// copy the full frame into the given texture
GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0,0, 0,0, DM.getWidth(),DM.getHeight());
}
/**
* Meant to be used in ORTHO mode (2D)
*/
public static void drawQuad(int textureHandle, int x, int y, float w, float h) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D,textureHandle);
// draw textured quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex3f( (float)x, (float)y, (float)0);
GL11.glTexCoord2f(1f, 0f);
GL11.glVertex3f( (float)x+w, (float)y, (float)0);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f( (float)x+w, (float)y+h, (float)0);
GL11.glTexCoord2f(0f, 1f);
GL11.glVertex3f( (float)x, (float)y+h, (float)0);
GL11.glEnd();
}
I use makeTexture() to create a blank texture (has to be square, and powers of two ie. 32x32 or 128x128 etc.), and call frameSave() to copy the whole screen (DM is the displayMode), but you could copy a portion as well. Then that texture can be passed to drawQuad() to draw it onto a rectangle on screen.