Comments (6)
After further investigation, it seems that high (100% or 25% for quad-cores) CPU usage is the expected behavior for most cases in OpenGL/Direct3D games, it mainly depends on graphics driver implementation. Game loop just keeps running all the time if not locked in any way. In GLFW3 is possible to glfwWaitEvents() instead of glfwPollEvent() so frame swap can be locked waiting for events and CPU usage falls to ~1% but that's not the desired behaviour in a game. Enabling VSYNC could have a similar effect but it also depends on graphics driver...
A couple of links with further info:
http://stackoverflow.com/questions/18365269/cpu-usage-is-high-when-using-opengl-control-class
http://gamedev.stackexchange.com/questions/19066/why-is-opengl-using-100-cpu-shortly-after-start-up-when-wglswapintervalext-is-e
from raylib.
Having an option in the lib API for vsync might help allot. When vendor drivers have trouble with vsync, the opengl software can make up for that and override the driver settings.
#ifdef _WIN32
// Turn on vertical screen sync under Windows.
// (I.e. it uses the WGL_EXT_swap_control extension)
typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int interval);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT)
wglSwapIntervalEXT(1);
#endif
from raylib.
GLFW already uses WGL_EXT_swap_control
extension to provide VSYNC (where this extension is available) but, again, it can be overriden by graphic driver, forcing on or off. Here it is further information on Swap Internal
:
https://www.opengl.org/wiki/Swap_Interval
But there is something I can do; I can expose GLFW VSYNC mechanism to raylib users through a flag, to be set before windows creation. That way users can try forcing VSYNC and wait for the driver to respond.
I'm working on it.
from raylib.
Thank you for the time and effort you have put into this.
from raylib.
Use function: SetConfigFlags(FLAG_VSYNC_HINT); // Use before InitWindow()
Underlying system, GLFW3, will try to enable vsync if graphic driver allows it.
Upcoming raylib v1.3 includes this change.
from raylib.
Issue corrected on commit b681e8c.
from raylib.
Related Issues (20)
- [rcore] `RenderTexture` looks wrong for a few frames after window init/resize HOT 3
- [raudio] Failing to load a MP3-File causes a double free HOT 5
- [rmodels] Support non-normalized GLTF vertex colors HOT 1
- [Zig] Zig build fails to compile HOT 1
- Broken links in `BINDINGS.md` HOT 7
- [raymath] Matrix multiply is backwards or the comment around Matrix struct is wrong. HOT 1
- [rcore] Previous gamepad button press isn't tracked on Android
- [raudio] Add a way to pass userdata into audio processors HOT 1
- [rcore_web] Relative mouse mode issues HOT 1
- [build] Obsolete apk file: raylib_game.signed.apk HOT 4
- Segmentation fault in rtextures.c HOT 1
- [rtextures] Segmentation fault at `LoadImageRaw()`, line 319 HOT 4
- [rlgl] Software renderer support? HOT 8
- [rcore_desktop] Upon entering fullscreen, uses original window size HOT 6
- [misc] Rename `Is*Ready()` to `Is*Valid()` HOT 34
- [rshapes] Off-by-one difference between DrawRectangleLinesEx and DrawLine/DrawLineV at drawing position. HOT 3
- [rmodels] Black GLB models HOT 6
- [build] Unable to build a Mach-O universal binary with 2 architectures when building from source HOT 3
- [Question] is Raylib compatible with smooth rendering ranging from 60 to 1. HOT 2
- WINBOOL not defined (clang) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raylib.