Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] VBO error: array vertex_buffer_object must be disabled  (Read 4527 times)
0 Members and 1 Guest are viewing this topic.
Offline voodoogiant

Senior Newbie





« Posted 2010-08-04 03: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)

      // bind VBOs for vertex array and index array
      gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, vertexVBO(0))        // for vertex coordinates
      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)) // for indices
      gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, triangleCount * 3 *
                         BufferUtil.SIZEOF_SHORT, indices, GL.GL_STATIC_DRAW_ARB)


     

      // number of coordinates per vertex, the type of each coordinate, stride, and ptr offset
      gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices)

      ... fill in with data ...

      gl.glEnableClientState(GL.GL_VERTEX_ARRAY)             // activate vertex coords array
      gl.glDrawElements(GL.GL_TRIANGLES, triangleCount, GL.GL_UNSIGNED_SHORT, 0)
      gl.glDisableClientState(GL.GL_VERTEX_ARRAY)

      // bind with 0, so, switch back to normal pointer operation
      gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, 0)
      gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, 0)
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2010-08-04 12: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
Offline voodoogiant

Senior Newbie





« Reply #2 - Posted 2010-08-04 13:11:30 »

Quote
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) // still need to port this
      gl.glCompileShader(vs)
      val fs = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER)
      gl.glShaderSource(fs, 1, (const GLchar **) &fragment_shader_code, NULL) // still need to port this
      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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2010-08-04 13: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
Offline voodoogiant

Senior Newbie





« Reply #4 - Posted 2010-08-04 14: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. 
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2010-08-04 15: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
Offline voodoogiant

Senior Newbie





« Reply #6 - Posted 2010-08-05 05: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)
    //val buffer = BufferUtil.newFloatBuffer(8)
    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_TRIANGLE_STRIP, 0, 4)
      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);
}


Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2010-08-05 06: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
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2010-08-05 06: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
Offline gouessej
« Reply #9 - Posted 2010-08-05 11:15:24 »

after the last put()
triangleData.put(-1f)

call
triangleData.flip()
I would rather call rewind().

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 423
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2010-08-05 11:59:45 »

rewind() doesn't set the limit for the buffer thus leaving its valid data length something of a mystery...

Cas Smiley

Offline gouessej
« Reply #11 - Posted 2010-08-05 12:35:50 »

rewind() doesn't set the limit for the buffer thus leaving its valid data length something of a mystery...

Cas Smiley

The limit is set at the creation of the buffer:
Quote
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:
Quote
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.

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2010-08-05 13:32:49 »

 Roll Eyes

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
Offline voodoogiant

Senior Newbie





« Reply #13 - Posted 2010-08-06 05: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. 
Offline gouessej
« Reply #14 - Posted 2010-08-06 10: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. 
Cheesy you're welcome.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (72 views)
2014-11-26 15:22:04

toopeicgaming1999 (61 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (28 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!