【问题标题】:Mac OS OpenGL - problems with CPU usageMac OS OpenGL - CPU 使用问题
【发布时间】:2015-01-04 01:54:02
【问题描述】:


由于 Mavericks 更新(我现在在 10.10),调试窗口显示此消息:

“CGContextErase”功能已过时,将被删除 在即将到来的更新中。不幸的是,这个应用程序,或者一个库 它使用,正在使用这个过时的功能,并因此做出贡献 导致系统性能整体下降。

我正在创建一个用 C++ 编写的 OpenGL (SDL) 应用程序,现在由于我的应用程序(它使用 MacBook 的 Intel i5 处理器 100% 的功率),我的 CPU 内存出现问题。 所以,也许是因为所有这些 CGContextErase 函数。 我该如何解决? 好吧,也许我的代码有错误:

//I'm using the SDL2
#include <SDL2/SDL.h>

class sWindow {
public:
    SDL_Window *win;
    SDL_Surface *winSur;
    SDL_Event e;

    void createWindow(char*,int,int,int,int,Uint32);
    void update();
    void render();
    void close();

    SDL_Rect WIN_RECT;
    char WIN_TITLE = NULL;
    int WIN_ID = -1;
};

SDL_Rect newRect(int x, int y, int w, int h) {
    SDL_Rect returnRect;

    returnRect.x = x;
    returnRect.y = y;
    returnRect.w = w;
    returnRect.h = h;

    return returnRect;
}

//The window, where the content(surface) will be rendered.
sWindow win1;

//Window's construct
void sWindow::createWindow(char* title, int x, int y, int w, int h, Uint32 flags) {
    win = SDL_CreateWindow(title, x, y, w, h, flags);
    winSur = SDL_GetWindowSurface(win);

    WIN_RECT = newRect(x, y, w, h);
    WIN_ID = SDL_GetWindowID(win);
}

//The logic and render actions...
void sWindow::update() {

}

//Window's destructor
void sWindow::close() {
    SDL_DestroyWindow(win);
    SDL_FreeSurface(winSur);
}

//Main loop control
bool quit = false;

//Initilize the OpenGL and other libs(SDL2)
bool inited() {
    bool result = true;

    if (SDL_INIT_VIDEO <= 0) {
        result = false;
        printf("SDL_INIT_VIDEO Failed");
    }

    return result;
}

//Main loop...
int main(int argc, char* argv[]) {
    if (inited()) {
        win1.createWindow((char*)"SpaceCode", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 380, 280, SDL_WINDOW_SHOWN);
        while (!quit) {

            while (SDL_PollEvent(&win1.e) != 0) {
                if (win1.e.type == SDL_QUIT) {
                    quit = true;
                }
            }
        }
    }

    win1.close();
    SDL_Quit();
    return 0;
}

【问题讨论】:

    标签: c++ macos opengl sdl cpu


    【解决方案1】:

    此代码总是会导致 CPU 使用率过高,因为没有设置帧速率上限,因此它只会尝试尽可能快地处理它。

    请参阅下面的各种帖子:

    还有更多在 Google 上的搜索。

    【讨论】:

      【解决方案2】:

      我遇到了这个问题。这是由过时的 Wacom 数位板驱动程序引起的。如果您安装了这样的驱动程序,我建议您删除它,然后重新安装更新的驱动程序。这对我有用。

      【讨论】:

      • 请不要对多个问题发布相同的答案。发布一个好的答案,然后投票/标记以关闭其他问题作为重复问题。如果问题不是重复的,调整您对该问题的回答。
      • 良好的反馈。谢谢。会的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 2021-08-18
      • 2016-10-07
      • 2015-04-15
      相关资源
      最近更新 更多