首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SDL中设置OGL主要版本会导致错误

在SDL中设置OGL主要版本会导致错误
EN

Stack Overflow用户
提问于 2012-11-08 23:50:25
回答 1查看 744关注 0票数 0

我现在正试着用C写下OpenGL。我有最新的代码:

代码语言:javascript
复制
#include <stdio.h>
#include <stdlib.h>

#define null (void*)0

#define GL3_PROTOTYPES 1
#include <GL/gl3.h>

#include <SDL.h>
#define PROGRAM_NAME "Tutorial1"

void sdldie(const char *msg)
{
    printf("%s: %s\n", msg, SDL_GetError());
    SDL_Quit();
    exit(1);
}

void checkSDLError(int line)
{
    #ifndef NDEBUG
        const char *error = SDL_GetError();
        if(*error != '\0')
        {
            printf("SDL Error: %s\n", error);
            if(&line != null)
                printf(" + line: %i\n", line);
            SDL_ClearError();
        }
    #endif
}

int main(int argc, char *argv[])
{
    SDL_Window *mainwindow; //window handle
    SDL_GLContext maincontext; //opengl context handle

    if(SDL_Init(SDL_INIT_VIDEO) < 0)//initialize video subsystem
        sdldie("Unable to initialize SDL"); //DIE ON ERROR

    //request OGL 3.2 context (default to SDL core profile)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

    //turn on double buffering with a 24 bit Z buffer
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
    if(!mainwindow)
        sdldie("Unable to create window");

    checkSDLError(__LINE__);

    //create an opengl context and attach it to the window
    maincontext = SDL_GL_CreateContext(mainwindow);
    checkSDLError(__LINE__);

    //VSync, turn it off later
    SDL_GL_SetSwapInterval(1);

    //clear buffer with red background
    glClearColor(1.0,0.0,0.0,1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    //swap back buffer to the front
    SDL_GL_SwapWindow(mainwindow);
    //wait 2 secs
    SDL_Delay(2000);

    //repeat with green
    glClearColor(0.0,1.0,0.0,1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    //swap back buffer to the front
    SDL_GL_SwapWindow(mainwindow);
    //wait 2 secs
    SDL_Delay(2000);

    //delete all dis shit
    SDL_GL_DeleteContext(maincontext);
    SDL_DestroyWindow(mainwindow);
    SDL_Quit();

    return 0;
}

注意我们选择OGL版本的代码行(在main中,在初始化视频之后)...当我像这里的代码那样做的时候,我会得到一个错误:

代码语言:javascript
复制
X Error of failed request:  GLXBadFBConfig
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  34 ()
  Serial number of failed request:  166
  Current serial number in output stream:  165

导致此问题的代码行具体如下:

代码语言:javascript
复制
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);

当它被注释掉时,一切都工作得很好(但很可能使用另一个OGL版本D:)

我使用的是最新版本的FOSS Radeon驱动程序(在Arch上),SDL2.0 HG版本,最新稳定的GLX和gl3.h已经手动下载...arch linux和gcc 4.7.2版

你知道为什么会发生这种情况(使用/how来摆脱它)吗?是否有必要设置该属性?

EN

回答 1

Stack Overflow用户

发布于 2013-06-02 19:49:39

SDL2还没有发布,可能会包含严重的错误。在你的例子中,是SDL_GL_CreateContext中的一个bug。

在2013年3月10日做出了一个承诺来解决这个问题:SDL_GL_CreateContext() causes fatal X11 protocol errors that should just be caught instead

我的成功地用最新的SDL2提交创建了一个OpenGl 3.2上下文。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13292518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档