Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have 2 custom classes, one is for drawing quads (Quad) and the other is for drawing quads using VBO's (VBOQuad).

If I create a simple quad and render it like so:

Quad sprite = new Quad();
sprite.Draw(0,0,mMPVMatrix)

Then it works perfectly.

Likewise if I create and draw a VBO like so:

VBOQuad sprite2 = new VBOQuad();
sprite2.draw(0,0,mMPVMatrix);

Then again, all is OK and the VBO Draws (I have FPS issues with my VBO's but that's another matter for which I will post another question).

However, if I do this:

Quad sprite = new Quad();
VBOQuad sprite2 = new VBOQuad();

And then draw my normal quad like so

sprite.Draw(0,0,mMPVMatrix);

Then I get nothing, I have no idea why but the act of simply creating a VBOQuad object seems to render my Quad object 'dead' as it were.

I'm not sure which parts of my code to post, but as it seems to be an object creation problem, the constructors seemed appropriate:

Constructor for simple quads

    //Constructor
    public Quad() {

        //Set values for quad size (These should be change with setSize())

        quadWidth=50;
        quadHeight=50;

        rotate(0,0,0);

        //Create initial Byte Buffer - it will then be updated every frame
        vertexBuf = ByteBuffer.allocateDirect(vertices.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();

    }

Constructor for VBO's

        //Constructor
        public VBOQuad() {

        //Set values for quad size (These should be change with setSize())

        quadWidth=50;
        quadHeight=50;

        rotate(0,0,0);

        //Create initial Byte Buffer - it will then be updated every frame
        vertexBuf = ByteBuffer.allocateDirect(vertices.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();

        // First, generate as many buffers as we need.
        // This will give us the OpenGL handles for these buffers.
        GLES20.glGenBuffers(1, buffers, 0);

        // Bind to the buffer. Future commands will affect this buffer specifically.
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);

                    //Create buffer which will be updated every frame
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexBuf.capacity() * 4,vertexBuf, GLES20.GL_STATIC_DRAW);
    }

Would anyone have any idea why creating one type of object would interfere with the displaying of another type of object? My understanding is that each class has it's own variables etc... so there shouldn't be any cross-over. (Even for 2 objects of the same class this is true), so what gives?! Suggestions would be very welcome.......

share|improve this question
Could it be that you still have the vbo bound? – Will Apr 20 at 15:28
Hi @Will, thanks for the comment, could you elaborate? Thanks! – user22241 Apr 28 at 12:57
after drawing with the VBO, unbind it: GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); – Will Apr 29 at 7:18
Thanks! I will check. – user22241 May 3 at 9:52

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.