我想复制使用OpenGL版本> = 3.3的教程(精灵渲染)。
例如,在3.2中引入了几何着色器,我得到了这个错误:
error: ‘GL_GEOMETRY_SHADER’ was not declared in this scope
我将我的台面驱动程序更新到最新;我真的不明白,在c ++中编译/链接时如何选择更新版本的OpenGL:
➜glxinfo| grep -i“version”
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
Version: 17.1.4
Max core profile version: 4.5
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL core profile version string: 4.5 (Core Profile) Mesa 17.1.4
OpenGL core profile shading language version string: 4.50
OpenGL version string: 3.0 Mesa 17.1.4
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 17.1.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
我无法解释这一点,但它表示使用4.5版本的某种核心配置文件。我如何利用此个人资料?
我在我的代码中初始化GL上下文:
if(!glfwInit()) e_glfw_init();
m_window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE.c_str(), nullptr, nullptr);
if(m_window == nullptr) e_window_context();
glfwMakeContextCurrent(m_window);
glewExperimental = true;
if(glewInit() != GLEW_OK) e_glew_init();
答案 0 :(得分:0)
According to the glfw documentation, you can specify the OpenGL version and profile by using the glfwWindowHint
function:
if(!glfwInit()) e_glfw_init();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
m_window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE.c_str(),
nullptr, nullptr);
答案 1 :(得分:-1)
我在Linux上通过在使用GLFW和着色器时包含了这三个标头解决了这个问题:
abstract class Fruit
{
protected abstract static function name() : string;
/*
* Basically, if you call the default method from any child (not necessarily a direct child) class, no problems,
* but if you call it directly from the baseclass, you get the somewhat acceptable exception :)
*/
public static function printName()
{
if(!is_subclass_of(static::class, self::class))
{
throw new \BadMethodCallException("Can't call base Fruit class methods directly!");
}
return "My name is: " . static::name();
}
}
//those are abstract now, just to match the intention of them being utility singletons
abstract class Apple extends Fruit
{
protected static function name() : string
{
return "apple";
}
}
abstract class Pear extends Fruit
{
protected static function name() : string
{
return "pear";
}
}