【问题标题】:SDL_SetRenderDrawColor(255 , 0 , 0 , 255); not set continue open window in black color Using Visual Studio 10SDL_SetRenderDrawColor(255, 0, 0, 255);未设置继续以黑色打开窗口使用 Visual Studio 10
【发布时间】:2019-09-14 21:48:46
【问题描述】:

我刚刚使用了 SDL_SetRenderDrawColor(ren, 255,0,0,255);

对于 SDL_Rect rec 但未更改颜色,窗口使用 SDL_RenderPresent(ren) 以黑色呈现;

还需要使用什么吗?可能是 SDL_RenderCopy?

有人知道发生了什么吗?

#include "game.h"

Game::Game(){
    SDL_Init(0);
    SDL_CreateWindowAndRenderer(800, 600, 0, &win, &ren);
    SDL_SetWindowTitle(win, "Game-SDL2");
    running=true;
    count=0;
    loop();
}

Game::~Game(){
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(win);
    SDL_Quit();

}

void Game::loop(){
    while(running){

      lastFrame = SDL_GetTicks();
      int static lastTime;
      if (lastFrame >= (lastTime+1000))
      {
         lastTime=lastFrame;  
         frameCount=0;
         count++;
      }

      render();
      input();
      update();

      if (count > 3) running=false;

    }
}

void Game::render(){

    SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);
    SDL_Rect rect;
    rect.x, rect.y=0;
    rect.w=800;
    rect.h=600;
    SDL_RenderFillRect(ren, &rect);

    frameCount++;
    int timerFPS = SDL_GetTicks()-lastFrame;
    if (timerFPS > (1000/60)){
        SDL_Delay((1000/60)-timerFPS);
    }

        SDL_RenderPresent(ren, &rect);

}

【问题讨论】:

    标签: c++ sdl-2


    【解决方案1】:

    我只是说

    SDL_RenderClear(ren);

    并且工作???显示为红色,但我更改了矩形矩形的尺寸,如果窗口 800x600 始终为红色,则没有任何变化,但我认为正确的是将颜色设置为矩形而不是所有窗口

    可能还没有解决办法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 2011-07-09
      • 1970-01-01
      • 2018-03-30
      • 2012-04-21
      相关资源
      最近更新 更多