GlBegin gives lag.

I am Using this method to draw my tiles in my LWJGL game.

public static void DrawQuad(Texture tex, float x, float y, float width, float height) {
tex.bind();
glTranslatef( x - player.x, y - player.y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
glEnd();
glLoadIdentity();

	}

But using glBegin everytime I draw a tile gives a lot of lag. (I draw around 645 tiles per frame).
How can I prevent using glBegin so much times?

You can start by not using glBegin :stuck_out_tongue: :stuck_out_tongue: I estimate a 200% speed increase.

[sub][sub]Look into VBOs[/sub][/sub]

Switch from immediate mode rendering to retained mode rendering (vertex arrays, VBO/VAO, …).

Oops, it’s already what the tiny link in the previous post suggests.

But if you want to continue using the old immediate mode: you afterwards have to call glEnd() :wink: