ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm making a racing game with openGL, but real-time updated reflections make it really slow. On the same computer, NFS underground seems to do exactly the same thing much faster. I don't think it can be the difference between directX and openGL, because ATI also provides good openGL support for my Radeon 9200 card, and DirectX 8+ and openGL aren't that much different. Of course it could be my code that's inefficient, but I don't think that that is the case, because of this:
Reflections are done by applying a texture to an object that describes its environment (the "environment map"). To update the environment map, you need to render the scene from the point of view of the object 6 times (left, right, top etc.), and put the results in the environment map. So after every rendering step you need at least one glCopyTexImage2D call to put the result in a texture. I've measured that these calls take approximately 2 ms, so it takes at least 6x2 = 12 ms to update a reflection.
Let's say that 25 fps is reasonable. That gives us 1/25 = 0.04 s = 40 ms for every frame. So with 12 ms per reflection, you can only update 3 reflections per frame. In reality it will be even worse, because you also need to render the scene 1 time + 6 times per reflection. But in a game like NFS underground I can see many cars and even the road having reflections, while the frame rate is still good. So how is that possible?
I haven't done much with cubical environment maps, which is what I am assuming you are using since you said you render the scene 6 times from different view, but there are a couple things you might be able to try.
First, you could try to use glCopyTexSubImage2D instead of glCopyTexImage2D. I believe that glCopyTExSubImage2D is generally a bit faster.
Second, when rendering for your environment map, you can try to use some tricks to make those renders go faster. Maybe turn off lighting for those, render into as small an area as possible, etc...
Third, if that none of that works, you could try and fall back to normal environment mapping, which only uses a single distorted texture instead of 6 textures from different directions...
I briefly looked at the link that was posted. If you just are just reflecting off of a plane (like a mirror), that method should work pretty well. If you are trying to make an irregularly shaped object reflect its environment, environment mapping will probably give you a better result.
I already did a lot of these things. Turn out lighting, depth testing, blending etc.
BTW currently I'm using sphere mapping, but for updating your sphere map you still need several rendering steps. In the future, when I'm going to support cube mapping, I'll be able to skip the final compilation of the sphere map, but that's not the thing that takes most of the time.
I know about the option to use a "static" environment map, but that's not what I'm talking about. I know that environment maps in NFS are dynamic (at least for cars close to the camera).
Thanks for the glCopyTexSubImage2D hint, I'll try it. Why would it be faster than glCopyTexImage2D?
I know very little about OpenGL, so I guess my words are light on the subject. But maybe you can change the Field Of View to render all sides of your "box" at one time? And then develop a static alorithm that transforms the result image into 6 images (abit streched and such, but might work?). Im thinking of gluPerspective. Im guessing you already do this when you use Spheric mapping, but from what I see you only need one render.
Originally posted by cjp Thanks for the glCopyTexSubImage2D hint, I'll try it. Why would it be faster than glCopyTexImage2D?
That I'm not exactly sure of myself. I seem to remember people recommending that on the OpenGL forums a lot, though. BTW, if you don't get a satisfactory answer here, there are a lot of very knowledgeable people over at the opengl.org forums.
I tried glCopyTexSubImage2D, and it really works. On my system, it takes 0,41 ms on average, compared to 2 ms for glCopyTexImage2D. Now I should only optimise the rendering of the scene, which is still 1,5 ms, but that's my problem