在OS X 10.10下启用OpenGL 4.1,并具有GLEW,GLFW和g++编译
Enabling OpenGL 4.1 under OS X 10.10 with GLEW, GLFW and g++ compilation
我有一个2014 RMBP,更新到最新版本的OS X,这应该保证我兼容OpenGL 4.1。我整理了一个最小的工作示例:
#include <iostream>
#include "GL/glew.h"
#include <GLFW/glfw3.h>
using namespace std;
int main(){
int windowWidth = 800;
int windowHeight = 800;
string windowTitle = "title";
glfwDefaultWindowHints();
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
if( !glfwInit() )
{
cerr << "Failed to initialize GLFW.n";
return 1;
} else {
clog << "Initialized GLFW." << endl;
}
GLFWwindow* pWindow = glfwCreateWindow(windowWidth, windowHeight, windowTitle.c_str(), 0, NULL);
glfwSetWindowPos(pWindow, 700, 200);
glfwMakeContextCurrent(pWindow);
if( pWindow == NULL )
{
cerr << "Failed to open GLFW window.n";
glfwTerminate();
return 1;
}
std::cout << "GL Version: " << glGetString(GL_VERSION) << "n";
std::cout << "GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << "n";
std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
while (!glfwWindowShouldClose(pWindow))
{
glfwPollEvents();
}
glfwDestroyWindow(pWindow);
return 0;
}
这将打开一个工作正常的窗口,但它输出以下内容:GL 版本: 2.1 英特尔-10.0.86GLSL 版本:1.20供应商:英特尔公司渲染器:英特尔锐炬 OpenGL 引擎
这是错误的!我应该获得 4.1 兼容性。我在 https://github.com/tomdalling/opengl-series 和 xCode 下下载了示例,它确实上升到 4.1,所以我知道我的计算机能够做到这一点。
这实际上适用于一个更大的项目;我确实尝试将我的项目导入 xcode,将其与 Tom Dalling 的项目合并,它只是不起作用,我总是得到 GL 2.1。
我正在编译上面的代码
g++ main.cpp -o GLTEST -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
。也许我错过了一个选择。非常感谢您的帮助!
阅读有关 glfw 站点上的窗口创建提示,您会发现:
每次使用 glfwInit 初始化库时,这些提示都会设置为其默认值
Tom Dalling 的(工作)代码在暗示版本之前调用glfwInit
,而你的代码则在之后执行。
所以我怀疑这可能与此有关。
相关文章:
- Windows.h与GLFW.h的接口
- 无法将 GLFW 库与 Ubuntu 18.04 上的头文件链接
- 如何获取 GLFW 窗口 ID?
- GLEW/GLUT:调用init并创建一个窗口后,取消初始化并重新初始化?
- GLFW需要链接什么?
- 使用Visual Studio Code和CMake调试OpenGL(使用GLEW&GLFW),无法设置断点
- glew和glfw .dylib文件缺少Mac
- Glew - 与 GLFW 配对时 gl- 函数符号上出现链接错误
- libigl,GLEW,GLFW和Eigen在CLion,Windows 10上.链接器错误
- Glew+GLFW Win32 No Dependencies Visual Studio
- 使用GLEW和GLFW,VS2013中似乎无关的错误
- 在OS X 10.10下启用OpenGL 4.1,并具有GLEW,GLFW和g++编译
- OpenGL与GLFW和GLEW-在windows下使用gcc编译
- GLFW/GLEW C++ (atioglxx.dll)
- 我使用Microsoft Visual Studio 2013中的GLFW和GLEW库在OpenGL中编写了一个程序.我
- OpenGL(GLFW/GLEW)中的屏幕上没有显示任何内容
- 如何在fedora/linux-gcc++上链接OpenGL/glew/glfw
- glGetError()中出现INVALID_ENUM错误.glGetError与glu、glew、glfw有关
- Visual Studio 2013 C++链接虚拟机上的静态库glew、glfw
- 如何构建 OpenGL + GLEW + GLFW 程序,以便在带有 exe 的文件夹中不需要 glfw3.dll?