简体   繁体   English

更新:Ubuntu SDL SetVideoMode失败,找不到匹配的GLX Visual

[英]Update: Ubuntu SDL SetVideoMode Failed, Couldn't Find matching GLX Visual

I have been tracking down this issue to the best of my abilities and I think I have found the culprit but I am unable to fix it. 我一直在竭尽所能地追踪这个问题,我想我找到了罪魁祸首,但我无法解决。

Basically I am trying to run my simple game engine in Ubuntu 12.04. 基本上,我试图在Ubuntu 12.04中运行我的简单游戏引擎。 The engine is a static library and it is linked to the using game. 该引擎是一个静态库,它链接到使用游戏。 Everything compiles (in Ubuntu) fine but when I run the program it never opens a window and immediately closes. 一切都可以编译(在Ubuntu中),但是当我运行程序时,它永远不会打开窗口并立即关闭。 In CodeBlocks I get the error "Process terminated with status 255". 在CodeBlocks中,出现错误“进程以状态255终止”。 I believe SetVideoMode is returning null as checked by this line in the Init code: 我相信SetVideoMode会返回Init代码中此行所检查的null:

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

I think this because I previously forgot to add the double equals before the NULL and in this condition the app does not terminate, only never creates a window bu the program is evidently running in the system monitor. 我认为这是因为我以前忘记在NULL之前添加双精度等于,并且在这种情况下应用程序不会终止,只会从不创建窗口,而程序显然已在系统监视器中运行。

I also noticed something interesting. 我也注意到一些有趣的事情。 The Debug version of the static library is 350 odd kb and the program itself is only 150kb. 静态库的Debug版本为350个奇数kb,程序本身仅为150kb。 On windows the program is always more than the size of the library, this assuming the library is built into the executable. 在Windows上,程序总是大于库的大小,这是假定库已内置在可执行文件中。 This maybe how Linux works though. 也许这就是Linux的工作方式。

Here is the engines initialization code: 这是引擎初始化代码:

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

All the function calls prefixed with "game" are extern functions in the actual program. 在实际程序中,所有带有“游戏”前缀的函数调用都是外部函数。 The above code is in the engines library. 上面的代码在引擎库中。

If you require further information please ask. 如果您需要更多信息,请询问。

EDIT: After further hunting down of the issue I noticed SDL give this error: 编辑:进一步寻找问题后,我注意到SDL给出此错误:

Couldn't Find Matching GLX Visual

What Does this mean and how on earth do I fix it? 这是什么意思,我该如何解决?

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

SDL_GL_DOUBLEBUFFER is in no way a valid flags argument to SDL_SetVideoMode() . SDL_GL_DOUBLEBUFFER绝对不是SDL_SetVideoMode()的有效flags参数。


Also, you're specifying a huge number of GL attributes. 另外,您要指定大量的GL属性。 Try removing all of the SDL_GL_SetAttribute() calls. 尝试删除所有SDL_GL_SetAttribute()调用。 If that works add them back in one at a time to figure out which one your GL implementation doesn't like. 如果可行,则一次又添加一次,以找出您的GL实施不喜欢的实施。

(I know this is old but I finally cracked it and it has been bothering me for months.) (我知道这已经很老了,但我终于破解了,几个月来一直困扰着我。)

Remove all the attribute sets for "SDL_GL_ACCUM*", removing these you should that setting multisamples works. 删除“ SDL_GL_ACCUM *”的所有属性集,如果设置多样本有效,则删除这些属性集。

Also remember to enable GL_MULTISAMPLE, GL_LINE_SMOOTH and GL_POLYGON_SMOOTH and perhaps provide hints for line/polygon smoothing. 还请记住启用GL_MULTISAMPLE,GL_LINE_SMOOTH和GL_POLYGON_SMOOTH,并可能提供线/多边形平滑的提示。

You may find you don't see effects of AA when in windowed mode and with some graphics drivers (my catalyst drivers don't seem to do anything.) 您可能会发现在窗口模式下以及使用某些图形驱动程序时看不到AA的效果(我的催化剂驱动程序似乎什么也没做。)

These are the attributes I use: 这些是我使用的属性:

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, 24);
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_ACCELERATED_VISUAL, 1);

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM