Jump to content
  • Advertisement
Sign in to follow this  
NicoG

OpenGL Need Help implementing Canvas for wxWidgets

This topic is 2554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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



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");
}
}


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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!