voodoogiant
JGO n00b  Posts: 31
|
 |
«
on:
2010-08-03 23:47:50 » |
|
I keep getting this error trying to get a basic VBO to work. Is this a common error? 1
| Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: array vertex_buffer_object must be disabled to call this method |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| gl.glGenBuffersARB(1, vertexVBO, 0) gl.glGenBuffersARB(1, indexVBO, 0)
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, vertexVBO(0)) gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, triangleCount * 3 * 3 * BufferUtil.SIZEOF_FLOAT, vertices, GL.GL_STATIC_DRAW_ARB) gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, indexVBO(0)) gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, triangleCount * 3 * BufferUtil.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW_ARB)
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices)
... fill in with data ...
gl.glEnableClientState(GL.GL_VERTEX_ARRAY) gl.glDrawElements(GL.GL_TRIANGLES, triangleCount, GL.GL_UNSIGNED_SHORT, 0) gl.glDisableClientState(GL.GL_VERTEX_ARRAY)
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, 0) gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, 0) |
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #1 on:
2010-08-04 08:55:10 » |
|
When in trouble, simplify your problem. Don't debug something in the middle of a complex app. As a reference, use: http://sscce.org/Regarding your problem: you cannot use VBOs and VAs (vertex arrays) at the same time in OpenGL. To use one, you need to disable the other, like glBindBufferARB(..., 0). Both JOGL and LWJGL are checking this for you, so it doesn't trip the driver and crash your app with a segfault.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
voodoogiant
JGO n00b  Posts: 31
|
 |
«
Reply #2 on:
2010-08-04 09:11:30 » |
|
When in trouble, simplify your problem. Don't debug something in the middle of a complex app. This is easier said than done with OpenGL 3, and I wouldn't call this a complex app. One has to go through a bit of code just to get something on the screen. I couldn't find many JOGL VBO examples, so I grabbed a C++ one, which was apparently wrong. I'm going to try getting it to work with JOGL 2.0 (was using 1.1.1). Based on some other example code, I have the following so far. It's in scala, but should be easy enough to read. Do you see anything wrong with this? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| def display(drawable:GLAutoDrawable) { val gl = drawable.getGL().getGL3() gl.glClear(GL.GL_COLOR_BUFFER_BIT) gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4) }
val gl = drawable.getGL().getGL3()
gl.glGenBuffers(1, bufferObject, 0) gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferObject(0)) gl.glBufferData(GL.GL_ARRAY_BUFFER, 4 * 2 * BufferUtil.SIZEOF_FLOAT, buffer, GL.GL_STATIC_DRAW) val data = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_WRITE_ONLY).asFloatBuffer() data.put(-0.75f) data.put(-0.75f) data.put(-0.75f) data.put(0.75f) data.put(0.75f) data.put(0.75f) data.put(0.75f) data.put(-0.75f) gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER)
gl.glVertexAttribPointer(0, 2, GL.GL_FLOAT, false, 0, 0) val vs = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER) gl.glShaderSource(vs, 1, (const GLchar **) &vertex_shader_code, NULL) gl.glCompileShader(vs) val fs = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER) gl.glShaderSource(fs, 1, (const GLchar **) &fragment_shader_code, NULL) gl.glCompileShader(fs) val program = gl.glCreateProgram() gl.glAttachShader(program, vs) gl.glAttachShader(program, fs) gl.glLinkProgram(program) gl.glUseProgram(program) } |
Also, you can see I use GL2ES2 to get the vertex and fragment values. For some reason GL.GL_VERTEX_SHADER and GL.GL_FRAGMENT_SHADER weren't contained in GL or GL3 despite what the documentation said.
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #3 on:
2010-08-04 09:19:04 » |
|
I don't get it. You have trouble with VBO/VA and still you are dealing with shaders.
Try to get a single triangle to render with VAs, and then with VBOs. Work from there, in small steps.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
voodoogiant
JGO n00b  Posts: 31
|
 |
«
Reply #4 on:
2010-08-04 10:58:51 » |
|
I'm using OpenGL core, so I have to use shaders. I don't think that's the issue here. There's a certain amount of setup for these VBOs and I was just wondering if an experienced VBO user could tell me if it "looked" correct.
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #5 on:
2010-08-04 11:10:33 » |
|
I keep getting this error trying to get a basic VBO to work. Is this a common error? 1
| Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: array vertex_buffer_object must be disabled to call this method |
So... on which line does the Exception happen? My *guess* is that it happens on: 1
| gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices) |
Why are you specifying a VA when you already put the data into a VBO? You should use: 1
| glVertexPointer(size, type, stride, pntr_offset); |
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
voodoogiant
JGO n00b  Posts: 31
|
 |
«
Reply #6 on:
2010-08-05 01:07:09 » |
|
Alright, I cleaned up my code to look like Stu Pomerantz's VBO example ( http://stupomerantz.com/public/opengl/). It certainly looks cleaner, but I'm still not getting anything drawn to my screen. I still need to check the output of my shaders to make sure they're working, but still I'm perplexed why nothing is showing up. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| val bufferObject = new Array[int](1) def init(drawable:GLAutoDrawable) { val gl = drawable.getGL().getGL3()
gl.glClearColor(.3f, .3f, .3f, 0)
val triangleData = BufferUtil.newFloatBuffer(9) triangleData.put(-0.9f) triangleData.put(-0.9f) triangleData.put(-1f)
triangleData.put(0.9f) triangleData.put(-0.9f) triangleData.put(-1f)
triangleData.put(0.9f) triangleData.put(0.9f) triangleData.put(-1f)
gl.glGenBuffers(1, bufferObject, 0) gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferObject(0)) gl.glBufferData(GL.GL_ARRAY_BUFFER, 9*BufferUtil.SIZEOF_FLOAT, triangleData, GL.GL_STATIC_DRAW) } |
1 2 3 4 5 6 7 8 9 10 11 12 13
| def display(drawable:GLAutoDrawable) { val gl = drawable.getGL().getGL3() gl.glClear(GL.GL_COLOR_BUFFER_BIT)
dummyShader.bind(gl) gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufferObject(0)) val vertexLocation = dummyShader.attribLocation(gl, "vertex") gl.glVertexAttribPointer(vertexLocation, 3, GL.GL_FLOAT, false, 0, 0) gl.glEnableVertexAttribArray(vertexLocation) gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3) dummyShader.release(gl) } |
1 2 3 4 5
| in vec3 vertex;
void main() { gl_Position = vec4(vertex,1.0); } |
1 2 3
| void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); } |
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #7 on:
2010-08-05 02:56:43 » |
|
after the last put() triangleData.put(-1f)
call triangleData.flip()
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #8 on:
2010-08-05 02:59:46 » |
|
Maybe it's fixed on OpenGL ES, but at least on my desktop I found that *not* using gl_Vertex in a vertex shader can cause a factor 10 drop of performance.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
gouessej
JGO Kernel      Posts: 3560 Medals: 30
TUER
|
 |
«
Reply #9 on:
2010-08-05 07:15:24 » |
|
after the last put() triangleData.put(-1f)
call triangleData.flip()
I would rather call rewind().
|
Julien Gouesse
|
|
|
Games published by our own members! Go get 'em!
|
|
princec
« League of Dukes » JGO Kernel      Posts: 8089 Medals: 96
Eh? Who? What? ... Me?
|
 |
«
Reply #10 on:
2010-08-05 07:59:45 » |
|
rewind() doesn't set the limit for the buffer thus leaving its valid data length something of a mystery... Cas 
|
|
|
|
gouessej
JGO Kernel      Posts: 3560 Medals: 30
TUER
|
 |
«
Reply #11 on:
2010-08-05 08:35:50 » |
|
rewind() doesn't set the limit for the buffer thus leaving its valid data length something of a mystery... Cas  The limit is set at the creation of the buffer: allocateDirect
public static ByteBuffer allocateDirect(int capacity)
Allocates a new direct byte buffer.
The new buffer's position will be zero, its limit will be its capacity Calling rewind() does not change the limit and it is what we want as the limit is already set: rewind() makes a buffer ready for re-reading the data that it already contains: It leaves the limit unchanged and sets the position to zero.
|
Julien Gouesse
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #12 on:
2010-08-05 09:32:49 » |
|
 Who cares. Both work, in this specific case. This is a thread where somebody tries to get something to work. Gouessej, what you said it correct, in this specific case. What Cas and I said, is correct, in the general case.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
voodoogiant
JGO n00b  Posts: 31
|
 |
«
Reply #13 on:
2010-08-06 01:23:50 » |
|
I was actually wondering if I needed to rewind the buffer, but was already on my way to work. Rewinding the buffer after pushing all the data did the trick. Thanks.
|
|
|
|
|
gouessej
JGO Kernel      Posts: 3560 Medals: 30
TUER
|
 |
«
Reply #14 on:
2010-08-06 06:26:35 » |
|
I was actually wondering if I needed to rewind the buffer, but was already on my way to work. Rewinding the buffer after pushing all the data did the trick. Thanks.
 you're welcome.
|
Julien Gouesse
|
|
|
|