问题描述
我创建一个游戏引擎,并开始使用简单的openGL窗口创建。我使用visual studio 2013和引擎正在构建为一个dll。这是dll中初始化openGL的代码:
I am creating a game engine and am starting out with simple openGL window creation. I am using visual studio 2013 and the engine is being built as a dll. This is the code in the dll that initializes 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是一个定义如下的结构:
AsWindowCreateStruct is a structure defined as follows:
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的一个对象。这个类的定义并不重要,但是使用的构造函数定义为:
This does nothing but act as a few parameters to pass into window creation. mWindow is an object of AsWindow. This class's definition is not important, but the constructor in use is defined as:
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的实例。
where pCreateStruct is an instance of AsWindowCreateStruct.
现在,所有代码放在一边,问题是glfwCreateWindow()总是返回0.我在控制台中出现错误WGL:无法找到合适的像素格式。我调试了大约一个小时,并追溯到函数choosePixelFormat在文件wgl_context.c行357调用。函数定义在wgl_context.c行144。这一切都在GLFW 3.0.4。我看过这样的其他文章,他们没有帮助。我有一个NVidia GTX 650ti和使用Geforce的经验Nvidia保持我的驱动程序更新。 Windows不会安装它们。我试过运行GLFW的简单程序,他们在自己的网站上,它的工作完美无瑕。我很确定它必须与在DLL中运行,但我不知道从哪里开始
Now, all code aside, the issue is that glfwCreateWindow() always returns 0. I got the error in the console "WGL: failed to find a suitable Pixel format". I debugged for about an hour and traced it down to the function choosePixelFormat called in the file wgl_context.c line 357. The functions definition is at wgl_context.c line 144. This is all in GLFW 3.0.4. I have looked at the other articles like this and they were not helpful. I have an NVidia GTX 650ti and am using Geforce experience from Nvidia to keep my drivers up to date. Windows is not installing them. I have tried running GLFW's simple program they have on their website www.glfw.org and it works flawlessly. I am pretty sure it has to do with this being run in a DLL, but I do not know where to start
如果你需要任何更多的信息,我会很高兴。
If you need any more information i will be glad to.
编辑:
问题出在
the issue was with
glfwWindowHint(GL_STEREO, GL_TRUE);
推荐答案
GL_STEREO
不启用输出到多个显卡。它使您的交换链中的缓冲区数量翻倍,以启用立体3D渲染(例如,单独的左/右图像)。
GL_STEREO
does not enable output onto multiple graphics cards. It doubles the number of buffers in your swap-chain to enable stereoscopic 3D rendering (e.g. separate left/right images). You may hear it referred to as quad-buffering in some circles.
您需要一个Radeon HD 6xxx +消费级GPU或工作站级NV / AMD GPU,以实现功能性一般在Windows上的OpenGL中公开。在OS X中,你可以得到它没有昂贵的工作站硬件。
You need a Radeon HD 6xxx+ consumer GPU or workstation class NV/AMD GPU in order for the functionality to be exposed in OpenGL on Microsoft Windows, generally. In OS X, you can get it without expensive workstation hardware.
新的NV的驱动程序据说暴露在OpenGL在Microsoft Windows中的此功能。我不能确认这一点,但它很可能是他们只有启用这个最新的GPU。否则为了在Microsoft Windows中的消费级NV卡上获得四缓冲,您必须使用D3D。
Newer versions of NV's drivers are said to expose this functionality in OpenGL in Microsoft Windows. I cannot confirm this, but it is likely they are only going to enable this for the very latest GPUs. Otherwise in order to get quad-buffering on a consumer level NV card in Microsoft Windows you have to use D3D.
Doom 3 BFG版很可能是NV的策略更改的原因,这是第一个主要的OpenGL 游戏使用立体渲染。
Doom 3 BFG Edition is likely the reason for NV's policy change, this is the first major OpenGL game to use stereoscopic rendering.
这篇关于GLFW“WGL:Failed to find a suitable pixel format”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!