我正在创建一个游戏引擎,并从简单的 openGL 窗口创建开始。我正在使用 Visual Studio 2013,并且引擎正在构建为 dll。这是 dll 中初始化 openGL 的代码:
bool AsGraphicsManager::Initialize(AsWindowCreateStruct pWindow)
{
//first create the error handler
glfwSetErrorCallback(error::glfw_error_callback);
//Initialize the library
if (!glfwInit())
return 0;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
#ifdef _DEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif /* _DEBUG */
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_SAMPLES, 0);
glfwWindowHint(GLFW_STEREO, GL_TRUE);
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
glfwWindowHint(GLFW_DEPTH_BITS, 16);
mWindow = new AsWindow(pWindow);
//make the first window the current
glfwMakeContextCurrent(mWindow->mWindow);
//make sure to do this to enable new opengl
glewExperimental = GL_TRUE;
//now initialize glew
GLenum res = glewInit();
if (res != GLEW_OK)
{
printf("Error code: %s While Initializing Glew \n", glewGetErrorString(res));
return false;
}
//input handler
glfwSetKeyCallback(mWindow->mWindow, input::key_callback);
glfwSetScrollCallback(mWindow->mWindow, input::scroll_callback);
glfwSetMouseButtonCallback(mWindow->mWindow, input::mouse_callback);
glfwSetCursorPosCallback(mWindow->mWindow, input::mouse_position_callback);
//nothing went wrong
return true;
}
AsWindowCreateStruct 是一个结构体,定义如下:
struct ASGE_API AsWindowCreateStruct
{
GLushort mHeight;
GLushort mWidth;
GLushort mXPos;
GLushort mYPos;
std::string mWindowTitle;
bool mFullscrean;
AsWindowCreateStruct(GLushort pWindowHeight, GLushort pWindowWidth, GLushort pWindowXPosition, GLushort pWindowYPosition, std::string pWindowTitle, bool pIsFullscrean = false) :
mHeight(pWindowHeight), mWidth(pWindowWidth), mXPos(pWindowXPosition), mYPos(pWindowYPosition), mWindowTitle(pWindowTitle), mFullscrean(pIsFullscrean){}
};
这只是作为一些参数传递给窗口创建。mWindow 是 AsWindow 的一个对象。这个类的定义并不重要,但使用的构造函数定义为:
mHeight = pCreateStruct.mHeight;
mWidth = pCreateStruct.mWidth;
mXPos = pCreateStruct.mXPos;
mYPos = pCreateStruct.mYPos;
mWindowTitle = pCreateStruct.mWindowTitle;
mFullscrean = pCreateStruct.mFullscrean;
mWindow = 0;
//now create the window
if (mFullscrean)
{
mWindow = glfwCreateWindow(mHeight, mWidth, mWindowTitle.c_str(), glfwGetPrimaryMonitor(), nullptr);
if (!mWindow)
{
printf("Error initializing Window \n");
glfwTerminate();
}
}
else
{
mWindow = glfwCreateWindow(mHeight, mWidth, mWindowTitle.c_str(), nullptr, nullptr);
//this needs to happen before seting window position
if (!mWindow)
{
printf("Error initializing Window \n");
glfwTerminate();
}
else
{
//as long as it isn't fullscrean, change the position
glfwSetWindowPos(mWindow, mXPos, mYPos);
}
};
//make the window visible
glfwShowWindow(mWindow);
其中 pCreateStruct 是 AsWindowCreateStruct 的一个实例。
现在,除了所有代码,问题是 glfwCreateWindow() 总是返回 0。我在控制台中收到错误“WGL:找不到合适的像素格式”。我调试了大约一个小时,并将其追溯到文件 wgl_context.c 第 357 行中调用的函数 choosePixelFormat。函数定义在 wgl_context.c 第 144 行。这一切都在 GLFW 3.0.4 中。我看过其他类似的文章,但它们没有帮助。我有一个 NVidia GTX 650ti,并且正在使用 Nvidia 的 Geforce 经验来使我的驱动程序保持最新。Windows 没有安装它们。我曾尝试运行他们在其网站www.glfw.org上提供的 GLFW 的简单程序,并且运行良好。我很确定这与在 DLL 中运行有关,但我不知道从哪里开始
如果您需要更多信息,我将很高兴。
编辑:
问题在于
glfwWindowHint(GL_STEREO, GL_TRUE);