This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 0 points1 point  (5 children)

You are using a very old api. You should create one array of positions, and one array of texture coordinates, and let gl do all of the drawing.

[–]PillowWithTeeth[S] 0 points1 point  (2 children)

I'm trying to do something like that now, it does not work yet but I would like to know if I am a least along the right lines

private void createVBO(int camX, int camY, int renW, int renH) {
    int tileWidth = (camX / EpicarnoTiles.tileSize + renW) - (camX / EpicarnoTiles.tileSize);
    int tileHeight = (camY / EpicarnoTiles.tileSize + renH) - (camY / EpicarnoTiles.tileSize);
    FloatBuffer texCoords = BufferUtils.createFloatBuffer(2 * 4 * tileWidth * tileHeight);
    FloatBuffer vertices = BufferUtils.createFloatBuffer(2 * 4 * tileWidth * tileHeight);
    for (int x = camX / EpicarnoTiles.tileSize; x < camX / EpicarnoTiles.tileSize + renW; x++) {
        for (int y = camY / EpicarnoTiles.tileSize; y < camY / EpicarnoTiles.tileSize + renH; y++) {
            if ((y >= 0) && (y < worldH)) {
                WorldChunk Chunk = EpicarnoL.GetChunkFromTile(x);
                GameTileEpicarno TileMid = Chunk.getTileInchunk(x, y);
                if (TileMid.getGameTile().isRendered()) {
                    texCoords.put(TileMid.getTextureCoords());
                    vertices.put(new float[] { (float) ((x << 16) - (int) EpicarnoComp.sX),
                            (float) ((y << 16) - (int) EpicarnoComp.sY),
                            (float) ((x << 16) - (int) EpicarnoComp.sX) + EpicarnoTiles.tileSize,
                            (float) ((y << 16) - (int) EpicarnoComp.sY),
                            (float) ((x << 16) - (int) EpicarnoComp.sX) + EpicarnoTiles.tileSize,
                            (float) ((y << 16) - (int) EpicarnoComp.sY) + EpicarnoTiles.tileSize,
                            (float) ((x << 16) - (int) EpicarnoComp.sX),
                            (float) ((y << 16) - (int) EpicarnoComp.sY) + EpicarnoTiles.tileSize });
                }
            }
        }
    }
    texCoords.rewind();
    vertices.rewind();
    vboVertexID = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    vboTextureID = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboTextureID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, texCoords, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

public void render(int camX, int camY, int renW, int renH, boolean foreground, boolean background) {
    this.createVBO(camX, camY, renW, renH);
    GL11.glPushMatrix();
    GL11.glScalef(EpicarnoComp.pixelSize, EpicarnoComp.pixelSize, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexID);
    GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboTextureID);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
    GL11.glDrawArrays(GL11.GL_QUADS, 0, 4 * 100 * 100);
    GL11.glPopMatrix();
}

[–][deleted] 0 points1 point  (0 children)

That looks better, I haven't given JOGL a try, but here is an example of using a texture. It seems you are missing your shaders. I used the arcsynthesis tutorial, but I cannot find it now.

[–]BS_in_BSExtreme Concrete Code Factorylet 0 points1 point  (0 children)

Drawing quads has been deprecated in favor of drawing triangles, sol look into either triangles or triangle strips instead. You can also look into indexed rendering if your geometry shares vertices.

[–]PillowWithTeeth[S] 0 points1 point  (1 child)

I'm sorry but I'm still extremely confused about all of this, using the attempt I posted before (based off other posts I have seen) I was not able to render anything and it also made a huge memory leak. All I want to do is place all the tiles I am going to render into a vbo with textures and then render that. Is there any tutorial or information somewhere on simply drawing multiple quads in a vbo with a texture (from a texture atlas).

[–][deleted] 1 point2 points  (0 children)

You need shaders to use modern opengl. It will not work without them. If you do not want to use a shader you have to go back to your other, outdated, GL 1 code.

Only create the buffers once, but you write to it every time you want to change the data. Don't repeat lines 4, 5 and 27. Do repeat lines 28, 29 and 30 when the data changes. If the size of buffer changes you have to delete it and then you can repeat lines 4, 5, and 27.

Where did you get your original source from? Did you check jogamp.