FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some link errors

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Wed Feb 20, 2008 12:58 pm    Post subject: Some link errors Reply with quote

I am using Derelict for the openGL wrapper. I am trying to render opengl in a MFC device context, but some functions are missing.
I saw on some sites that those methodes are implemented in openGL normaly.

I want to know how you procede to bind methods in our openGL libs, to be able to add those methodes manualy.

Code:

C:\D\Projects\HelloWorld\Main.obj(Main)
 Error 42: Symbol Undefined _wglMakeCurrent@8
C:\D\Projects\HelloWorld\Main.obj(Main)
 Error 42: Symbol Undefined _wglDeleteContext@4
C:\D\Projects\HelloWorld\Main.obj(Main)
 Error 42: Symbol Undefined _ZeroMemory@8
C:\D\Projects\HelloWorld\Main.obj(Main)
 Error 42: Symbol Undefined _wglCreateContext@4
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Wed Feb 20, 2008 9:48 pm    Post subject: Reply with quote

UPDATE: Sorry, what I posted here earlier was nonsense. The wgl* functions can all be found in derelict.opengl.wgl. Just import that module and those link errors should disappear.

FYI, ZeroMemory is implemented as a macro in the Windows C header, not a function. In Tango, it is implemented in sys.win32.Macros as a wrapper for memset. In Phobos, it isn't implemented at all. Just use the standard C function memset in its place.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Thu Feb 21, 2008 5:19 pm    Post subject: Reply with quote

Thx for your precious help.

I have correct the ZeroMemory error with the simple replacement by memset like you said and the add of :
Code:

private extern(C) { void* memset(void*, uint, uint); }


The wgl* are always missing, I add the import like that :
Code:

import derelict.opengl.wgl;


The definition works there are present in my wgl.d file.

I think that something stay wrong in my DerelictGL.lib, or I may add an other lib for the linker.

My compilation commands (write by poseidon)
Code:

C:\D\dmd\bin\dmd.exe  C:\D\Projects\HelloWorld\Main.obj -ofHelloWorld -IC:\D\dm\lib;C:\D\dmd\src\ext C:\D\dm\lib\gdi32.lib C:\D\dm\lib\kernel32.lib C:\D\Libs\Derelict\lib\DerelictGL.lib C:\D\Libs\Derelict\lib\DerelictUtil.lib -O -release -L/SUBSYSTEM:windows:4

C:\D\dmd\bin\..\..\dm\bin\link.exe C:\D\Projects\HelloWorld\Main,HelloWorld,,C:\D\dm\lib\gdi32.lib+C:\D\dm\lib\kernel32.lib+C:\D\Libs\Derelict\lib\DerelictGL.lib+C:\D\Libs\Derelict\lib\DerelictUtil.lib+user32+kernel32/noi/SUBSYSTEM:windows:4;
Back to top
View user's profile Send private message
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Thu Feb 21, 2008 5:39 pm    Post subject: Reply with quote

I think that the probleme is those functions are declared like private.

I have to add those lines for having the correct definitions :
Code:

private extern(Windows) { BOOL wglMakeCurrent(HDC,HGLRC); }
private extern(Windows) { BOOL wglDeleteContext(HGLRC); }
private extern(Windows) { HGLRC wglCreateContext(HDC); }


May I wrap those functions like this delerict function ? :
Code:

DerelictGLContext getCurrentContext()
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Thu Feb 21, 2008 9:17 pm    Post subject: Reply with quote

flamaros wrote:

I have correct the ZeroMemory error with the simple replacement by memset like you said and the add of :
Code:

private extern(C) { void* memset(void*, uint, uint); }


You don't need to do that. If you are using Phobos, memset is declared in std.c.string. In Tango, it is in tango.stdc.string.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Thu Feb 21, 2008 9:27 pm    Post subject: Reply with quote

flamaros wrote:
I think that the probleme is those functions are declared like private.


I don't understand. In derelict.opengl.wgl, these functions are all public.

[quote]
I have to add those lines for having the correct definitions :
Code:

private extern(Windows) { BOOL wglMakeCurrent(HDC,HGLRC); }
private extern(Windows) { BOOL wglDeleteContext(HGLRC); }
private extern(Windows) { HGLRC wglCreateContext(HDC); }

[quote]

You should not need to do this at all, and it actually shouldn't work since you aren't linking to opengl32.lib. Importing derelict.opengl.wgl should be enough. What error(s) are you getting when you do so? Are you calling DerelictGL.load before attempting to call these functions? The wgl* functions reside in opengl32.dll, which Derelict loads when you call DerelictGL.load. If you do not call that first, the function pointers will be null and an access violation will occur if you attempt to call them.


Quote:

May I wrap those functions like this delerict function ? :
Code:

DerelictGLContext getCurrentContext()


You can do whatever you like, but that's not going to help your current problem. That specific wrapper method is just to provide a common interface for obtaining the context on multiple platforms and was intended to be used to help DerelictGL manage context switching internally, something that was never implemented. It actually serves no purpose at the moment.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Fri Feb 22, 2008 1:42 pm    Post subject: Reply with quote

I am getting those errors when I just use the import of wgl lib.

Code:

*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
wglDeleteContext( hRC );

C:\D\Projects\HelloWorld\Sources\Main.d(181): Error: cannot implicitly convert expression (*hDC) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(181): Error: cannot implicitly convert expression ((*wglCreateContext)(*hDC)) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(182): Error: cannot implicitly convert expression (*hDC) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(182): Error: cannot implicitly convert expression (*hRC) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(190): Error: cannot implicitly convert expression (hRC) of type HANDLE to HANDLE


The call of DerelictGL.load(); is the first line in my main() function.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Fri Feb 22, 2008 7:06 pm    Post subject: Reply with quote

flamaros wrote:
I am getting those errors when I just use the import of wgl lib.

Code:

*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
wglDeleteContext( hRC );

C:\D\Projects\HelloWorld\Sources\Main.d(181): Error: cannot implicitly convert expression (*hDC) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(181): Error: cannot implicitly convert expression ((*wglCreateContext)(*hDC)) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(182): Error: cannot implicitly convert expression (*hDC) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(182): Error: cannot implicitly convert expression (*hRC) of type HANDLE to HANDLE
C:\D\Projects\HelloWorld\Sources\Main.d(190): Error: cannot implicitly convert expression (hRC) of type HANDLE to HANDLE


The call of DerelictGL.load(); is the first line in my main() function.


For starters, these are type conversion errors. Any time you see an error that begins with 'cannot implicitly convert expression', you can fix it with a simple cast. But it looks like the root of your problem is something else.

Have you declared hRC and hDC as pointers? They should not be and you should not be using the pointer dereference syntax (such as *hRC and *hDC) in calling the wgl functions. Your declarations and calls should look like this:

Code:

// assuming that HDC and HGLRC are aliased to HANDLE
HDC hDC;
HGLRC hRC;

hRC = wglCreateContext( hDC );
wglMakeCurrent( hDC, hRC );
wglDeleteContext( hRC );


If you are still having problems with this, I'll need more info to help you:

Are you using Phobos or Tango?

Show me your declarations of hDC and hRC.

Have you declared HANDLE/HDC/HGLRC yourself or are you getting them from Phobos, Tango or somewhere else? If you've declared them yourself, show me the declarations.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Sat Feb 23, 2008 5:06 am    Post subject: Reply with quote

I give you all my code. I am using phobos, and I don't have declared HANDLE/HDC/HGLRC types myself. Thx a lot for your precious help, starting with D can be little Hard.

Quote:

import std.c.windows.windows;
import std.c.stdio;
import std.c.string;
//import c.gl.gl;

import derelict.opengl.wgl;
import derelict.opengl.gl;

//private extern(C) { void* memset(void*, uint, uint); }

//private extern(Windows) { BOOL wglMakeCurrent(HDC,HGLRC); }
//private extern(Windows) { BOOL wglDeleteContext(HGLRC); }
//private extern(Windows) { HGLRC wglCreateContext(HDC); }

const int PFD_DRAW_TO_WINDOW = (0x4);
const int PFD_SUPPORT_OPENGL = (0x20);
const int PFD_DOUBLEBUFFER = (0x1);
const int PFD_TYPE_RGBA = (0);
const int PFD_MAIN_PLANE = (0);

extern(Windows)
int WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage( 0 );
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch ( wParam )
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:
return DefWindowProcA( hWnd, message, wParam, lParam );
}
}

/**********************************************************/

/* Note the similarity of this code to the console D startup
* code in \dmd\src\phobos\dmain2.d
* You'll also need a .def file with at least the following in it:
* EXETYPE NT
* SUBSYSTEM WINDOWS
*/

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

extern(Windows)
{
void DestroyWindow(HANDLE);
BOOL SwapBuffers(HDC);
// void ZeroMemory(PVOID, size_t);
int ChoosePixelFormat(HDC, PIXELFORMATDESCRIPTOR*);
// HGLRC wglCreateContext(HDC);
// BOOL wglMakeCurrent(HDC, HGLRC);
// BOOL wglDeleteContext(HGLRC);
}


void main()
{
DerelictGL.load();
gc_init(); // initialize garbage collector
_minit(); // initialize module constructor table

WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL quit = FALSE;
float theta = 0.0f;
HINSTANCE hInstance = GetModuleHandleA(null);

// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = &WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIconA( null, IDI_APPLICATION );
wc.hCursor = LoadCursorA( null, IDC_ARROW );
// wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = null;
wc.lpszClassName = "GLSample";
RegisterClassA( &wc );

// create main window
hWnd = CreateWindowA(
"GLSample", "OpenGL Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 256, 256,
null, null, hInstance, null );

// enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC );

// program main loop
while ( !quit )
{
// check for messages
if ( PeekMessageA( &msg, null, 0, 0, PM_REMOVE ) )
{
// handle or dispatch messages
if ( msg.message == WM_QUIT )
{
quit = TRUE;
}
else
{
TranslateMessage( &msg );
DispatchMessageA( &msg );
}
}
else
{
// OpenGL animation code goes here
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );

glPushMatrix();
glRotatef( theta, 0.0f, 0.0f, 1.0f );
glBegin( GL_TRIANGLES );
glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
glEnd();
glPopMatrix();

SwapBuffers( hDC );

theta += 1.0f;
}
}

// shutdown OpenGL
DisableOpenGL( hWnd, hDC, hRC );

// destroy the window explicitly
DestroyWindow( hWnd );
return msg.wParam;
}

// Enable OpenGL

void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int format;

// get the device context (DC)
*hDC = GetDC( hWnd );

// set the pixel format for the DC
//ZeroMemory( &pfd, pfd.sizeof );
memset(&pfd, 0, pfd.sizeof);
pfd.nSize = pfd.sizeof;
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, format, &pfd );

// create and enable the render context (RC)
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}

// Disable OpenGL

void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent( null, null );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sun Feb 24, 2008 10:29 pm    Post subject: Reply with quote

OK, it looks like this is a side-effect of Derelict declaring some Win32 types internally while publicly exposing the functions that use them. You should be able to eliminate these particular errors by inserting some casts to HANDLE like so:

Code:

*hRC cast(HANDLE) = wglCreateContext(cast(HANDLE) *hDC );
wglMakeCurrent( cast(HANDLE)*hDC, cast(HANDLE)*hRC );
wglDeleteContext( cast(HANDLE)hRC );


That's a little clunky and inconvenient, but it's the best solution I can offer for now.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Tue Feb 26, 2008 12:21 pm    Post subject: Reply with quote

It doesn't change anything, I have always same errors
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Tue Feb 26, 2008 10:55 pm    Post subject: Reply with quote

I have modified wgl.d in Derelict such that the wgl* functions no longer use HDC or HGLRC declarations. They now are declared with void* instead. I've tested locally and this fixes the conflict. So you can remove most of the casts to HANDLE that I suggested. However, you'll still need one cast on this line:

Code:

// create and enable the render context (RC)
*hRC = cast(HANDLE)wglCreateContext( *hDC );


So if you pull down the latest Derelict trunk you'll get the fixes and your code will compile. However, it will not execute properly as written. I don't have the time to debug it though. You might want to take it to #D in IRC if you can't get it working.

Some advice: you don't need to call gc_init or _minit if you aren't using WinMain. When you use a main method, those functions are called automatically by the bootstrap code inside Phobos. You can remove all of these prototypes if you are going to use a main method:

Code:

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();


If you do decide to use WinMain as your entry point, you'll need to call all of those methods, not just gc_init and _minit (though _moduleUnitTests is optional).

Also, for future reference, you aren't using MFC but are using the WIN32 API.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
flamaros



Joined: 02 Feb 2008
Posts: 33

PostPosted: Wed Feb 27, 2008 2:29 pm    Post subject: Reply with quote

It works fine, thank a lot for your help and your advices.

I know that MFC are different than the Win32 API but for a lot people Win32 API can't creates windows, and I don't want to understant "It's easiest to use SDL or something else".

I am learning D just for fun, I have all my time. Unlike of my work where I have more time constraints, especially since everyone knows that video games are always late. Laughing


I wish you best.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group