本文介绍了在SDL 1.3中创建一个OpenGL 3.2 / 3.x上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,SDL说它不支持OpenGL 3.x上下文。我试图遵循本教程:。我在这种情况下使用GLEW,但我不能得到gl3.h使用这个。这是我最终得到的代码:

  #include< glew.h> 
#include< SDL.h>

int Testing :: init()
{
if(SDL_Init(SDL_INIT_EVERYTHING)< 0)
{
DEBUGLINE );
printSDLError();
system(pause);
return 1; //错误
}

//请求OpenGL 3.2上下文。
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2);

//设置双缓冲区
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

//创建窗口
window = SDL_CreateWindow(OpenGL 3.2 test,
SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,
600,400,SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if(window == NULL)return 3; //错误

//如果有任何
打印错误到控制台printSDLError(__ LINE__);

//设置OpenGL上下文。
glContext = SDL_GL_CreateContext(window);
printSDLError(__ LINE__);
if(glContext == NULL)
{
DEBUGLINE(无法创建OpenGL上下文。
system(pause);
return 4;
}

//初始化glew
GLenum err = glewInit();
if(err!= GLEW_OK)
{
DEBUGLINE(GLEW无法初始化:<< glewGetErrorString(err));
system(pause);
return 2;
}

return 0; // OK代码,没有错误。
}

报告的唯一问题是尝试调用 SDL_GL_CreateContext(window),其中SDL报告不支持GL 3.x。但是,教程和此(我没有打算测试)报告成功结合SDL 1.3和OpenGL 3.2。我知道SDL 1.3正在开发中,但我有点怀疑,即使无意的支持将被删除。



一个上下文仍然创建,GLEW是能够初始化就好了。 (我不能弄清楚我的生活如何看待创建的上下文的版本,因为它应该是核心配置文件,我不知道如何找到这两个。根据教程, SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3)实际上没有做任何事情,在这种情况下我不知道如何获得适当的上下文创建或更改默认上下文。)



编辑:经过一些测试感谢有帮助的功能Nicol给了我,我发现,无论参数我传递到 SDL_GL_SetAttribute ,上下文总是版本1.1。但是,放入任何版本低于3.0不会吐出一个错误,说它不被支持。所以问题是SDL看到的核心版本只有1.1。



为了记录,我使用Visual C ++ 2010 express,GLEW 1.7.0和最新的SDL 1.3修订版。我是相当新的使用所有这三个,我不得不手动建立SDL库32位和64位版本,所以有很多可能会出问题。但是,到目前为止,32和64位版本正在做同样的事情。



编辑:我使用一个nVidia 360M GPU与最新的驱动程序, 4.04报告与OpenGL 3.3完全兼容。



任何帮助都很感激。



:我设法让SDL停止对我说,它不支持3.x上下文。问题是 SDL_GL_SetAttribute 必须设置 BEFORE SDL_Init 被调用:

  //请求OpenGL 3.2上下文。 
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2);

//初始化SDL
if(SDL_Init(SDL_INIT_EVERYTHING)< 0)
{
DEBUGLINE(Error initializing SDL。
return 1;不幸的是,GLEW仍然拒绝承认任何高于OpenGL 1.1的版本(如果你的版本不支持OpenGL 1.1版本)只有GLEW_VERSION_1_1返回true),这仍然让我困惑。 glGetString(GL_VERSION)也报告1.1.0。似乎我的程序根本不知道任何更高的版本,如果我根本没有安装它们。

解决方案

p>因为我不知道你是否已经找到了一个解决方案,这里是我的:



我今天和昨天用这个东西奋斗了很多。高级GL函数不能使用,所以我甚至调试到opengl32.dll只是看看它真的工作和包装调用到硬件特定的OpenGL DLL(nvoglnt.dll)。所以必须有另一个原因。在互联网上甚至有提示在所有其他库之前链接到opengl32.lib,因为ChoosePixelFormat和一些其他函数被彼此覆盖。



但这不是原因,太。我的解决方案是启用加速的视觉效果在这里:

  // init SDL 
if(SDL_INIT_VIDEO | SDL_INIT_HAPTIC | SDL_INIT_TIMER)< 0){
fprintf(stderr,Could not init SDL);
return 1;
}

//我们希望我们的OpenGL版本!
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,1);

因为在当前SDL修订版本(2​​011年12月15日)中,他在SDL_windowsopengl.c

  if(_this-> gl_config.accelerated> = 0){
* iAttr ++ = WGL_ACCELERATION_ARB;
* iAttr ++ =(_this-> gl_config.accelerated?WGL_FULL_ACCELERATION_ARB:
WGL_NO_ACCELERATION_ARB);
}

并且此属性初始化为-1,如果您没有在拥有。



并且:从不在初始化SDL之前设置版本属性,因为设置属性需要正确初始化视频后端!



我希望这有助于。


I'm facing a problem where SDL says it does not support OpenGL 3.x contexts. I am trying to follow this tutorial: Creating a Cross Platform OpenGL 3.2 Context in SDL (C / SDL). I am using GLEW in this case, but I couldn't get gl3.h to work with this either. This is the code I ended up with:

#include <glew.h>
#include <SDL.h>

int Testing::init()
        {
            if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
            {
                DEBUGLINE("Error initializing SDL.");
                printSDLError();
                system("pause");
                return 1; // Error
            }

            //Request OpenGL 3.2 context.
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

            //set double buffer
            SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

            //Create window
            window = SDL_CreateWindow("OpenGL 3.2 test",
                SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                600, 400, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
            if(window == NULL) return 3; // Error

            //Print errors to console if there are any
            printSDLError(__LINE__);

            //Set up OpenGL context.
            glContext = SDL_GL_CreateContext(window);
            printSDLError(__LINE__);
            if(glContext == NULL)
            {
                DEBUGLINE("OpenGL context could not be created.");
                system("pause");
                return 4;
            }

            //Initialize glew
            GLenum err = glewInit();
            if(err != GLEW_OK)
            {
                DEBUGLINE("GLEW unable to be initialized: " << glewGetErrorString(err));
                system("pause");
                return 2;
            }

            return 0; // OK code, no error.
        }

The only problem that is reported is after trying to call SDL_GL_CreateContext(window), where SDL reports "GL 3.x is not supported". However, both the tutorial and this sample pack (which I have not bothered to test with) report success in combining SDL 1.3 and OpenGL 3.2. I am aware that SDL 1.3 is in the middle of development, but I somewhat doubt that even unintentional support would be removed.

A context is still created, and GLEW is able to initialize just fine. (I can't figure out for the life of me how to see the version of the context that was created, since it's supposed to be the core profile, and I don't know how to find that either. According to the tutorial, SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) doesn't actually do anything, in which case I have no clue how to get the appropriate context created or change the default context.)

EDIT: After some testing thanks to the helpful function Nicol gave me, I have found that, regardless of the parameters I pass to SDL_GL_SetAttribute, the context is always version 1.1. However, putting in any version below 3.0 doesn't spit out an error saying it is not supported. So the problem is that the "core" version SDL sees is only 1.1.

For the record, I am using Visual C++ 2010 express, GLEW 1.7.0, and the latest SDL 1.3 revision. I am fairly new to using all three of these, and I had to manually build the SDL libraries for both 32 and 64 bit versions, so there's a lot that could go wrong. So far however, the 32 and 64 bit versions are doing the exact same thing.

EDIT: I am using an nVidia 360M GPU with the latest driver, which OpenGL Extension Viewer 4.04 reports to have full compatibility up to OpenGL 3.3.

Any help is appreciated.

UPDATE: I have managed to get SDL to stop yelling at me that it doesn't support 3.x contexts. The problem was that the SDL_GL_SetAttribute must be set BEFORE SDL_Init is called:

//Request OpenGL 3.2 context.
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

//Initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
    DEBUGLINE("Error initializing SDL.");
    return 1; // Error
}

Unfortunately, GLEW still refuses to acknowledge anything higher than OpenGL 1.1 (only GLEW_VERSION_1_1 returns true), which still has me puzzled. glGetString(GL_VERSION) also reports 1.1.0. It seems that my program simply doesn't know of any higher versions, as if I don't have them installed at all.

解决方案

since I don't know if you already found a solution, here is mine:

I struggled around a lot today and yesterday with this stuff. Advanced GL functions couldn't be used, so I even debugged into opengl32.dll just to see it really works and wraps the calls into the hardware-specific OpenGL DLL (nvoglnt.dll). So there must have been another cause. There were even tips in the internet to link to opengl32.lib before all other libraries, because ChoosePixelFormat and some other functions are overwritten by each other.

But that wasn't the cause, too. My solution was to enable the accelerated visuals here:

// init SDL
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_HAPTIC | SDL_INIT_TIMER) < 0) {
    fprintf(stderr, "Could not init SDL");
    return 1;
}

// we must wish our OpenGL Version!!
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

because in the current SDL revision (Dec 15, 2011) he checks for it in SDL_windowsopengl.c

if (_this->gl_config.accelerated >= 0) {
       *iAttr++ = WGL_ACCELERATION_ARB;
        *iAttr++ = (_this->gl_config.accelerated ? WGL_FULL_ACCELERATION_ARB :
                                                   WGL_NO_ACCELERATION_ARB);
   }

and this attribute is initialized to -1 if you did not define it on your own.

And: Never set the version attributes before initializing SDL, because settings attributes needs the video backend to be initialized properly!

I hope this helps.

这篇关于在SDL 1.3中创建一个OpenGL 3.2 / 3.x上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 21:30