PDA

View Full Version : Jumping/stuttering (probably lag)



Brad811
05-11-2012, 09:04 PM
I was previously using display lists to render, and am now using VBOs, and I'm getting the same problem.
I'm getting some jumping, as in for a frame or two everything stutters/jumps to the side (generally in the direction of motion). I'm wondering if this is a lag problem, but it seems to have gotten worse since switching to VBOs, which is the opposite of what I was expecting.


I'm also getting some horizontal lines. I'm drawing textures by using a 512px x 512px image divided into 16x16 tiles. I've tried to fix this by drawing 1.0f/16.001f of the texture instead of just 1.0f/16.0f, and this helps, but doesn't completely fix it. It looks like it's still drawing a little too much of the image (1 pixel to be exact) and in a long row of tiles this causes a very noticeable horizontal line.


Does anyone have any idea what could be causing these issues?


Thanks!

Here is the code I'm using to render about 1000 polygons per frame. I'd like to eventually be able to draw many more, but I need to fix these issues first.


public void render(float scaleX, float scaleY, float scaleZ)
{
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertex_buffer_data, GL15.GL_STATIC_DRAW);

GL11.glBindTexture(GL11.GL_TEXTURE_2D, GameApplet.getTilesTexture().getTextureID());

GL11.glVertexPointer(3, GL11.GL_FLOAT, 48, 0);
GL11.glNormalPointer(GL11.GL_FLOAT, 48, 12);
GL11.glColorPointer(4, GL11.GL_FLOAT, 48, 24);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 48, 40);

GL11.glScalef(scaleX, scaleY, scaleZ);
GL11.glDrawArrays(GL11.GL_QUADS, 0, vertex_data_array.length / 12);
}

BionicBytes
05-12-2012, 07:04 AM
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertex_buffer_data, GL15.GL_STATIC_DRAW);
So you are uploading new data to the VBO each frame? Does the size of the data array change each frame or always the same?
As for the texture issue - it sounds like your edges of the tiles are sampling the neighbours due to the bilinear filtering h/w. If you set the texture filtering to GL_NEAREST does the issue go away?

V-man
05-12-2012, 08:41 AM
If your VBO data is static, then don't call glBufferData.
If it is dynamic, there are some tricks to get better performance
http://www.opengl.org/wiki/VBO_-_more#Dynamic_VBO

Brad811
05-12-2012, 11:40 AM
Ah, ok thanks guys, that makes sense. I removed glBufferData call and unlimited the frame rate that got things from 104fps to 345fps. Looks very smooth at 60fps.


public void render(float scaleX, float scaleY, float scaleZ)
{
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, GameApplet.getTilesTexture().getTextureID());

GL11.glVertexPointer(3, GL11.GL_FLOAT, 48, 0);
GL11.glNormalPointer(GL11.GL_FLOAT, 48, 12);
GL11.glColorPointer(4, GL11.GL_FLOAT, 48, 24);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 48, 40);

GL11.glScalef(scaleX, scaleY, scaleZ);
GL11.glDrawArrays(GL11.GL_QUADS, 0, vertex_data_array.length / 12);
}


As for the textures, I have them set like so:


GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);


If I put them on linear, they look pretty bad, and have lines on all sides from their surrounding areas in the png. On nearest, it seems like only at certain distances from the camera they have black lines (so only one or two rows of tiles have black lines on their botton at a time, and only at a couple of distances).
I was going to say it sounded like a rounding error, but I don't have any black lines on my texture png, so I'm not sure where it would be getting it from.

--EDIT--
Here is my test texture which is 512x512:
716
Which is divided up into 16ths so each tile will have the texture:
717
And here is the result:
718

--EDIT 2--
Upon further investigation, this black line is actually the clear/background color showing through. That means that every once in a while the tiles are rendered as not touching. What can I do to fix this?