2009-10-05 64 views
3

heya,我正在運行的Linux(Ubuntu的),使用mingw交叉編譯一個opengl應用程序的窗口

我遇到了一些麻煩。我試過下載glut32.dll,並將其粘貼在mingw的lib /目錄下,然後在include /中設置適當的頭文件 - 儘管編譯沒問題 - 鏈接器在查找符號時遇到了嚴重問題。

我該如何去做這件事?我如何使用mingw爲windows創建一個opengl應用程序?

感謝,

+0

我在幾個月前爲我的圖形類嘗試過這樣做。我嘗試了所有我能想到的事情,但永遠無法解決鏈接器問題。我最終只是用微軟的編譯器編譯它,它工作得很好。 – 2009-10-05 20:22:51

回答

2

在Windows世界,一些鏈接到一個DLL,你需要一個「導入庫」。你可以將它們看作靜態庫,並帶有可以暴露DLL符號的存根函數。你需要尋找libglut32.a。

如果你找不到那個,甚至可能會有一個Visual C++來在互聯網上的某個地方使用導入庫轉換工具...(這已經有一段時間了,因爲我需要這樣的東西,所以也許我只是夢想着)

+0

謝謝:)即時到達那裏,使用這種方法:) – horseyguy 2009-10-07 21:52:38

0

實際上,你甚至不需要GLUT,它已經存在,只需要鏈接到libopengl32.a,它會將可執行文件鏈接到系統上的本地opengl32.dll。

typedef struct RENDER_SURFACE { 
    void (*redraw)(struct RENDER_SURFACE*); 
    HWND hWnd; 
    HINSTANCE hInstance; 
    HDC hdc; 
    HGLRC hrc; 
    int width; 
    int height; 
    int pix_fmt; 
    float light_position[4]; 
    float light_ambient[4]; 
    float light_diffuse[4]; 
    float light_specular[4]; 
    float light_shininess; 
} RENDER_SURFACE; 

static LRESULT AppProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
{ 
    RENDER_SURFACE* rs = (RENDER_SURFACE*)GetWindowLongPtr(hWnd, GWLP_USERDATA); 
    if (uMsg == WM_CREATE) 
    { 
     RECT rc; 
     PIXELFORMATDESCRIPTOR pfd; 
     rs = (RENDER_SURFACE*)((LPCREATESTRUCT)lParam)->lpCreateParams; 
     SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)rs); 
     rs->hWnd = hWnd; 
     rs->hdc = GetDC(hWnd); 
     GetClientRect(hWnd, &rc); 
     rs->width = rc.right-rc.left; 
     rs->height = rc.bottom-rc.top; 
     memset(&pfd, 0, sizeof(pfd)); 
     pfd.nSize = sizeof(pfd); 
     pfd.nVersion = 1; 
     pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL; 
     pfd.cColorBits = 24; 
     pfd.cDepthBits = 32; 
     rs->pix_fmt = ChoosePixelFormat(rs->hdc, &pfd); 
     if (!rs->pix_fmt) 
     { 
      MessageBox(hWnd, "ChoosePixelFormat FAILED!", "Fatal Error", MB_OK | MB_ICONSTOP); 
      DestroyWindow(hWnd); 
      return -1; 
     } 
     SetPixelFormat(rs->hdc, rs->pix_fmt, &pfd); 
     rs->hrc = wglCreateContext(rs->hdc); 
     wglMakeCurrent(rs->hdc, rs->hrc); 
     /* SwapBuffers(rs->hdc); */ 
     return 0; 
    } 
    else if (uMsg == WM_PAINT) 
    { 
     /* other stuffs */ 
    } 
    return DefWindowProc(hWnd, uMsg, wParam, lParam); 
} 
相關問題