您好我正在关注SDL教程,但是当我尝试运行该程序时,我收到此错误:
The program can't start because SDL2.dll is missing from your computer. Try reinstalling the program to fix this problem
这个问题的其他答案都没有帮助我。我尝试将SDL2.dll文件放在Debug文件夹中,该文件夹包含.exe文件,项目根文件夹和带有.cpp文件的文件夹
我不认为我的代码对这个问题很重要,但无论如何它都在这里。
的main.cpp
#include "MainGame.h"
#include <iostream>
int main(int argc, char ** argv)
{
MainGame mainGame;
mainGame.run();
return 0;
}
MainGame.h
#pragma once
#include <SDL.h>
#include <GL/glew.h>
enum class GameState {PLAY, EXIT};
class MainGame
{
public:
MainGame();
~MainGame();
void run();
private:
void initSystems();
void gameLoop();
void processInput();
void drawGame();
SDL_Window * _window;
int _screenWidth;
int _screenHeight;
GameState _gameState;
};
MainGame.cpp
#include "MainGame.h"
#include <SDL.h>
#include <iostream>
#include <string>
void fatalError(std::string errorString)
{
std::cout << errorString << std::endl;
std::cout << "Enter any key to quit....";
int tmp;
std::cin >> tmp;
SDL_Quit();
}
MainGame::MainGame()
{
_window = nullptr;
_screenWidth = 1024;
_screenHeight = 720;
_gameState = GameState::PLAY;
}
MainGame::~MainGame()
{
}
void MainGame::run()
{
initSystems();
gameLoop();
}
void MainGame::initSystems()
{
SDL_Init(SDL_INIT_EVERYTHING);
_window = SDL_CreateWindow("Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _screenWidth, _screenHeight, SDL_WINDOW_OPENGL);
if (_window == nullptr)
{
fatalError("SDL Window could not be created!");
}
SDL_GLContext glContext = SDL_GL_CreateContext(_window);
if (glContext == nullptr)
{
fatalError("SDL_GLContext could not be created!");
}
GLenum error = glewInit();
if (error != GLEW_OK)
{
fatalError("Could not initialize glew");
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
void MainGame::gameLoop()
{
while(_gameState != GameState::EXIT)
{
processInput();
drawGame();
}
}
void MainGame::processInput()
{
SDL_Event e;
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
_gameState = GameState::EXIT;
break;
case SDL_MOUSEMOTION:
std::cout << e.motion.x << " " << e.motion.y << std::endl;
break;
}
}
}
void MainGame::drawGame()
{
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(_window);
}
我正在使用visual studio 2015。