找不到SDL2 / SDL.H文件

时间:2019-11-09 09:51:59

标签: c++ xcode macos

我正在YouTube上关注此教程: https://www.youtube.com/watch?v=44tO977slsU

,他链接了一个有关如何安装SDL2的视频,我关注了该视频,并且也关注了该视频。但是,当我编译它时,总会找不到SDL2 / SDL吗?我不确定该如何解决

到目前为止,这是我的代码 MAIN.CPP

#include "Game.hpp"

Game *game =nullptr;

int main(int argc, const char * argv[]) {

    game = new Game();

    game->init("Nijigen-Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);

    while (game->running()) {

        game->handleEvents();
        game->update();
        game->render();
    }

    game->clean();

    return 0;
}

Game.cpp

#include "Game.hpp"

Game::Game()
{}
Game::~Game()
{}

void Game::init(const char *title, int xpos, int ypos, int width, int height, bool fullscreen)
{

    int flags = 0;
    if(fullscreen)
    {
        flags = SDL_WINDOW_FULLSCREEN;
    }

    if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
    {
        std::cout << "Subsystems Initiated!..." << std::endl;

        window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
        if(window)
        {
            std::cout << "Window Created!..." << std::endl;
        }

        renderer = SDL_CreateRenderer(window, -1, 0);
        if(renderer)
        {
            SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
            std::cout << "Renderer Created!..." << std::endl;
        }

        isRunning = true;
    } else {
        isRunning = false;
    }
}

void Game::handleEvents()
{
    SDL_Event event;
    SDL_PollEvent(&event);
    switch (event.type) {
        case SDL_QUIT:
            isRunning = false;
            break;

        default:
            break;
    }
}

void Game::update()
{}

void Game::render()
{
    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);
}

void Game::clean()
{
    SDL_DestroyWindow(window);
    SDL_DestroyRenderer(renderer);
    SDL_Quit();
    std::cout << "Game Cleaned" << std::endl;

}

**和Game.hpp **


#ifndef Game_hpp
#define Game_hpp
#include "SDL2/SDL.h"
#include <iostream>

class Game {

public:
    Game();
    ~Game();

    void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);

    void handleEvents();
    void update();
    void render();
    void clean();

    bool running() { return isRunning; }


private:
    bool isRunning;
    SDL_Window *window;
    SDL_Renderer *renderer;
};

#endif /* Game_hpp */

0 个答案:

没有答案