我正在尝试在SDL_Window上初始化OpenGL上下文。
问题是,当我尝试执行glewInit()
时,它无法初始化并提供错误消息"缺少OpenGL版本。"
我在谷歌上搜索过,似乎这个错误要么在OpenGL上下文没有被初始化时出现,要么更具体地说是SDL,当上下文没有被SDL_GL_MakeCurrent
生成时。
值得一提的是,此处使用的SDL / OpenGL对象(gi_window,gi_glcontext)是GameInstance
类中的公共变量。
我的OpenGL版本是3.0,我的SDL版本是2.0.3,而我的GLEW版本是1.10-2。
使用的系统是64位Arch Linux(因此安装了上述库的64位版本)。
#include "../headers/init.h"
GameInstance::GameInstance(int p_fps, int p_height, int p_width, const char* p_wtitle)
{
gi_fps = p_fps;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
std::cerr << "SDL Error(something about the init):" << SDL_GetError() << std::endl;
}
gi_window = SDL_CreateWindow(p_wtitle,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, p_width, p_height,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if(gi_window == NULL)
{
std::cerr << "SDL Error(couldn't create window): " << SDL_GetError() << std::endl;
}
SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MAJOR_VERSION , 3 ) ;
SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MINOR_VERSION , 0 ) ;
gi_glcontext = SDL_GL_CreateContext(gi_window);
if(gi_glcontext == NULL)
{
std::cerr << "SDL Error(something about glcontext): " << SDL_GetError() << std::endl;
}
std::cout << glGetString(GL_VERSION) << std::endl;
if(SDL_GL_MakeCurrent(gi_window, gi_glcontext) < 0)
{
std::cerr << "SDL Error(something about glcontext): " << SDL_GetError() << std::endl;
}
glewExperimental = GL_TRUE;
GLenum glewerror = glewInit();
if(glewerror =! GLEW_OK)
{
std::cerr << "GLEW Error(something about the initilazation): " << glewGetErrorString(glewerror) << std::endl;
}
SDL_version compiled;
SDL_GetVersion(&compiled);
printf("SDL Version: %d.%d.%d\n",compiled.major, compiled.minor, compiled.patch); //
SDL_Delay(200000);
}
似乎还没有设置glewExperimental时出现Missing OpenGL Version
的另一个原因,因为只有实验版的glew支持3.0+
我已经正确设置了glewExperimental(至少从我从在线示例中收集到的内容),但它仍然给了我Missing OpenGL Version
。
代码here执行不抛出Missing OpenGL version
,尽管它与我的非常相似。
根据enhzflep的建议,我已经重写了代码,试图诊断发生了什么。
错误并没有减轻。
#include <SDL2/SDL.h>
#include <SDL2/SDL_version.h>
#include <GL/glew.h>
#include <iostream>
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* gi_window = SDL_CreateWindow("I would love for this to work!",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
SDL_GLContext gi_glcontext = SDL_GL_CreateContext(gi_window);
SDL_GL_MakeCurrent(gi_window, gi_glcontext);
SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MAJOR_VERSION , 3 );
SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MAJOR_VERSION , 0 );
glewExperimental = GL_TRUE;
GLenum glewerror = glewInit();
if(glewerror =! GLEW_OK)
{
std::cerr << "GLEW Error(something about the initilazation): " << glewGetErrorString(glewerror) << std::endl;
}
}
答案 0 :(得分:1)
我是个白痴。
if(glewerror =! GLEW_OK)
{
std::cerr << "GLEW Error(something about the initilazation): " <<
glewGetErrorString(glewerror) << std::endl;
}
应该是
if(glewerror != GLEW_OK)
{
std::cerr << "GLEW Error(something about the initilazation): " <
glewGetErrorString(glewerror) << std::endl;
}
欢迎所有试图帮助的人!