我正在创建一个游戏引擎,并从简单的openGL窗口创建开始。我使用的是2013,引擎是作为dll构建的。这是初始化openGL的dll中的代码:
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:未能找到合适的像素格式“中得到了错误。我调试了大约一个小时,并将其跟踪到文件choosePixelFormat第357行中调用的函数。函数定义在wgl_context.c第144行。这都是在GLFW 3.0.4中。我看过其他类似的文章,它们没有帮助。我有一个NVidia GTX650ti,并正在使用来自Nvidia的Geforce经验,以保持我的司机最新。Windows没有安装它们。我尝试运行GLFW的简单程序,他们在他们的网站www.glfw.org和它的工作完美。我很确定这与在DLL中运行有关,但我不知道从哪里开始。
如果你需要更多的信息,我很乐意。
编辑:
这个问题是关于的
glfwWindowHint(GL_STEREO, GL_TRUE);发布于 2013-11-10 23:12:33
GL_STEREO不允许输出到多个显卡上。它使交换链中的缓冲区数量加倍,以启用立体3D渲染(例如,分开的左/右图像)。在某些圈子里,你可能会听到所谓的四缓冲。
通常,您需要一个Radeon HD 6xxx+消费GPU或工作站类NV/AMD,以便在Microsoft上在OpenGL中公开该功能。在OS中,无需昂贵的工作站硬件就可以获得它。
新版本的NV驱动程序据说在Microsoft中的OpenGL中公开了此功能。我无法证实这一点,但很可能他们只会为最新的GPU启用这一功能。否则,在Microsoft中,为了在消费者级NV卡上获得四缓冲,您必须使用D3D。
命定3 BFG版可能是NV的政策改变的原因,这是第一个主要的OpenGL 游戏使用立体渲染。
https://stackoverflow.com/questions/19881461
复制相似问题