• Advertisement
Sign in to follow this  

OpenGL OpenGL is too slow ...

This topic is 3021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By LifeArtist
      Good Evening,
      I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
      First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
      I am really stucked right now because of the fundamental question:
      Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
      If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on. 
      In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
      Should I treat those debug objects as entities/components?
      For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
      Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
      Regards,
      LifeArtist
    • By QQemka
      Hello. I am coding a small thingy in my spare time. All i want to achieve is to load a heightmap (as the lowest possible walking terrain), some static meshes (elements of the environment) and a dynamic character (meaning i can move, collide with heightmap/static meshes and hold a varying item in a hand ). Got a bunch of questions, or rather problems i can't find solution to myself. Nearly all are deal with graphics/gpu, not the coding part. My c++ is on high enough level.
      Let's go:
      Heightmap - i obviously want it to be textured, size is hardcoded to 256x256 squares. I can't have one huge texture stretched over entire terrain cause every pixel would be enormous. Thats why i decided to use 2 specified textures. First will be a tileset consisting of 16 square tiles (u v range from 0 to 0.25 for first tile and so on) and second a 256x256 buffer with 0-15 value representing index of the tile from tileset for every heigtmap square. Problem is, how do i blend the edges nicely and make some computationally cheap changes so its not obvious there are only 16 tiles? Is it possible to generate such terrain with some existing program?
      Collisions - i want to use bounding sphere and aabb. But should i store them for a model or entity instance? Meaning i have 20 same trees spawned using the same tree model, but every entity got its own transformation (position, scale etc). Storing collision component per instance grats faster access + is precalculated and transformed (takes additional memory, but who cares?), so i stick with this, right? What should i do if object is dynamically rotated? The aabb is no longer aligned and calculating per vertex min/max everytime object rotates/scales is pretty expensive, right?
      Drawing aabb - problem similar to above (storing aabb data per instance or model). This time in my opinion per model is enough since every instance also does not have own vertex buffer but uses the shared one (so 20 trees share reference to one tree model). So rendering aabb is about taking the model's aabb, transforming with instance matrix and voila. What about aabb vertex buffer (this is more of a cosmetic question, just curious, bumped onto it in time of writing this). Is it better to make it as 8 points and index buffer (12 lines), or only 2 vertices with min/max x/y/z and having the shaders dynamically generate 6 other vertices and draw the box? Or maybe there should be just ONE 1x1x1 cube box template moved/scaled per entity?
      What if one model got a diffuse texture and a normal map, and other has only diffuse? Should i pass some bool flag to shader with that info, or just assume that my game supports only diffuse maps without fancy stuff?
      There were several more but i forgot/solved them at time of writing
      Thanks in advance
    • By RenanRR
      Hi All,
      I'm reading the tutorials from learnOpengl site (nice site) and I'm having a question on the camera (https://learnopengl.com/Getting-started/Camera).
      I always saw the camera being manipulated with the lookat, but in tutorial I saw the camera being changed through the MVP arrays, which do not seem to be camera, but rather the scene that changes:
      Vertex Shader:
      #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); TexCoord = vec2(aTexCoord.x, aTexCoord.y); } then, the matrix manipulated:
      ..... glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); ourShader.setMat4("projection", projection); .... glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp); ourShader.setMat4("view", view); .... model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); ourShader.setMat4("model", model);  
      So, some doubts:
      - Why use it like that?
      - Is it okay to manipulate the camera that way?
      -in this way, are not the vertex's positions that changes instead of the camera?
      - I need to pass MVP to all shaders of object in my scenes ?
       
      What it seems, is that the camera stands still and the scenery that changes...
      it's right?
       
       
      Thank you
       
    • By dpadam450
      Sampling a floating point texture where the alpha channel holds 4-bytes of packed data into the float. I don't know how to cast the raw memory to treat it as an integer so I can perform bit-shifting operations.

      int rgbValue = int(textureSample.w);//4 bytes of data packed as color
      // algorithm might not be correct and endianness might need switching.
      vec3 extractedData = vec3(  rgbValue & 0xFF000000,  (rgbValue << 8) & 0xFF000000, (rgbValue << 16) & 0xFF000000);
      extractedData /= 255.0f;
    • By Devashish Khandelwal
      While writing a simple renderer using OpenGL, I faced an issue with the glGetUniformLocation function. For some reason, the location is coming to be -1.
      Anyone has any idea .. what should I do?
  • Advertisement