This paper presents an effective algorithm for occlusion culling using hardware occlusion queries. The number of queries is optimized according to the results of the queries from several preceding frames. Parts of the scene which are found to be unoccluded in recent frames, are tested less often thus reducing the number of queries performed per frame. The algorithm is applicable to any kind of scene, including scenes with moving objects. The algorithm utilizes a tree structure containing objects in the scene.