为什么这个SpriteBatch在C#中工作而在Java中不工作?

为什么这个SpriteBatch在C#中工作而在Java中不工作?,java,c#,opengl,spritebatch,Java,C#,Opengl,Spritebatch,我有两种不同语言编写的SpriteBatch版本: 爪哇: C#: 它们有相同的代码,都在一个简单的程序中进行以下调用: 爪哇: C#: OpenGL的上下文对于这两个方面都是完全相同的(3.3) 然而,C#版本做了它应该做的事情(画一个白色矩形),而Java版本什么也不做(只有绿色背景)。谁能告诉我有什么不同吗?什么不起作用?非常感谢。我已经在这个问题上坚持了三个星期。所以,我实际上发现了问题所在。这与Java管理内存的方式以及Java在这方面是一堆垃圾有关。它在C#中工作而不在Java中工作

我有两种不同语言编写的SpriteBatch版本:

爪哇: C#:

它们有相同的代码,都在一个简单的程序中进行以下调用:

爪哇:

C#:

OpenGL的上下文对于这两个方面都是完全相同的(3.3)


然而,C#版本做了它应该做的事情(画一个白色矩形),而Java版本什么也不做(只有绿色背景)。谁能告诉我有什么不同吗?什么不起作用?非常感谢。我已经在这个问题上坚持了三个星期。

所以,我实际上发现了问题所在。这与Java管理内存的方式以及Java在这方面是一堆垃圾有关。它在C#中工作而不在Java中工作的原因是,C#提供对指针的访问,而Java最接近的东西是NIO缓冲区。为了让OpenGL调用工作,必须提供物理指针,但缓冲区可以根据它们的构造方式提供物理或虚拟指针。简而言之,将“ByteBuffer.allocateDirect”替换为“BufferUtils.createByteBuffer”可以解决这个问题。尽管如此,我宁愿看到Java被修复:P

    private void GenerateBatches() {
        if(glyphs.size() < 1) return;

        // Create Arrays
        ByteBuffer bb = BufferUtils.createByteBuffer(6 * glyphs.size() * VertexSpriteBatch.Size);
        SpriteBatchCall call = new SpriteBatchCall(0, glyphs.get(0).Texture, batches);
        glyphs.get(0).VTL.AppendToBuffer(bb);
        glyphs.get(0).VTR.AppendToBuffer(bb);
        glyphs.get(0).VBL.AppendToBuffer(bb);
        glyphs.get(0).VBL.AppendToBuffer(bb);
        glyphs.get(0).VTR.AppendToBuffer(bb);
        glyphs.get(0).VBR.AppendToBuffer(bb);
        emptyGlyphs.add(glyphs.get(0));

        int gc = glyphs.size();
        for(int i = 1; i < gc; i++) {
            SpriteGlyph glyph = glyphs.get(i);
            call = call.Append(glyph, batches);
            glyph.VTL.AppendToBuffer(bb);
            glyph.VTR.AppendToBuffer(bb);
            glyph.VBL.AppendToBuffer(bb);
            glyph.VBL.AppendToBuffer(bb);
            glyph.VTR.AppendToBuffer(bb);
            glyph.VBR.AppendToBuffer(bb);
            emptyGlyphs.add(glyphs.get(i));
        }
        bb.flip();
        glyphs = null;

        // Set The Buffer Data
        glBindBuffer(BufferTarget.ArrayBuffer, vbo);
        if(gc > glyphCapacity) {
            glyphCapacity = gc * 2;
            glBufferData(
                    BufferTarget.ArrayBuffer,
                    (glyphCapacity * 6) * VertexSpriteBatch.Size,
                    bufUsage
                    );
        }
        glBufferSubData(BufferTarget.ArrayBuffer, 0, bb);
        GLBuffer.Unbind(BufferTarget.ArrayBuffer);
    }
private void generateBaches(){
if(glyphs.size()<1)返回;
//创建数组
ByteBuffer bb=BufferUtils.createByteBuffer(6*glyphs.size()*VertexSpriteBatch.size);
SpriteBatchCall=新SpriteBatchCall(0,glyphs.get(0).Texture,批次);
字形。get(0)。VTL。AppendToBuffer(bb);
字形.get(0).VTR.AppendToBuffer(bb);
glyphs.get(0.VBL.AppendToBuffer(bb);
glyphs.get(0.VBL.AppendToBuffer(bb);
字形.get(0).VTR.AppendToBuffer(bb);
glyphs.get(0.VBR.AppendToBuffer(bb);
emptyGlyphs.add(glyphs.get(0));
int gc=glyphs.size();
for(int i=1;i容量){
容量=gc*2;
glBufferData(
BufferTarget.ArrayBuffer,
(容量*6)*垂直SpriteBatch.尺寸,
鼻塞
);
}
glBufferSubData(BufferTarget.ArrayBuffer,0,bb);
GLBuffer.Unbind(BufferTarget.ArrayBuffer);
}

请不要将每个单词的首字母大写。这让你的问题很难理解。K,很抱歉。习惯。
    GL.Viewport(0, 0, game.Width, game.Height);
    GL.ClearColor(0, 1, 0, 1);
    GL.ClearDepth(1.0);
    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

    sb.Begin();
    sb.Draw(tex, new Vector2(-0.5f, 0.5f), new Vector2(1, -1), Color.White);
    sb.End(SpriteSortMode.None);
    sb.RenderBatch(Matrix4.Identity, Matrix4.Identity, BlendState.Opaque, SamplerState.PointWrap, DepthState.None, RasterizerState.CullNone);
    private void GenerateBatches() {
        if(glyphs.size() < 1) return;

        // Create Arrays
        ByteBuffer bb = BufferUtils.createByteBuffer(6 * glyphs.size() * VertexSpriteBatch.Size);
        SpriteBatchCall call = new SpriteBatchCall(0, glyphs.get(0).Texture, batches);
        glyphs.get(0).VTL.AppendToBuffer(bb);
        glyphs.get(0).VTR.AppendToBuffer(bb);
        glyphs.get(0).VBL.AppendToBuffer(bb);
        glyphs.get(0).VBL.AppendToBuffer(bb);
        glyphs.get(0).VTR.AppendToBuffer(bb);
        glyphs.get(0).VBR.AppendToBuffer(bb);
        emptyGlyphs.add(glyphs.get(0));

        int gc = glyphs.size();
        for(int i = 1; i < gc; i++) {
            SpriteGlyph glyph = glyphs.get(i);
            call = call.Append(glyph, batches);
            glyph.VTL.AppendToBuffer(bb);
            glyph.VTR.AppendToBuffer(bb);
            glyph.VBL.AppendToBuffer(bb);
            glyph.VBL.AppendToBuffer(bb);
            glyph.VTR.AppendToBuffer(bb);
            glyph.VBR.AppendToBuffer(bb);
            emptyGlyphs.add(glyphs.get(i));
        }
        bb.flip();
        glyphs = null;

        // Set The Buffer Data
        glBindBuffer(BufferTarget.ArrayBuffer, vbo);
        if(gc > glyphCapacity) {
            glyphCapacity = gc * 2;
            glBufferData(
                    BufferTarget.ArrayBuffer,
                    (glyphCapacity * 6) * VertexSpriteBatch.Size,
                    bufUsage
                    );
        }
        glBufferSubData(BufferTarget.ArrayBuffer, 0, bb);
        GLBuffer.Unbind(BufferTarget.ArrayBuffer);
    }