Sign in to follow this  
FlyingSolo

OpenGL OpenGL is too slow ...

Recommended Posts

I'm puzzled. Very puzzled in fact. I'm a newcomer to OpenGL (good, isn't it!) and have been using various online references and tutorials including videotutorialsrock.com and our own beloved NeHe. Many of the example programs that accompany these tutorials don't do a great deal, but are not timer driven - they are running flat out. What gives? An OpenGL program rotating a small quad or triangle surely should be a blur if in a loop with nothing else going on ? My own code, basic though it is so far, certainly isn't showing any lightning qualities despite doing very very little. How are people writing hugely complex apps like flight/racing simulators which have extremely rapid full-screen graphics movement? I'm Puzzled. Would love to hear comments from the more experienced out there.

Share this post


Link to post
Share on other sites
My guess is that vsync is limiting your framerate. Vsync is an option available on most video hardware that limits the framerate to the monitor's refresh rate. This prevents wasted frames being generated that would never be displayed by the monitor and it also prevents "tearing" that occurs when a frame changes in the middle of a refresh.

Share this post


Link to post
Share on other sites
Just to add specifics to what others said...

If your FPS is stuck at 60 or 80 fps, that means vsync is limiting your FPS to prevent tearing (:

If that's the case, ignore it or figure out how to turn off vsync on your computer (you can do it in code, and sometimes you can do it via driver settings) if you want to see the true fps.

If that isn't the case, how much FPS are you getting?

Share this post


Link to post
Share on other sites
If it's time based movement (which I think most of nehe's stuff is) it'll rotate at the same speed no matter what the framerate is

-me

Share this post


Link to post
Share on other sites
Sorry chaps: Windows XP(Pro), loadsa RAM, nVidia 9600GT (512MB)
Compiler: MS Visual C (Express). Latest nVidia Drivers.
I know my system is happy since I'm getting very good frame rates from X-Plane, my favourite OpenGL app.

Frame rates for NeHe's 'example04' are about 20-30 with Vsync enabled, and very f.quick if it isn't. Surely vsync shouldn't make _that_ much of an impact?

Is it normal for a graphic intensive (ie: game/simulation) OpenGl prog to force the Vsync to off?

the only alternative would be to use larger steps in the animation - icky icky.

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
If it's time based movement (which I think most of nehe's stuff is) it'll rotate at the same speed no matter what the framerate is


Check out Example 4 - not a timer to be seen.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=04

Share this post


Link to post
Share on other sites
Quote:
Original post by FlyingSolo
Quote:
Original post by Palidine
If it's time based movement (which I think most of nehe's stuff is) it'll rotate at the same speed no matter what the framerate is


Check out Example 4 - not a timer to be seen.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=04


Yep. But it's definitely not disabling vsync so there's your reason.

[EDIT: and before you ask this is why vsync is default to on: http://en.wikipedia.org/wiki/Page_tearing]

-me

Share this post


Link to post
Share on other sites
Paladine, he said hes getting 20-30 fps. If it is vsync he should be getting 60 (or 80 or whatever his montior refreshes at).

20-30 seems to indicate he should update his video drivers dont you think?

Share this post


Link to post
Share on other sites
You understand that your actual screen is only refreshed a maximum number of times per second (usually 60-85 depending on settings with 60 being more common than all other settings combined).

Secondly you should therefore understand that this rate is the absolute maximum desirable framerate for any purpose whatsoever (so if your monitor is set to 60Hz, you want a game framerate of exactly 60 at all times for visual perfection).

Third you should recall that motion pictures use a framerate of 24 FPS (real motion pictures in a real theatre, because about 100 years ago early motion picture people found that while 18 FPS is enough to look "right" to the large majority of viewers, some people are bothered by flickers smaller than about 20 FPS, but less than 1% of all people can perceive the difference between 24 Hz and 30Hz when viewing a screen directly).

Fourth you should recall that until VERY recently (2-3 years) HI-DEF TVs supported a max of either 30 Hz progressive scan, or 60 Hz interlaced (drawing half the screen each 1/60th of a second). Now they have a mode that is 60 Hz progressive scan, which allows the consumer to not have to choose ... but realize we are talking about the TV set itself here, not the source material. Almost all HD-DVD and Blue Ray is mastered with a 30 Hz data rate ... so no matter what you own or view it on, there are a max of 30 updates per second.

Fifth, search for an article about the new ratchet and clank (PS3) game that used a 60 FPS goal framerate (one of the only games to do so on a console ever) ... and see that the producer intends to never do it again (instead he will target 30 FPS with richer graphics).

But still, on your rig you should be getting near 60 FPS.

But understand that with V-Sync on, each time the computer fails to update a frame in 1 cycle the framerate would drop 1 of those 60 and if this we're because of the system being just a little too slow you would experience 30 FPS numbers. If the system is sometimes too slow to update a scene in 2 frames, it would use 3, which if common would yield 20 FPS.

None of these slower framerates are a problem at all, in fact for non-twitch gaming all that is beneficial is to stay above about 20 FPS.

But there is a reason some games "need" or benifit from higher framerates ... its latency or lag. Most game engines run the screen 2-3 frames behind what the game is actually doing (for instance while the user is seeing frame X and making input choices (which will take the user some time to complete), the game has already drawn frame X+1, and is now drawing frame X+2). So if the game is using 30 FPS (0.033 seconds per frame) then the lag from when they push a button to when they see it on the screen is between 2/30 and 3/30 of a second ... but if the framerate was at 60 FPS, the lag time would be half of that (best case) ...

In the real world though, the user cannot respond to stimulus instantly, so the game creates a situation (an enemy in from of them), the users sees this in 2-3 frames (lets say 3 for worst case example) - 100 ms ... they push the mouse fire button some time later (180-200 msec milliseconds is average best-case reaction ability of humans to visual stimulus). So 300 ms after the game has put the enemy in front of them, it processes a "fire" command. Now if another user's computer had 60 FPS the lag would have been 250ms, so they have a 50 ms advantage ... which is meaningless for an RTS or most RPGs, but for twich FPS games 50 ms lag difference can matter.

Also, I didn't mention it yet, but the alternative to V-Sync is to have the game engine run faster than the screen, and have visual "tearing" where the screen is drawing part of the screen at 1 frame (say X), then while drawing it switches to the next frame (X+1) and maybe before the end even switches again (X+2) .... so in that case the lower regions of the screen are newer than the higher ones (and this can be seen as visual disconnects where the switch happened) ... so the screen is uglier, but lag is reduced somewhat.

Share this post


Link to post
Share on other sites
Quote:
Original post by Atrix256
Paladine, he said hes getting 20-30 fps. If it is vsync he should be getting 60 (or 80 or whatever his montior refreshes at).

20-30 seems to indicate he should update his video drivers dont you think?


Yes. I missed that part. Video drivers are a good idea. He should def be near 60. As an experiment it'd be worthwhile turning off vsync and seeing what the FPS is ([google])

-me

Share this post


Link to post
Share on other sites
Cor, Xai - what a cracking response!

Vsync is most definitely the answer to what I _perceived_ to be a speed problem.

I think the problem lies in my having been a bit-blaster for so long where my code could whistle along as fast as the processor would let it and the video system would update the image as and when it was ready. This means of course that I was rendering 'scenes' that never got displayed.

I agree with all your factoids Xai, the human eye is very easily fooled - luckily.

A little googling advises me that unless absolutely positively necessary, leave Vsync on to maintain displayed image integrity and avoid tearing.

I compiled NeHe's Lesson4 on my own machine and the fps appears to match my monitor refresh.

Tell you what, bit-blasting is a helluva lot easier, but OpenGL looks sooooo much nicer!

Thanks for setting me straight guys. Appreciate it.

Share this post


Link to post
Share on other sites
Actually there is a reason not to have VSync enabled sometimes. If your application is spending longer than one frame to produce its output then it has to wait for the end of the next frame before it can be displayed (with double-buffering). So every time you miss that frame your effective frame rate drops down to 30fps. This can be noticeable in-game as a loss in fluidity, especially if you're just missing the frame occasionally.

It depends on what you find worse, occasional tearing or stutters. :-)

Share this post


Link to post
Share on other sites
While I can't speak specifically about the tutorials you're reading, here's a few tips about OpenGL programming which can make a huge performance improvement.

- Coding - Many tutorials use immediate mode rendering glBegin/glEnd because it's quick to get things up and running, but unfortunately does not provide the greatest performance. You should read about Vertex Buffer Objects (think Vertex Buffers in D3D), Vertex Arrays (older method of buffered data rendering), and Display Lists.

- Tools - Make sure you are running the latest versions of your Compiler (i.e. Visual C++ Express Edition 2008), libraries (e.g. OpenGL Extension Wrangler or GLEW), and you're operating system to ensure proper compatibility

- Drivers - Make sure you have hardware that supports OpenGL (i.e. NVidia, ATI cards) and the latest drivers from your vendor. Some companies will ship stock (reference) drivers with their hardware which could be really old and may not be fully optimized for said features. Although Intel and others make video cards, their drivers/cards are known to have problems with OpenGL.

Anyways, that's just a few quick things off the top of my head that can affect OpenGL performance. Good luck with everything.

Share this post


Link to post
Share on other sites
All great advice folks, and very much appreciated.

Isn't triple-buffering at the discretion of the hardware though?

I'm trying to keep my app's very cross-platform compatible so I don't want (and shouldn't need) to do anything too gnarly.

Again, my thanks to all :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627770
    • Total Posts
      2979002
  • Similar Content

    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
  • Popular Now