运行循环故障时SDL。为什么if语句使SDL窗口无法正确呈现

时间:2018-03-02 03:49:17

标签: c++ sdl

如果if语句中的数字被改为小于40的程序,程序将开始正确渲染SDL窗口,有人知道为什么会发生这种情况吗?谢谢你的进步。

while(this->running) {
    SDL_PollEvent(&event);
    if(event.type == SDL_QUIT) {this->running = false;}

    currentTime = SDL_GetTicks();

    //changing the 40 on the if statement below
    //to any other number less than 30 
    //will make the program run correctly. I'm not sure why 
    //this is happening. help!!!
    if(currentTime > lastTime + 40) {
        SDL_UpdateTexture(
            this->texture,
            NULL,
            this->pixels,
            this->WIDTH * sizeof(Uint32)
        );

        for(int i = 0;i < HEIGHT;i++){
            for(int j = 0;j < WIDTH;j++){
                this->pixels[i*WIDTH + j] = DSDL_MapTanhToRGB(fmt,1000000/(pow(i-HEIGHT/2,2) + pow(j-WIDTH/2,2)+100*(int)loopCount+1));
            }
        }

        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, NULL, NULL);
        SDL_RenderPresent(renderer);

        //printf("Loop #: %d\n",loopCount);
    }

    lastTime = currentTime;
    loopCount++;
}

最终,我尝试使用if语句来降低每秒帧数,以便在其他地方使用cpu资源。

0 个答案:

没有答案