This post was updated on .
Hello everyone,
using the latest autobuild, I guess I have found a bug in jogl. Everytime I use glBufferData or glBufferSubData the transmitted data seems to be completly empty. I discoevered this bug after coding a little test application, because I wanted to check how things in OpenGL work. The test application didn't displan anything, but after some googling I still couldn't figure out what I was doing wrong. So I coded the same application in C++ using freeglut and there it worked. So I compared the code, but they both were equivlant, except for the different language classes (e.g Buffers in Java, vector in C++ for storing to be transmitted data). Finally I checked with apitrace, a very useful tool, that displays all OpenGL functions calls an application makes, and even there the calls there the same. But I noticed that in the java the data actually transmitted to the GPU via glBufferData or glBufferSubData is always empty (means containing only 0.0f). The buffer's contents are allright, I dump them before making the call. Here's a screenshot: http://img64.imageshack.us/img64/5113/joglbug.png used jogl autobuild b426 and gluegen autobuild b386 source code of the application (relevant parts): http://pastebin.com/yteMn9ZS source code of c++ application (ignore the comments): http://pastebin.com/ndn7BVrQ edit: executeable jar, if anyone cares: http://www.file-upload.net/download-3673777/glPointerTestRunable.jar.html |
Administrator
|
Hi!
A call of indices.rewind() is missing before the line 153 (you use get() on this buffer which changes the position). The position in the NIO buffer is very important for JOGL. I used these methods a few months ago without problems. If you're sure something is wrong, write a very short test case which exhibits the wrong behavior. Maybe it is a regression. Best regards
Julien Gouesse | Personal blog | Website
|
Just tested with calling the rewind() function for both the vertexPositions and indices, before uploading the data to OpenGL. It changed nothing, same problem as before. About the minimal testprogram, my source code is actually just made of that I provided. Ok, there's sure for sure a short function opening the window (aka JFrame), but it's really short and it doesn't do anything special. Here's a minimal eclipse project with all files necessary to build: http://www.file-upload.net/download-3674197/glBufferDataProblem.tar.gz.html
PS.: Can anyone tell me what's a good free file uploader, I just used the first found by google |
Administrator
|
call vertexPositions.rewind() before calling gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, verticesSizeInBytes, vertexPositions)
Julien Gouesse | Personal blog | Website
|
Administrator
|
I checked the positions of the buffers, and they are already at 0 before and after all the glBuffer* calls. Let me look closer.
Henry: as for a file upload service, you can upload files directly to this forum by clicking "More options > Upload a file" when you're composing a message. You can also insert an image by clicking "Insert Image" -- you don't have to put it on an image hosting site. |
In reply to this post by gouessej
Just tried to call rewind() directly before calling glBufferData. Still doens't work, I tested with
private void setUPVBO(GL2 gl) { // create vbo gl.glGenBuffers(2, vboID, 0); // create buffer for vbo float[] verticesPlain = new float[] { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f }; vertexPositions = ByteBuffer.allocateDirect(verticesSizeInBytes).asFloatBuffer(); vertexPositions.put(verticesPlain); // DEBUG System.out.println("dumping vertexPositions"); vertexPositions.rewind(); for (int i = 0; vertexPositions.hasRemaining(); ++i) { if ((i % componentsPerVertex) == 0 && i != 0) { System.out.println(); } System.out.print(vertexPositions.get() + " "); } System.out.println(); // ------ // upload data gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vboID[0]); vertexPositions.rewind(); gl.glBufferData(GL.GL_ARRAY_BUFFER, verticesSizeInBytes, vertexPositions, GL2.GL_STATIC_DRAW); //gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, verticesSizeInBytes, vertexPositions); gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vboID[1]); vertexPositions.rewind(); gl.glBufferData(GL.GL_ARRAY_BUFFER, verticesSizeInBytes, vertexPositions, GL2.GL_STATIC_DRAW); //gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, verticesSizeInBytes, vertexPositions); vertexPositions = null; } private void setUPIBO(GL2 gl) { //create ibo gl.glGenBuffers(1, iboID, 0); // create buffer for ibo short[] indicesPlain = new short[] { 0, 1, 2, 2, 3, 0 }; indices = ByteBuffer.allocateDirect(indicesSizeInBytes).asShortBuffer(); indices.put(indicesPlain); // DEBUG System.out.println("dumping indices"); indices.rewind(); while (indices.hasRemaining()) { System.out.print(indices.get() + " "); } System.out.println(); // --------- //upload data gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, iboID[0]); indices.rewind(); gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indicesSizeInBytes, indices, GL2.GL_STATIC_DRAW); indices = null; } Edit: Sorry, I guess this post is useless, didn't see Wake Walker's post |
Administrator
|
Problem solved! You just need to make your buffers native ordered. To do so, change:
// vertexPositions = ByteBuffer.allocateDirect(verticesSizeInBytes).asFloatBuffer(); vertexPositions = Buffers.newDirectFloatBuffer(verticesSize); and // indices = ByteBuffer.allocateDirect(indicesSizeInBytes).asShortBuffer(); indices = Buffers.newDirectShortBuffer(indicesSize); When I make those two changes, I see two white squares on screen |
Also made the changes and it works. Thank you for your help. I didn't even know there are functions allocating a direct FloatBuffer, that's why I used ByteBuffer and asFloatBuffer().
|
Free forum by Nabble | Edit this page |