Hello,
I have been playing with pbuffers a little, and I have a few surprises.
I am using pbuffers to draw a texture and then paint it over a square. In the display() method of the gleventlistener added to the pbuffer, I want to write some text, using glutBitmapString. On one pc (p4, radeon r9800), the text is flipped horizontally ( like a mirror). On the other computer (P4, GeForce 440Go) everything is fine.
Another thing. When using the pbuffer as a texture, on the radeon if I do not use pbuffer.releaseTexture(), no problem, on the nvidia, forgetting this causes the jvm to crash.
I am posting here the interesting portions of code, I must be missing something as I a am new to jogl
Pbuffer creation :
if (gl.isExtensionAvailable("WGL_ARB_pbuffer"))
System.out.println("pbuffer SUPPORTED");
else
return;
GLCapabilities caps = new GLCapabilities();
caps.setOffscreenRenderToTexture(true);
caps.setDoubleBuffered(false);
if (!gLDrawable.canCreateOffscreenDrawable())
{
return;
}
pbuffer = gLDrawable.createOffscreenDrawable(caps, 512, 512);
pbuffer.addGLEventListener(new PbufferEventListener());
in the PbufferEventListener display method :
public void display(GLDrawable drawable)
{
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, size.x, 0.0, size.y);
//gl.glDisable(GL.GL_TEXTURE_2D);
//gl.glDisable(GL.GL_LIGHTING);
gl.glColor3f( 0.3f, 0.3f, 0.7f );
gl.glLineWidth(5.0f);
gl.glBegin (GL.GL_LINE_LOOP);
gl.glVertex2i (rpos.x+ret,rpos.y+ret);
gl.glVertex2i (rpos.x+size.x-ret,rpos.y+ret);
gl.glVertex2i (rpos.x+size.x-ret,rpos.y+size.y-ret);
gl.glVertex2i (rpos.x+ret,rpos.y+size.y-ret);
gl.glEnd();
gl.glRasterPos2i(100,100);
glut.glutBitmapString(gl, GLUT.BITMAP_HELVETICA_18, "Some text to test !");
//gl.glEnable(GL.GL_TEXTURE_2D);
//gl.glEnable(GL.GL_LIGHTING);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glEnable(GL.GL_DEPTH_TEST);
}
To use the buffer elsewhere :
pbuffer.bindTexture();
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(10f,10f,10f);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex2f(0f,0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex2f( size.x,0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex2f( size.x, size.y);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex2f(0.0f, size.y);
gl.glEnd();
pbuffer.releaseTexture();