Changing VBO Data not Changing Rendered Model

Started by JaredBGreat, February 21, 2015, 20:21:15

Previous topic - Next topic

JaredBGreat

I'm not sure if this is the right forum or not, that is, if this is an LWJGL bug or something else going wrong, but I'm getting some strange results with defining a very simple (two triangle) VBO.

Changing the float buffer creation like so:
        FloatBuffer buffer = BufferUtils.createFloatBuffer(2 * 3 * 5);
        System.out.println("sideLength = " + sideLength);
        float[] preBuffer = new float[]{0f,         0f,                   0f, 0f, 0f,
                               0f,                  (float)(-sideLength), 0f, 0f, 1f,
                               (float)(sideLength), (float)(-sideLength), 0f, 1f, 1f,
                               0f,                  0f,                   0f, 0f, 0f, 
                               (float)(sideLength), 0f,                   0f, 1f, 0f,
                               (float)(sideLength), (float)(-sideLength), 0f, 1f, 1f};
        for(int i = 0; i < preBuffer.length; i++) {
            System.out.println(preBuffer[i]);
        }
        buffer.clear();
        buffer.put(preBuffer);
        buffer.flip();




...to...
        FloatBuffer buffer = BufferUtils.createFloatBuffer(2 * 3 * 5);
        System.out.println("sideLength = " + sideLength);
        float[] preBuffer = new float[]{0f,         0f,                   0f, 0f, 0f,
                               0f,                  (float)(-sideLength / 2), 0f, 0f, 1f,
                               (float)(sideLength / 2), (float)(-sideLength / 2), 0f, 1f, 1f,
                               0f,                  0f,                   0f, 0f, 0f, 
                               (float)(sideLength / 2), 0f,                   0f, 1f, 0f,
                               (float)(sideLength / 2), (float)(-sideLength / 2), 0f, 1f, 1f};
        for(int i = 0; i < preBuffer.length; i++) {
            System.out.println(preBuffer[i]);
        }
        buffer.clear();
        buffer.put(preBuffer);
        buffer.flip();




Has the expected and desired result, images (on the models) become smaller as expected, but changing the variable:
public static final int sideLength = 24;


to something like

public static final int sideLength = 12;


or

public static final int sideLength = 24 / 2;




Has no effect, despite debugging code showing the correct value in the array.  (Full code for the class is at: https://github.com/BlackJar72/MacyMae/blob/master/src/me/jaredblackburn/macymae/graphics/Graphic.java)

Is this a bug in LWJGL?  Something just weird going on in OpenGL?  Something else (that I'm doing?)?  I'm confused.

EDIT: This is with LWJGL 2.9.1 on a IvyBridge machine with HD4000 graphics and Linux Mint, and Oracle Java 7 (and other version, using 7).
EDIT 2: I just upgrade to LWJGL 2.9.3, same results.

Kai

You must be doing something else wrong in your code at some place not shown in your code snippet and the mentioned 'Graphic' class.
Maybe you reference the public static sideLength field somewhere else in your application, possibly when you set the viewport or some projection/view matrices.

Your mentioned Graphics class however seems to be just fine.
You are doing some unnecessary no-op pushMatrix, loadIdentity and popMatrix in makeTileVBO() though, which you can get rid of, but that's not the issue here.

Other than that, your interleaved VBO is setup correctly and draw() also sets correct pointer stride and offset.
Currently, I see nothing wrong with just that Graphic class.

But, the fact that hoisting the integer division / 2 out of the float array initialization into the sideLength field gives different results for you, can only mean that there is some other code depending on sideLength not shown here, which influences the final rendering result.
That all is very very likely neither a bug in LWJGL nor in OpenGL.

JaredBGreat

Sorry for being such a noob, and thanks for the reply.  I've found and fixed the problem; it seems I was using it elsewhere to calculate the window size in a naive scaling attempt.  I have since fixed both problems.