由于某种原因,SDL 拒绝渲染图像。我不明白为什么,这真的阻碍了我正在开发的 2d 游戏的进展。一切都正确链接等等。这是我的代码:
//main.cpp
#include "main.h"
void game::createWindow(const int SCREEN_W, const int SCREEN_H, const char* SCREEN_NAME)
{
buffer = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, NULL);
SDL_WM_SetCaption(SCREEN_NAME, NULL);
}
void game::enterLoop()
{
while(Running == true)
{
SDL_BlitSurface(zombie, NULL, buffer, NULL);
SDL_Flip(buffer);
while(SDL_PollEvent(&gameEvent))
{
if(gameEvent.type == SDL_QUIT)
{
Running = false;
}
}
}
}
void game::loadContent()
{
zombie = SDL_LoadBMP("zombie.bmp");
}
int main(int argc, char* argv[])
{
game gameObj;
SDL_Init(SDL_INIT_EVERYTHING);
gameObj.createWindow(960, 600, "uShootZombies");
gameObj.loadContent();
gameObj.enterLoop();
SDL_Quit();
return 0;
}
//main.h
#include <SDL.h>
#include <fstream>
#include <string>
using namespace std;
class game
{
public:
void createWindow(const int SCREEN_W, const int SCREEN_H, const char* SCREEN_NAME);
void enterLoop();
void loadContent();
game()
{
Running = true;
}
~game()
{
SDL_FreeSurface(buffer);
SDL_FreeSurface(background);
SDL_FreeSurface(player);
SDL_FreeSurface(zombie);
}
private:
SDL_Surface* buffer;
SDL_Surface* background;
SDL_Surface* player;
SDL_Surface* zombie;
SDL_Event gameEvent;
bool Running;
};NU