Basic performance tips.

Started by
43 comments, last by wyrd 19 years, 10 months ago
I was wondering if someone could give me some basic performance tips on how to improve performance in a 2D game. I'm using Quads and Textures built with Display Lists (for each frame in an animation). The performance is decent I suppose, 2,500 draws per frame at 30 fps in windowed mode (my comp specs are g2, 256mb ram, 800mhz athlon). I tried using vertex and texcoord arrays instead of draw lists, no performance was gained. So I'm curious, is there any way to speed this up? Perhaps using triangles would be faster? (although that would require twice the amount of triangles compared to quads, 2 triangles per quad). What about Vertex Buffers? I heard you can enable them using extensions, or gain other improvements using extensions. Anyone have a link that shows how? Thanks in advance.
Advertisement
Hi there !

You should use Triangle Strips. They are very fast (if you find it too complicated, use triangles, not quads because graphics card are optimized to use triangles).

About Vertex Buffer Objects, you should take a look at this excellent tutorial : Nehe's Lesson 46.

Hope it helps !
- Artist on the web -- Lwjgl Ressources & blog -
Your performance sucks (for such a small number of polys and such a powerful computer).

Some ideas:
1. Try making the textures smaller (I guess they are too big).
2. Disable the Vsync (if enabled) since you can't actually test the performance with Vsync on.
3. Profile your code.
4. Find out what your bottleneck is (CPU, fillrate, or geometry).
Chman: I'll look into triangle strips. Thanks for the link to the vertex buffers.

Raduprv:
1. I should of mentioned the quads are only 32x32. I tried changing the texture size in memory, that had no effect. Maybe I could try 16x16, but I have a feeling that it won't help much.
2, 3, 4. I'm fairly new to game programming so I have no clue how to do what you just mentioned. :) The most complicated game I've ever made was using GDI and it was a space ship you flew around in space and attacked/killed other enemy ships. If you can provide any links on vsync, profiling, fillrate/geomatry issues, I'd be very greatful.

Thanks for your help guys. I think the first thing I'll do is try the triangle strips and check into vertex buffers as it's something I'm probably more capable of doing.
Triangle strips won't really make a difference unless you are geometry limited. In your case (2.5K) I don't think this is what limits the FPS.
To disable the Vsync, right click on desktop, go to the Nvidia properties thingy, and it has an option somewhere to disable it.
To profile your code, I don't know how to do that, I assume you use VC, and I never used it.
If you use DevC++ I can teach you how.
To determine what slows you down, well, that's hard. Try to increase the texture size to 256x256
See if the game is slower. If it isn't, then you are not fill rate limited.
im 99% tri_strips/display lists/vertex arrays etcwont make it much quicker (ie less than 1%)
to test if this is correct make the window small eg 320x240 if the framerate goes up then youre fillrate limited and tri_strips/display lists/vertex arrays etc aint really gonna help. u will have to look into otherways
eg lesser quality textures/mipmapping/less overdraw etc.
ie try to draw as less as possible and try to keep the drawing operations as simple as possible
Okay I did the Vertex Buffers. At first it seemed like it was a huge performance gain (ie; I was getting some 500+ frames per second for drawing one sprite, whereas before I was only getting like 60 max). But I noticed as I starting the increase the amount of sprites drawn, the performance severely degraded as it kept going. I got good horrible performance (worse than just using display lists) at 2,5000 sprite draws.

For testing I just loaded a single texture and single vertex buffer of a single quad, and drew it over and over again. The area being drawn was 32x32, same as before.

Perhaps there's just no hope of increasing performance on my system?
VBO are NOT for small quads. Neither are the display lists or vertex arrays. Those things are for many polys rendered at once.
Anyway, post a screenshot of your application.
Hmm.. so should I just draw 'em in immediate mode then? Or come up with some sort of routine that keeps track of all objects drawn in a single frame, then combines them into a single VB?

As for the screenshot, no need for one. It's a blank window with a single 32x32 image in the middle of it, which is drawn 2500 times on top of itself.
sorry to come in this thread, but i am having the same problem!!! im only drawing about 410 quads each frame, yet my framerate SUCKS on lower systems!!! im using glvertex2f to draw all my quads (mostly just filling the screen with tiles , around 400 tiles)

i was told to use vertex arrays / texture coord arrays. so is it true then this wont improve performance? like i said, im drawing the screen full of tiles which is around 400 32x32 quads each frame, plus maybe a few extra quads for enemies / players / bullets (more then a "few" i guess) / etc.

thanks for any help!!

ps- i profiled my code, and ~50% of the game is spent drawing my screen full of tiles....
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement