Reputation: 424
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 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){}
};
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);
where pCreateStruct is an instance of AsWindowCreateStruct.
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.
EDIT:
the issue was with
glfwWindowHint(GL_STEREO, GL_TRUE);
Upvotes: 0
Views: 2816
Reputation: 43359
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.
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.
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 Edition is likely the reason for NV's policy change, this is the first major OpenGL game to use stereoscopic rendering.
Upvotes: 2