gpt4 book ai didi

c++ - Mac OS OpenGL - CPU 使用问题

转载 作者:行者123 更新时间:2023-11-28 06:35:50 27 4
gpt4 key购买 nike


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

The function ‘CGContextErase’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.

我正在创建一个 OpenGL (SDL) 应用程序,它是用 C++ 编写的,现在由于我的应用程序(它使用 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;
}

最佳答案

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

查看下面的各种帖子:

还有更多在 Google 上的搜索。

关于c++ - Mac OS OpenGL - CPU 使用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26798438/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com