www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Glad and WGL

reply Josh Phillips <jjpman71 gmail.com> writes:
So I started using Glad but I can't get WGL to work with it, 
though I think this is more of a Win32 issue than WGL.

wndclass.lpfnWndProc   = &WndProc;

Gives me an error no matter what:
Error: cannot implicitly convert expression (& WndProc) of type 
int function(void* hWnd, uint message, uint wParam, int lParam) 
to extern (Windows) int function(void*, uint, uint, int) nothrow

I think the error has to do with the nothrow but I tried making 
the function empty

extern(Windows)
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam)
{
    return 0;
}

And still got the same exact error. Any ideas/help?
Jan 13 2016
next sibling parent Dav1d <d dav1d.de> writes:
On Wednesday, 13 January 2016 at 18:34:14 UTC, Josh Phillips 
wrote:
 So I started using Glad but I can't get WGL to work with it, 
 though I think this is more of a Win32 issue than WGL.

 wndclass.lpfnWndProc   = &WndProc;

 Gives me an error no matter what:
 Error: cannot implicitly convert expression (& WndProc) of type 
 int function(void* hWnd, uint message, uint wParam, int lParam) 
 to extern (Windows) int function(void*, uint, uint, int) nothrow

 I think the error has to do with the nothrow but I tried making 
 the function empty

 extern(Windows)
 LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
 lParam)
 {
    return 0;
 }

 And still got the same exact error. Any ideas/help?
Your function isnt marked nothrow.
Jan 13 2016
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 13 January 2016 at 18:34:14 UTC, Josh Phillips 
wrote:
 extern(Windows)
 LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
 lParam)
You just need to explicitly mark it nothrow in the signature. Add `nothrow` to the end of the param list: extern(Windows) LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) nothrow and then you'll be cool
Jan 13 2016
parent reply Josh Phillips <jjpman71 gmail.com> writes:
On Wednesday, 13 January 2016 at 18:37:09 UTC, Adam D. Ruppe 
wrote:
 You just need to explicitly mark it nothrow in the signature. 
 Add `nothrow` to the end of the param list:

 extern(Windows)
 LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
 lParam) nothrow

 and then you'll be cool
Oh wow that's easy. They should really make that more clear in the dlang reference. They way it sounds there made me think that if a function doesn't throw any errors it automatically is 'nothrow' Dav1d do I need to implicitly link WGL to any dlls or anything? Now I'm getting linking errors ..\dlibgui\lib\dlibgui.lib(window) Error 42: Symbol Undefined _wglMakeCurrent 8 ..\dlibgui\lib\dlibgui.lib(window) Error 42: Symbol Undefined _wglCreateContext 4 ..\dlibgui\lib\dlibgui.lib(window) Error 42: Symbol Undefined _ChoosePixelFormat 8 ..\dlibgui\lib\dlibgui.lib(window) Error 42: Symbol Undefined _SetPixelFormat 12 ..\dlibgui\lib\dlibgui.lib(window) Error 42: Symbol Undefined _wglDeleteContext 4 --- errorlevel 5 dmd failed with exit code 5.
Jan 13 2016
next sibling parent reply Dav1d <d dav1d.de> writes:
On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips 
wrote:
 On Wednesday, 13 January 2016 at 18:37:09 UTC, Adam D. Ruppe 
 wrote:
 [...]
Oh wow that's easy. They should really make that more clear in the dlang reference. They way it sounds there made me think that if a function doesn't throw any errors it automatically is 'nothrow' [...]
Link with opengl32.lib
Jan 13 2016
parent reply Josh Phillips <jjpman71 gmail.com> writes:
On Wednesday, 13 January 2016 at 20:08:55 UTC, Dav1d wrote:
 Link with opengl32.lib
How? Everywhere I looked it says this cannot be done due to conflicting formats between the dmd compiler and the windows one.
Jan 13 2016
parent reply Dav1d <d dav1d.de> writes:
On Thursday, 14 January 2016 at 02:35:28 UTC, Josh Phillips wrote:
 On Wednesday, 13 January 2016 at 20:08:55 UTC, Dav1d wrote:
 Link with opengl32.lib
How? Everywhere I looked it says this cannot be done due to conflicting formats between the dmd compiler and the windows one.
Welcome to D and Windows. You can use GDC or LDC or try http://wiki.dlang.org/Installing_DMD_on_64-bit_Windows_7_(COFF-compatible) Or you find an OMF opengl32.lib OR you make your own with implib and coff2omf http://www.digitalmars.com/ctg/implib.html http://www.digitalmars.com/ctg/coff2omf.html I dont really remember how that worked.
Jan 14 2016
parent reply Dav1d <d dav1d.de> writes:
On Thursday, 14 January 2016 at 09:25:50 UTC, Dav1d wrote:
 On Thursday, 14 January 2016 at 02:35:28 UTC, Josh Phillips 
 wrote:
 On Wednesday, 13 January 2016 at 20:08:55 UTC, Dav1d wrote:
 Link with opengl32.lib
How? Everywhere I looked it says this cannot be done due to conflicting formats between the dmd compiler and the windows one.
Welcome to D and Windows. You can use GDC or LDC or try http://wiki.dlang.org/Installing_DMD_on_64-bit_Windows_7_(COFF-compatible) Or you find an OMF opengl32.lib OR you make your own with implib and coff2omf http://www.digitalmars.com/ctg/implib.html http://www.digitalmars.com/ctg/coff2omf.html I dont really remember how that worked.
There is also objconv: http://www.agner.org/optimize/ I found in an older code: echo "implib /s opengl32.lib opengl32.dll && exit" | cmd So maybe `implib /s opengl32.lib opengl32.dll` is enough. Would like to help you more, but I didnt need to deal with this shit lately (luckily) and forgot most of this mess.
Jan 14 2016
parent reply Josh Phillips <jjpman71 gmail.com> writes:
On Thursday, 14 January 2016 at 09:42:50 UTC, Dav1d wrote:
 On Thursday, 14 January 2016 at 09:25:50 UTC, Dav1d wrote:
 On Thursday, 14 January 2016 at 02:35:28 UTC, Josh Phillips 
 wrote:
 Welcome to D and Windows. You can use GDC or LDC or try 
 http://wiki.dlang.org/Installing_DMD_on_64-bit_Windows_7_(COFF-compatible)

 Or you find an OMF opengl32.lib OR you make your own with 
 implib and coff2omf
 http://www.digitalmars.com/ctg/implib.html
 http://www.digitalmars.com/ctg/coff2omf.html
 I dont really remember how that worked.
There is also objconv: http://www.agner.org/optimize/ I found in an older code: echo "implib /s opengl32.lib opengl32.dll && exit" | cmd So maybe `implib /s opengl32.lib opengl32.dll` is enough. Would like to help you more, but I didnt need to deal with this shit lately (luckily) and forgot most of this mess.
I actually got it to work by enforcing 64bit. DMD uses the VC Linker in 64bit mode I guess. However I (of course) ran into new errors. Gl functions like glGetString and glGetIntegerv cause the program to crash. It appears that an opengl context is being created so I'm not sure whats causing the problem
Jan 14 2016
parent Josh Phillips <jjpman71 gmail.com> writes:
On Friday, 15 January 2016 at 07:37:27 UTC, Josh Phillips wrote:
 However I (of course) ran into new errors. Gl functions like 
 glGetString and glGetIntegerv cause the program to crash. It 
 appears that an opengl context is being created so I'm not sure 
 whats causing the problem
For anyone else with this issue I finally figured it out. You have to call gladLoadGL AFTER you set the glContext and before you call any gl code.
Jan 15 2016
prev sibling parent reply userABCabc123 <userABCabc123 ab.bc> writes:
On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips 
wrote:
 Oh wow that's easy. They should really make that more clear in 
 the dlang reference. They way it sounds there made me think 
 that if a function doesn't throw any errors it automatically is 
 'nothrow'
No, because actually you can have a function that uses sub-functions that throw, but marked explicitly nothrow, because it hides the stuff under the carpet. --- void bar() { throw new Exception("kaboom"); } void foo() nothrow { try {bar;} catch {/*under the carpet*/} } --- and that will compile.
Jan 13 2016
parent Josh Phillips <jjpman71 gmail.com> writes:
On Thursday, 14 January 2016 at 02:16:40 UTC, userABCabc123 wrote:
 On Wednesday, 13 January 2016 at 19:05:30 UTC, Josh Phillips 
 wrote:
 Oh wow that's easy. They should really make that more clear in 
 the dlang reference. They way it sounds there made me think 
 that if a function doesn't throw any errors it automatically 
 is 'nothrow'
No, because actually you can have a function that uses sub-functions that throw, but marked explicitly nothrow, because it hides the stuff under the carpet. --- void bar() { throw new Exception("kaboom"); } void foo() nothrow { try {bar;} catch {/*under the carpet*/} } --- and that will compile.
Ok? I'm not sure what you are saying no to and I understand this. It makes sense because foo catches bar's error and doesn't throw it up and further. I was just saying that the reference here https://dlang.org/spec/function.html was not all that clear since the section entitled nothrow merely states: "Nothrow functions do not throw any exceptions derived from class Exception. Nothrow functions are covariant with throwing ones." A deeper search on the page made me realize that there are more examples later which clarify how to declare a "nothrow" function however I didn't bother looking deeper at the time since the main section for nothrows gave no indication that I should.
Jan 13 2016