我开始在 Windows 上使用 SDL 和 OpenGL 制作这个超级简单的游戏引擎。引擎位于静态库中,到目前为止,它所做的只是显示一个蓝色窗口,其中包含引擎的所有基础工作。
它在 Windows 上运行良好,但后来我将它移植到 Linux 上,什么也没有。该程序运行良好并显示在系统监视器中,但没有出现任何窗口。我安装了几个 mesa 和 gl 库来检查是不是这样。现在它不会运行并说进程以状态-1终止。
这是引擎中的初始化代码。请询问其他任何事情。
#include "Scales.h"
#include "SDL/SDL.h"
#include "gl.h"
#include "glu.h"
Engine *scalesEngine;
bool OnInit(int WindowHeight, int WindowWidth){
SDL_Surface* Surf_Display;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
return false;
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
if((Surf_Display = SDL_SetVideoMode(WindowWidth, WindowHeight, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)) = NULL){
return false;
}
glClearColor(0.422f,0.576f,1.0f,1.0f);
glClearDepth(1.0f);
glViewport(0, 0, WindowWidth, WindowHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WindowWidth, WindowHeight, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
game_Init();
return true;
}
int main(int argc, char* argv[]){
scalesEngine = new Engine;
game_preload();
if(OnInit(scalesEngine->WindowHeight(), scalesEngine->WindowWidth()) == false){
return -1;
}
SDL_Event Event;
//Main Game Loop
while(scalesEngine->Running){
while(SDL_PollEvent(&Event)){
scalesEngine->OnEvent(&Event);
}
scalesEngine->Update();
scalesEngine->Render();
}
scalesEngine->OnCleanUp();
delete scalesEngine;
return 0;
}