LWJGL
May 19, 2013, 08:10:52 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Drawing triangle from vertex buffer, exception  (Read 667 times)
ReddZed
Newbie
*
Posts: 2


« on: June 13, 2012, 14:50:08 »

Hi, I was working through some tutorials around to learn other techniques than immediate mode. Basically translating this C example into LWJGL: http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=5

So I create a float[] of for the triangle data, push it into a buffer in my initArrays() method.

Then in my render() method I bind to that buffer and set up the vertex array pointer to start at zero and move in steps of 3 over the buffer (to get the 3 values to form the vertex locations I'm assuming). However, when it executes the call to glVertexAttribPointer() I get the following exception:

Code:
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Cannot use Buffers when Array Buffer Object is enabled
at org.lwjgl.opengl.GLChecks.ensureArrayVBOdisabled(GLChecks.java:87)
at org.lwjgl.opengl.GL20.glVertexAttribPointer(GL20.java:835)
at com.gordonmcmahon.lwjgl.temp.OpenGL3App.render(OpenGL3App.java:79)
at com.gordonmcmahon.lwjgl.temp.OpenGL3App.<init>(OpenGL3App.java:39)
at com.gordonmcmahon.lwjgl.temp.OpenGL3App.main(OpenGL3App.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


I've googled and gone through the source to try and find out why arrayBuffer is set to 1 on the Capabilities (and therefore failing the GLCheck) but I've not come up with much. Source for the two key methods below, but I can post the whole source if you think that will help.

Thanks in advance.


Code:
[tt]private void initArrays(){
        fTriangle[0] = -0.2f;   fTriangle[1] = 0.1f;    fTriangle[2] = 0.0f;
        fTriangle[3] = 0.4f;    fTriangle[4] = 0.1f;    fTriangle[5] = 0.0f;
        fTriangle[6] = 0.0f;    fTriangle[7] = 0.7f;    fTriangle[8] = 0.0f;

        triangleBuffer = BufferUtils.createFloatBuffer(fTriangle.length);
        triangleBuffer.put(fTriangle);

        uiVBO = BufferUtils.createIntBuffer(1);
        glGenBuffers(uiVBO);

        glBindBuffer(GL_ARRAY_BUFFER, uiVBO.get(0));
        glBufferData(GL_ARRAY_BUFFER, triangleBuffer, GL_STATIC_DRAW );
    }


Code:
   
private void render() {
        glClear(GL_COLOR_BUFFER_BIT);

        glEnableVertexAttribArray(0);

        // Triangle render
        glBindBuffer(GL_ARRAY_BUFFER, uiVBO.get(0));
        glVertexAttribPointer(0, 3, false, 0, triangleBuffer);    // THIS IS WHERE THE EXCEPTION IS THROWN
        glDrawArrays(GL_TRIANGLES, 0, 3);
    }
Logged
ReddZed
Newbie
*
Posts: 2


« Reply #1 on: June 19, 2012, 00:48:46 »

Ahh...you've all played a cunning game of "leave him alone and he'll fix it himself". Well done. I've since got my code working and have a much better understanding of what I was doing wrong.
Logged
matheus23
Regular nerd
**
Posts: 62


« Reply #2 on: June 19, 2012, 10:05:29 »

Ahh...you've all played a cunning game of "leave him alone and he'll fix it himself". Well done. I've since got my code working and have a much better understanding of what I was doing wrong.
Lol... Cheesy
Logged

My github account and currently active project: https://github.com/matheus23/UniverseEngine
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!