unpack pixel_buffer_object must be bound to call this method

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

unpack pixel_buffer_object must be bound to call this method

nyholku
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?
Reply | Threaded
Open this post in threaded view
|

Re: unpack pixel_buffer_object must be bound to call this method

gouessej
Administrator
Where do you call Texture.bind() or glBindTexture()?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: unpack pixel_buffer_object must be bound to call this method

nyholku
Hi,

thanks for replying.

In the code version I showed I call it nowhere, but I've tried various ways of doing this like:

Like below, neither one of the commented out bind attempts makes no difference:

gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
//tex.bind(gl);
//gl.glBindTexture(GL2.GL_TEXTURE_2D, tex.getTextureObject());
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, 128, 128, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, tex.getTextureObject());
Reply | Threaded
Open this post in threaded view
|

Re: unpack pixel_buffer_object must be bound to call this method

gouessej
Administrator
Don't mix the low level OpenGL API calls with the high level API calls. I still see neither tex.enable() nor gl.glEnable(GL.GL_TEXTURE_2D), either of them must be called before binding. Please look at our numerous JOGL examples, those of the Red Book, our unit tests and our demos in our Github repositories.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: unpack pixel_buffer_object must be bound to call this method

nyholku
Hi,
ok, thanks I will experiment with that (tex.enable()) 

A direct pointer to something that would clarify the low level high level API stuff would be appreciated.

I've read through quite a number of tutorials but I've not really found one where BufferedImage to texture would
be covered. 

wbr Kusti


From: "gouessej [via jogamp]" <[hidden email]>
Date: Monday, 27 November 2017 16:42
To: nyholku <[hidden email]>
Subject: Re: unpack pixel_buffer_object must be bound to call this method

Don't mix the low level OpenGL API calls with the high level API calls. I still see neither tex.enable() nor gl.glEnable(GL.GL_TEXTURE_2D), either of them must be called before binding. Please look at our numerous JOGL examples, those of the Red Book, our unit tests and our demos in our Github repositories.
Julien Gouesse | Personal blog | Website



If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/unpack-pixel-buffer-object-must-be-bound-to-call-this-method-tp4038328p4038334.html
To unsubscribe from unpack pixel_buffer_object must be bound to call this method, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: unpack pixel_buffer_object must be bound to call this method

gouessej
Administrator
You're welcome. Keep in mind that we can't provide demos covering all possible combinations of methods but those examples may help:
https://github.com/gouessej/jogl/blob/master/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java
https://github.com/gouessej/jogl/blob/master/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGTextureFromFileAWT.java
https://github.com/gouessej/jogl-demos/blob/master/src/redbook/src/glredbook11/texbind.java

Warning: Some code above needs an update as it uses obsolete package names and call "GLU.createGLU(GL)" rather than "new GLU()".
Julien Gouesse | Personal blog | Website