I'm pretty new to all this LWJGL stuff and have been having a problem for the last week or so with lag spikes in my tiny 2D game engine (if I can even call it that). From what I could gather the lag spikes always happen inside my render function, but I'm uncertain what is really causing the lag.
public void render(){
shader.setUniform(texcoord.getMatrix(),UNIFORM_TEXCOORD); // Texture cordinates inside a matrix
shader.setUniform(transform.getMatrix(),UNIFORM_MODELVIEW); // Position of the object in the world
glBindTexture(GL_TEXTURE_2D, ID);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0,2,GL_FLOAT,false,8,0L);
glDrawArrays(GL_TRIANGLES, 0, SIZE);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
I've read on the forums before that it could be because of a garbage collection, but I can't seem to find anything in my render function that would create garbage.
This is also how I create the vbo if it is by any help. I'm just initializing this code once and using the same vbo for all the textures.
vbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER,Util.createFlippedBuffer(new float[]{0.0f,0.0f, 0.0f,1.0f, 1.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f}),GL_STATIC_DRAW); // createFlippedBuffer just puts the values in a FloatBuffer
glBindBuffer(GL_ARRAY_BUFFER,0);
If you need any more information just ask.
Thanks for any help.