So I was continuing on my game made in LWJGL, and I am able to move a player around on a grass background. The only problem I am having is being able to update the player correctly by getting rid of the older player positions.If i call:

1

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

then the grass background disappears and the player updates fine. I can't redraw the grass background every time I update, because the FPS will drop down to about 1 - 3. If there is a way that I can just clear the layer that the player is on, then I would greatly appreciate it.

I can't redraw the grass background every time I update, because the FPS will drop down to about 1 - 3.

Then you're doing something very wrong in drawing the grass. You should be able to draw everything visible in every frame and still sustain high framerates. Maybe if you pasted the relevant rendering code?

You should be able to render thousands (if not tens of thousands) of small (e.g. 32x32) tiles easily to the screen every frame.

A) How many tiles are you rendering per frame?B) How are you drawing the grass tiles?

Show us the code and we can help.

Some ways of speeding up rendering:- Batch your texture binds. If you are binding a new texture each tile, then you're going to run into performance problems. To minimize texture binds, merge various tiles (grass, wood, dirt, water, etc) into the same "sprite sheet" or texture atlas.- If you are using immediate mode (glBegin/glEnd), you can speed up tile rendering by calling glBegin only once before your nested loop, and glEnd only once after your loop (assuming all tiles use the same texture and you aren't doing any weird glTranslate/glRotate/etc. in between)- Learn to write your own vertex array renderer to further speed up sprite rendernig- If the tiles cover the entire screen, then you don't need to call glClear (assuming you are rendering all tiles every frame). This will speed things up slightly.

You should be able to render thousands (if not tens of thousands) of small (e.g. 32x32) tiles easily to the screen every frame.

A) How many tiles are you rendering per frame?B) How are you drawing the grass tiles?

Show us the code and we can help.

Some ways of speeding up rendering:- Batch your texture binds. If you are binding a new texture each tile, then you're going to run into performance problems. To minimize texture binds, merge various tiles (grass, wood, dirt, water, etc) into the same "sprite sheet" or texture atlas.- If you are using immediate mode (glBegin/glEnd), you can speed up tile rendering by calling glBegin only once before your nested loop, and glEnd only once after your loop (assuming all tiles use the same texture and you aren't doing any weird glTranslate/glRotate/etc. in between)- Learn to write your own vertex array renderer to further speed up sprite rendernig- If the tiles cover the entire screen, then you don't need to call glClear (assuming you are rendering all tiles every frame). This will speed things up slightly.

Indeed, OP is doing something very wrong. Just take a look at what's possible.

I bet that OP is drawing tiles using glBegin and glEnd. This is insanely slow since your CPU can't feed data fast enough to your GPU. You really need to draw tiles in batches instead of one by one. Since you can't switch textures while drawing tiles you need to have your tiles in a tile map, e.g. a single texture containing all tiles and then pick out tiles using texture coordinates. The easiest way of doing this is with display lists. They're very easy to use. You simply wrap your glBegin/glEnd code in a display list, and then you can draw everything in the display list with a single draw call later without the CPU overhead of glBegin, glEnd, glVertex, e.t.c. Simply doing this should give you perfectly fine performance

I'm not so sure about not calling glClear each frame though. glClear isn't simply a fullscreen quad with a certain color; it's first of all much much faster and secondly might improve performance in other ways. With some pixel modes (mostly multisampled modes) the color/depth/stencil/e.t.c buffers are often compressed to reduce memory usage and more importantly memory bandwidth which can lead to a small performance win. When glClear is called, it resets the compression blocks which is both very and improves performance for subsequent rendering. On a much more advanced level, glClear also signals that frame data will not be reused in multi-GPU setups, which allows the driver to remove the copy between GPUs, but this is of course completely irrelevant in in this case. The point is that the performance cost of glClear is ridiculously low and literally zero if the game is CPU bound, which is OPs case and the case for pretty much every 2D game out there, while there are potential benefits of it. It's better to just make a habit of clearing the screen each frame.

What I want is some way not to clear the loop drawing the grass, and still being able to clear the player images and then draw it in a new position.Some command that would be nice is: glClear(oldPlayerDrawing);And then draw the new player.

Well, I tried rendering the grass every frame and this time it worked without a big fps drop. I don't know why it worked this time but I'm happy. Perhaps I forgot to remove another piece of code when I was testing it before. This is the code I've ended up with:

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org