Using OpenGL (custom port)
David Butler
xadrian at gmail.com
Sun Oct 4 16:52:12 PDT 2009
I'm a bit new to D, but seem to be mostly getting the hang of things.
For a learning project, I decided to do something in OpenGL from scratch
(including porting the headers). As far as I can tell, things are
mostly ported properly... I can create an OpenGL 2.1 context, basic
functions work, etc. However, I've run into a snag in creating a 3+
context.
I have this working in C++ and it should be a straight-forward
conversion, and since everything but this is working I'm starting to
suspect it may be a difference in C arrays and D arrays.
Here's the relevant area (warning, incoming code!):
// Create an old-style context
HGLRC tmpContext = wglCreateContext(m_dc);
wglMakeCurrent(m_dc, context);
int[] attribs =
[
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0
];
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = null;
wglCreateContextAttribsARB =
cast(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
HGLRC newContext;
if (wglCreateContextAttribsARB != null)
{
// Failing for some reason
newContext = wglCreateContextAttribsARB(m_dc, cast(HANDLE)0,
attribs.ptr);
if (!newContext)
{
newContext = context;
}
else
{
wglMakeCurrent(null, null);
wglDeleteContext(context);
wglMakeCurrent(m_dc, newContext);
}
}
else
{
newContext = context;
}
assert(newContext);
// End
In the C++ version, I get a 3.0 context without an issue. The D version
here ends up with a null 'newContext', and an error that the context
requested is invalid.
Is there a difference between a pointer to a D array and an int* in C?
How do I convert between the two? Am I even looking in the right place?
Thanks for any help!
-Dave Butler
More information about the Digitalmars-d-learn
mailing list