c++ - 更新 : Ubuntu SDL SetVideoMode Failed, 找不到匹配的 GLX Visual

标签 c++ linux opengl sdl

我一直在尽我所能追踪这个问题,我想我已经找到了罪魁祸首,但我无法修复它。

基本上,我正在尝试在 Ubuntu 12.04 中运行我的简单游戏引擎。该引擎是一个静态库,它链接到正在使用的游戏。一切都编译(在 Ubuntu 中)很好但是当我运行程序时它永远不会打开一个窗口并立即关闭。在 CodeBlocks 中,我收到错误“进程终止,状态为 255”。我相信 SetVideoMode 正在返回 null,正如 Init 代码中的这一行所检查的那样:

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

我认为这是因为我之前忘记在 NULL 之前添加双等号,在这种情况下,应用程序不会终止,只会从不创建窗口,但程序显然正在系统监视器中运行。

我还注意到了一些有趣的事情。 Debug版本的静态库有350多kb,程序本身只有150kb。在 Windows 上,程序总是大于库的大小,这是假设库是内置到可执行文件中的。这也许是 Linux 的工作方式。

这是引擎初始化代码:

#include "Scales.h"
#include "SDL/SDL.h"
#include "GL/gl.h"
#include "GL/glu.h"
#include "SDL/SDL_opengl.h"
#include <iostream>

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_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;
}

所有以“game”为前缀的函数调用都是实际程序中的外部函数。以上代码在engines库中。

如果您需要更多信息,请询问。

编辑:在进一步追查问题后,我注意到 SDL 给出了这个错误:

Couldn't Find Matching GLX Visual

这是什么意思,我究竟该如何解决?

最佳答案

SDL_SetVideoMode(WindowWidth, WindowHeight, 32,SDL_GL_DOUBLEBUFFER | SDL_OPENGL))

SDL_GL_DOUBLEBUFFER 绝不是 SDL_SetVideoMode() 的有效 flags 参数.


此外,您还指定了大量的 GL 属性。尝试删除所有 SDL_GL_SetAttribute() 调用。如果可行,一次将它们加回去,以确定您的 GL 实现不喜欢哪一个。

关于c++ - 更新 : Ubuntu SDL SetVideoMode Failed, 找不到匹配的 GLX Visual,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495382/

相关文章:

c++ - 部分专用模板的声明不完整

c++ - 在 C++/Windows 中,如何获取我所在计算机的网络名称?

c++ - 引用或指针更快吗?

c - 使用C在Linux中通过串口从SIM读取短信

c++ - 没有 main() 的 Cpp 类中的 `undefined reference to ` main`

linux - 在后台运行 SCP 并监控进度

c++ - 用 GLUT 绘制大文本?

c++ - OpenGL C++ 围绕场景中心旋转对象

c++ - 将 std::vector 作为参数传递给函数时出现 EXC_BAD_ACCESS

linux - linux 和 nginx 更新后 php 不工作