?
Ich möchte meinen eigenen Context erzeugen und habe dafür eine Klasse von wxWindow abgeleitet.
Dann erzeuge ich das Fenster genauso wie wxGLCanvas im wxWidgets Source Code:
wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
CreateBase(parent, id, pos, size, wxBORDER_DEFAULT, "NL2DOpenGLCanvas");
parent->AddChild(this);
WXDWORD exStyle = 0;
DWORD msflags = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
msflags |= MSWGetStyle(wxBORDER_DEFAULT, &exStyle);
if ( !MSWCreate(wxApp::GetRegisteredClassName(wxT("NL2DOpenGLCanvas"), 0, CS_OWNDC|CS_VREDRAW|CS_HREDRAW),
NULL, pos, size, msflags, exStyle) )
{
return false;
}
Danach erzeuge ich meinen eigenen Context.
Das lustige:
Mein Programm meldet dass alles okay ist. Nur mein Context bleibt grau :(. Es wird nix gerendert.
http://h4.abload.de/img/wxprob4t6a.png
[NLIPlatformContext] OpenGL Vendor String: ATI Technologies Inc.
[NLIPlatformContext] OpenGL Version: 3.3.10834 Core Profile Forward-Compatible Context
[NLIPlatformContext] OpenGL Renderer: ATI Radeon HD 4800 Series
[NLIPlatformContext] OpenGL Shader Version: 3.30
Context:
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.");
}
// When running under Windows Vista or later support desktop composition.
// This doesn't really apply when running in full screen mode.
if (osvi.dwMajorVersion > 6 || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 0))
pfd.dwFlags |= PFD_SUPPORT_COMPOSITION;
// 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");
}
}
Kann sich wer vorstellen was da los sein könnte?
Hinweis: Mit einem puren Win32 Fenster funktioniert der Context.