LWJGL Forum

Programming => OpenGL => Topic started by: JaredBGreat on September 22, 2013, 16:33:07

Title: Wrong Model Rendered! glGenBuffers() giving duplicat IDs?
Post by: JaredBGreat on September 22, 2013, 16:33:07
Everything was going great until I added a new model (a rectanglar stand in for later human models).  I had three model (building stand-ins) that render just fine this way.  To be on the safe side I tried changing it to use different buffers for the build arrays, but this didn't change anything.  I've looked and look and can't find any place where I put in the wrong identifies.  The new model also worked in another class (set aside for experimenting, here I'm trying to start tying models to the simulation engine).  I don't get it.  I call the drawPeeps for this model:


   private static void makePeep() {
       glLoadIdentity();
       buildBuffer = BufferUtils.createFloatBuffer(12 * 3 * 7);
       buildBuffer.put(new float[]{...});
       buildBuffer.flip();
       
       peepMID = glGenBuffers();        
       glBindBuffer(GL_ARRAY_BUFFER, peepMID);
       glBufferData(GL_ARRAY_BUFFER, buildBuffer, GL_STATIC_DRAW);
       glBindBuffer(GL_ARRAY_BUFFER, 0);
   }
   
   
   public static void drawPeep(Location loc) {
       glPushMatrix();                
           glTranslatef(loc.getXfloat(), loc.getYfloat() -1f, loc.getZfloat());
           glRotatef(loc.getRotate(), 0, 1, 0);
           glEnableClientState(GL_VERTEX_ARRAY);
           glBindBuffer(GL_ARRAY_BUFFER, peepMID);
           glVertexPointer(36, GL_FLOAT, 28, 0L);

           glEnableClientState(GL_COLOR_ARRAY);
           glBindBuffer(GL_ARRAY_BUFFER, peepMID);
           glColorPointer(36, GL_FLOAT, 28, 12L);

           glDrawArrays(GL_TRIANGLES, 0, 36);
           glDisableClientState(GL_COLOR_ARRAY);
           glDisableClientState(GL_VERTEX_ARRAY);
       glPopMatrix();
   }


...but it uses the vertex and color VBO for this model (which makes really strange models, since this stand it uses quads and the other uses triangle, beside replace a human size model with a one for a commercial building):


   private static void makeGenRec() {
       glLoadIdentity();
       buildBuffer = BufferUtils.createFloatBuffer(6 * 4 * 7);
       buildBuffer.put(new float[] {...});
       buildBuffer.flip();
       modelIDs[2] = glGenBuffers();
       glBindBuffer(GL_ARRAY_BUFFER, modelIDs[2]);
       glBufferData(GL_ARRAY_BUFFER, buildBuffer, GL_STATIC_DRAW);
       glBindBuffer(GL_ARRAY_BUFFER, 0);
   }
   
   
   public static void drawGenRec(Location loc) {
       glPushMatrix();
           //glTranslatef(loc.getXfloat(), loc.getYfloat(), loc.getZfloat());
           glTranslatef(loc.getXfloat(), loc.getYfloat() -1, loc.getZfloat());
           glRotatef(loc.getRotate(), 0, 1, 0);
           
           glEnableClientState(GL_VERTEX_ARRAY);
           glBindBuffer(GL_ARRAY_BUFFER, modelIDs[2]);
           glVertexPointer(3, GL_FLOAT, 28, 0L);

           glEnableClientState(GL_COLOR_ARRAY);
           glBindBuffer(GL_ARRAY_BUFFER, modelIDs[2]);
           glColorPointer(4, GL_FLOAT, 28, 12L);

           glDrawArrays(GL_QUADS, 0, 24);
           glDisableClientState(GL_COLOR_ARRAY);
           glDisableClientState(GL_VERTEX_ARRAY);            
       glPopMatrix();
   }


What is going on?  How can I fix it?  If I can't get Java to keep four simple models separate, how can I expect and large number of complex models to work?  Is there a better way -- maybe to make the IntBuffers work?

I've tried modifying it with an IntBuffer (new type for modleIDs), like so:

   
   private static void makePeep() {
       glLoadIdentity();
       buildBuffer = BufferUtils.createFloatBuffer(12 * 3 * 7);
       buildBuffer.put(new float[]{-0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   
                                   -0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                   -0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   
                                   -0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                   -0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                   -0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                    0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                    0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                   -0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                    0.10f, 0.60f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.60f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                   -0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
       
                                    0.10f, 0.01f,  0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                    0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f,
                                   -0.10f, 0.01f, -0.06f, 1.0f, 1.0f, 1.0f, 1.0f});
       buildBuffer.flip();
       
       glBindBuffer(GL_ARRAY_BUFFER, modelIDs.get(0));
       glBufferData(GL_ARRAY_BUFFER, buildBuffer, GL_STATIC_DRAW);
       glBindBuffer(GL_ARRAY_BUFFER, 0);
   }
   
   
   public static void drawPeep(Location loc) {
       glPushMatrix();                
           glTranslatef(loc.getXfloat(), loc.getYfloat() -1f, loc.getZfloat());
           glRotatef(loc.getRotate(), 0, 1, 0);
           glEnableClientState(GL_VERTEX_ARRAY);
           glBindBuffer(GL_ARRAY_BUFFER, modelIDs.get(0));
           glVertexPointer(36, GL_FLOAT, 28, 0L);

           glEnableClientState(GL_COLOR_ARRAY);
           glBindBuffer(GL_ARRAY_BUFFER, modelIDs.get(0));
           glColorPointer(36, GL_FLOAT, 28, 12L);

           glDrawArrays(GL_TRIANGLES, 0, 36);
           glDisableClientState(GL_COLOR_ARRAY);
           glDisableClientState(GL_VERTEX_ARRAY);
       glPopMatrix();
   }


...but I get the exact seem results.
Title: Re: Wrong Model Rendered! glGenBuffers() giving duplicat IDs?
Post by: JaredBGreat on September 22, 2013, 18:22:33
Just to let anyone reading this know:  I put in some debug code to print out the VBO IDs, and they are not duplicates.  I'm not using the wrong indices (checked, re-checked, and rechecked some more).  I even used my debug data to enter the IDs in the right place by hand as literals.  No change, same garbage on my screen.  I almost wonder if this should be under "Bugs" rather than "OpenGL."  Does anyone know what causes this or what (if anything) I can do about it?

Also, if anyone wants to know, I'm running Kubuntu 13.04 Linux on a Core i7 Ivy Bridge, with 8GB ram, (only) Intel HD4000 graphics, lwjgl 2.9.0 (regular, non-daily), and real Oracle/Sun Java -- might be important if its an OpenGL or lwjgl bug.
Title: Re: Wrong Model Rendered! glGenBuffers() giving duplicat IDs?
Post by: quew8 on September 22, 2013, 21:00:10
I have issues with these lines:

Quote
            glVertexPointer(36, GL_FLOAT, 28, 0L);
and
Quote
            glColorPointer(36, GL_FLOAT, 28, 12L);

I don't think you have 36 elements to your positions and colours. In fact, this is from the OpenGL docs for glVertexPointer():

Quote
size
Specifies the number of coordinates per vertex. Must be 2, 3, or 4. The initial value is 4.

and

Quote
GL_INVALID_VALUE is generated if size is not 2, 3, or 4.

This tells me two things:

1) This function call is being ignored by OpenGL. Which is why your getting this problem. The pointers stay pointing toward the other model's vbo so that is what is drawn.

2) An error is being thrown by OpenGL and you didn't notice this. Which means you are not checking your OpenGL errors!!!!! I would reprimand you for this but I think the precious hours you have spent trying to debug this will have done that for me.