简体   繁体   English

带有SDL2的OpenGL无法返回正确的版本

[英]OpenGL with SDL2 doesn't return the right version

I have an SDL2 application in which I want to create an OpenGL 3.2 context. 我有一个SDL2应用程序,我想在其中创建OpenGL 3.2上下文。 I googled a bit and started following this tutorial: http://open.gl/context#SDL 我在Google上搜索了一下,并开始遵循本教程: http : //open.gl/context#SDL

Everything seems to work except for the last step. 除了最后一步,一切似乎都正常。 When I had to implement this piece of code: 当我必须实现这段代码时:

GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);

printf("%u\n", vertexBuffer);

My application doesn't seem to have a reference to the functor that should be there. 我的应用程序似乎没有引用应该存在的函子。 I know there are some people here who had the same problem but I didn't find a solution there. 我知道这里有些人遇到同样的问题,但是我没有找到解决方案。 When I output the GL_VERSION it says it's 1.1.0 although I say it should be 3.2.0. 当我输出GL_VERSION时,它说是1.1.0,尽管我说应该是3.2.0。 Here's my code: 这是我的代码:

// START SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
    logSDLError(std::cout, "SDL_Init");
    return 1;
}

// SETUP OPENGL SETTINGS
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

// OPENING WINDOW
m_pWindow = SDL_CreateWindow("SDL/OpenGL Game Client - With Networking Library", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
if (m_pWindow == nullptr)
{
    logSDLError(std::cout, "CreateWindow");
    return 2;
}

// CREATE AN OPENGL CONTEXT ASSOCIATED WITH THE WINDOW.
m_GlContext = SDL_GL_CreateContext(m_pWindow);
if( m_GlContext == NULL )
{
    printf( "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() );
}

//Initialize GLEW
glewExperimental = GL_TRUE; 
GLenum glewError = glewInit();
if( glewError != GLEW_OK )
{
    printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
}

printf((char*)glGetString(GL_VERSION));

I have a FirePro graphics card that should be able to run OpenGL 4.0. 我有一个应该能够运行OpenGL 4.0的FirePro图形卡。 I checked my driver updates and everything should be fine + I get no compile warnings saying that something might be wrong with OpenGL or Glew or SDL. 我检查了驱动程序更新,并且一切正常,并且没有收到编译警告,指出OpenGL或Glew或SDL可能有问题。

One thing I had to do to make glGetString() working was to include GL\\freeglut.h. 为了使glGetString()正常工作,我要做的一件事就是包含GL \\ freeglut.h。 I don't really know why that is because it doesn't say so in the tutorial I followed. 我真的不知道为什么会这样,因为在我遵循的教程中没有这么说。

I found the problem. 我发现了问题。 I forgot to mention that I'm using MSTSC to remote from my desktop to my laptop (which is easier to work) and apparently this changes the graphics device. 我忘了提到我使用MSTSC从台式机到笔记本电脑的远程操作(这更容易工作),显然这改变了图形设备。

I tried opening my application from the actual laptop and suddenly it worked, giving the right OpenGL version and everything. 我尝试从实际的笔记本电脑打开应用程序,然后突然工作了,给出了正确的OpenGL版本和所有内容。

Stupid mistake, I should've found this earlier. 愚蠢的错误,我应该早点发现。

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

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