Sign in to follow this  
FlyingSolo

OpenGL OpenGL is too slow ...

Recommended Posts

FlyingSolo    117
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
cowsarenotevil    3005
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
Atrix256    539
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
FlyingSolo    117
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
FlyingSolo    117
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
Palidine    1315
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
Atrix256    539
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
Xai    1838
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
Palidine    1315
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
FlyingSolo    117
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
PlayerX    279
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
shwasasin    482
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
FlyingSolo    117
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  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now