Sign in to follow this  
NicoG

OpenGL Need Help implementing Canvas for wxWidgets

Recommended Posts

Guys, I need some serious help.
I have a class that creates an OpenGL3 Profile:

[code]

NLContextWin32::NLContextWin32(NLWindowHandle parent, NLOpenGLSettings settings)
: NLIPlatformContext(parent, settings)
{
int pf = 0;
PIXELFORMATDESCRIPTOR pfd = {0};
OSVERSIONINFO osvi = {0};
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

// Obtain HDC for this window.
if (!(m_hdc = GetDC((HWND)parent)))
{
NLError("[NLContextWin32] GetDC() failed.");
throw NLException("GetDC() failed.", true);
}

// Create and set a pixel format for the window.
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = settings.BPP;
pfd.cDepthBits = settings.BPP;
pfd.iLayerType = PFD_MAIN_PLANE;

// Obtain Windows Version
if (!GetVersionEx(&osvi))
{
NLError("[NLContextWin32] GetVersionEx() failed.");
throw NLException("[NLContextWin32] GetVersionEx() failed.");
}

// Get a pixelformat, based on our settings
pf = ChoosePixelFormat(m_hdc, &pfd);

// Set the pixelformat
if (!SetPixelFormat(m_hdc, pf, &pfd))
{
NLError("[NLContextWin32] GetVersionEx() failed.");
throw NLException("[NLContextWin32] SetPixelFormat() failed.");
}

// Verify that this OpenGL implementation supports the extensions we need
std::string extensions = wglGetExtensionsStringARB(m_hdc);
if (extensions.find("WGL_ARB_create_context") == std::string::npos){
NLError("[NLContextWin32] Required extension WGL_ARB_create_context is not supported.");
throw NLException("[NLContextWin32] Required extension WGL_ARB_create_context is not supported.");
}

// Creates an OpenGL forward compatible rendering context.
int attribList[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, settings.MAJOR,
WGL_CONTEXT_MINOR_VERSION_ARB, settings.MINOR,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0, 0
};

// First try creating an OpenGL context.
if (!(m_hglrc = wglCreateContextAttribsARB(m_hdc, 0, attribList)))
{
// Fall back to an OpenGL 3.0 context.
attribList[3] = 0;
if (!(m_hglrc = wglCreateContextAttribsARB(m_hdc, 0, attribList))){
NLError("[NLContextWin32] wglCreateContextAttribsARB() failed for OpenGL 3 context.");
throw NLException("[NLContextWin32] wglCreateContextAttribsARB() failed for OpenGL 3 context.", true);
}
}

if (!wglMakeCurrent(m_hdc, m_hglrc)){
NLError("[NLContextWin32] wglMakeCurrent() failed for OpenGL 3 context.");
throw NLException("[NLContextWin32] wglMakeCurrent() failed for OpenGL 3 context.");
}

// Load wglSwapIntervalExt
typedef BOOL (APIENTRY * PFNWGLSWAPINTERVALEXTPROC)(int);
static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));

if ( wglSwapIntervalEXT )
{
if ( settings.VSYNC == true )
{
wglSwapIntervalEXT(1);
}
else if ( settings.VSYNC == false )
{
wglSwapIntervalEXT(0);
}
}
else if (wglSwapIntervalEXT == NULL )
{
NLWarning("[NLContextWin32] Cannot load wglSwapIntervalEXT");
}
}
[/code]

When I try to create my Canvas on a wxWindow, then the code fails with "GetDC() failed" because the Widgets do not have CS_OWNDC. And I did not find any way to create one.
I asked in the wxWidgets forums for help, but no replies.
So I try here.
I would also gladly take any other gui-toolkit that supports OpenGL3 properly.
The reason I cannot use wxGLCanvas is that I use gl3w to initialize OpenGL and it requires a strict OpenGL3 context.
I need a GUI-Toolkit for my Tools.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this