gpt4 book ai didi

c++ - SDL+OpenGL 程序没有出现在 linux 上

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:58:42 26 4
gpt4 key购买 nike

我开始在 Windows 上使用 SDL 和 OpenGL 制作这个 super 简单的游戏引擎。引擎位于静态库中,到目前为止它所做的只是显示一个蓝色窗口,其中包含引擎的所有基础工作。

它在 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;
}

最佳答案

if((Surf_Display = SDL_SetVideoMode(WindowWidth, WindowHeight, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)) = NULL){
return false;
}

我很确定你的意思是 == NULL,对吧?

关于c++ - SDL+OpenGL 程序没有出现在 linux 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com