glVertexAttribPointer causes GL_INVALID_OPERATION

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

glVertexAttribPointer causes GL_INVALID_OPERATION

Hotzenplotz
This post was updated on .
Hi,

i cant figure out what i am doing wrong. When i call glVertexAttribPointer i get an GL_INVALID_OPERATION:

display method (scala code):
val gl = glautodrawable.getGL.getGL3
gl.glClear( GL.GL_COLOR_BUFFER_BIT );
gl.glClearColor(0,0.5f,1,0)

gl.glUseProgram(_prog.id)
				
//println(gl.getInt(GL2.GL_MAX_VERTEX_ATTRIBS_ARB)) // => 29
//println(gl.getInt(GL2GL3.GL_MAJOR_VERSION)) // => 3

val attrIdx = 0

gl.glBindAttribLocation(_prog.id,attrIdx,"position")
gl.throwWhenError
gl.glBindBuffer(GL.GL_ARRAY_BUFFER,vboId)
gl.throwWhenError
gl.glEnableVertexAttribArray(attrIdx)
gl.throwWhenError // <-- #throws NO error#

gl.glVertexAttribPointer(attrIdx,3,GL.GL_FLOAT,false,0,0)
gl.throwWhenError // <-- #throws the error#

gl.setProgramUniform(_prog.id,'modelview_matrix,_camera.modelViewMatrix)
gl.setProgramUniform(_prog.id,'projection_matrix,_camera.projectionMatrix)

gl.drawPrimitives(Primitives.Triangles,6)

gl.glDisableVertexAttribArray(attrIdx)

The vbo is set up like this:
val plane = Geometry.groundPlaneAttributes // just an array of 6*3 floats

vboId = gl.generateBuffer
gl.glBindBuffer(GL.GL_ARRAY_BUFFER,vboId)
				gl.loadBufferData(GL.GL_ARRAY_BUFFER,6*3*4,FloatBuffer.wrap(plane),GL.GL_STATIC_DRAW)

This returns true:
gl.isExtensionAvailable("GL_ARB_vertex_buffer_object")

What am i doing wrong? Or how could i find out whats wrong? I have this error with jogl-2.0-b544/gluegen-2.0-b437 and jogl-2.0-b23/gluegen-2.0-b23.

EDIT:
Im using:
val glprofile = GLProfile.get(GLProfile.GL3)
val glcapabilities = new GLCapabilities(glprofile)
val glcanvas = new GLCanvas(glcapabilities)
Reply | Threaded
Open this post in threaded view
|

Re: glVertexAttribPointer causes GL_INVALID_OPERATION

Hotzenplotz
This post was updated on .

Ok, solved it by myself by inspecting the VertexProgWarp.java of the demos. In the first calls to the display method it seems like opengl is not fully initialized, therefore it throws an invalid operation. I included a framecounter that gets incremented on each display-invocation and only call methods like glVertexAttribPointer when the counter is greater than 1.

Edit: No, the display method only got to frame #1, so the code was never called and threw no exception. The problem is still there.
Reply | Threaded
Open this post in threaded view
|

Re: glVertexAttribPointer causes GL_INVALID_OPERATION

Hotzenplotz
Ok, now i solved it. It seems like one has to explicitly create and bind an Vertex Array Object in order to be able to render anything. So i just added this to my initialization:

_vao = gl.generateVertexArrayObject // custom method wrapping error handling etc
gl.glBindVertexArray(_vao)