unpack pixel_buffer_object must be bound to call this method
Posted by nyholku on Nov 26, 2017; 6:11pm
URL: https://forum.jogamp.org/unpack-pixel-buffer-object-must-be-bound-to-call-this-method-tp4038328.html
I get this error:
<code><pre>
javax.media.opengl.GLException: unpack pixel_buffer_object must be bound to call this method
at jogamp.opengl.gl4.GL4bcImpl.checkBufferObject(GL4bcImpl.java:37213)
at jogamp.opengl.gl4.GL4bcImpl.checkUnpackPBOBound(GL4bcImpl.java:37299)
at jogamp.opengl.gl4.GL4bcImpl.glTexImage2D(GL4bcImpl.java:27291)
</pre></code>
from code below. Actually the title of this post is misleading, what I'm looking for<br>
is instructions or better yet a working example how to render a BufferedImage<br>
using OpenGL 2 ES. My ultimate goal is to render some 2D text which I plan to<br>
do by rendering it first to a BI and then rendering a rectangle with the texture<br>
mapping.<br>
<p>
I've been up and down the information highway and have not seen an example<br>
that would allow me to us a BI as texture. Lots of info here and there but I<br>
can't make it work. The code below is just one attempt out of dozens I've tried.<br>
wbr Kusti
<p>
<code><pre>
BufferedImage img = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) img.getGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 128, 128);
g.setColor(Color.green);
g.fillOval(0, 0, 128, 128);
Texture tex = AWTTextureIO.newTexture(GLProfile.getDefault(), img, true);
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 3 * Float.BYTES);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer m_VertexBuffer = vbb.asFloatBuffer();
m_VertexBuffer.position(0);
m_VertexBuffer.put(new float[] { -1, -1, 0 });
m_VertexBuffer.put(new float[] { +1, -1, 0 });
m_VertexBuffer.put(new float[] { +1, +1, 0 });
m_VertexBuffer.put(new float[] { -1, +1, 0 });
ByteBuffer tbb = ByteBuffer.allocateDirect(4 * 2 * Float.BYTES);
tbb.order(ByteOrder.nativeOrder());
FloatBuffer m_TextureCoordBuffer = tbb.asFloatBuffer();
m_TextureCoordBuffer.position(0);
m_TextureCoordBuffer.put(new float[] { 0, 0 });
m_TextureCoordBuffer.put(new float[] { 1, 0 });
m_TextureCoordBuffer.put(new float[] { 1, 1 });
m_TextureCoordBuffer.put(new float[] { 0, 1 });
m_VertexBuffer.position(0);
m_TextureCoordBuffer.position(0);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, 128, 128, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, tex.getTextureObject());
gl.glColor3f(1.0f, 0, 0);
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL2.GL_FLOAT, 0, m_VertexBuffer);
gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, m_TextureCoordBuffer);
gl.glDrawArrays(GL2.GL_TRIANGLE_FAN, 0, m_VertexBuffer.limit() / 3);
gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
</pre></code>
PS what is the proper way to include code samples in this forum?