【问题标题】:using mingw to cross-compile an opengl app for windows使用mingw为windows交叉编译opengl应用程序
【发布时间】:2009-10-05 20:05:35
【问题描述】:

嘿嘿,我正在运行 linux (ubuntu),

我遇到了一些麻烦。我已经尝试下载 glut32.dll 并将其粘贴在 mingw 的 lib/ 目录中,并在 include/ 中设置适当的头文件,但是 - 尽管编译很好 - 链接器在查找符号时遇到了严重问题。

我该怎么做呢?如何使用 mingw 为 windows 构建 opengl 应用程序?

谢谢,

【问题讨论】:

  • 几个月前我也尝试为我的图形课这样做。我尝试了所有我能想到的东西,但始终无法解决链接器问题。我最后只是用微软的编译器编译它,它工作得很好。

标签: opengl mingw cross-compiling


【解决方案1】:

在 Windows 世界中,要将某些内容链接到 DLL,您需要一个“导入库”。您可以将这些视为带有暴露 DLL 符号的存根函数的静态库。你需要寻找libglut32.a。

如果你找不到,甚至可能在 Internet 上的某个地方有一个 Visual C++ 到 mingw 导入库转换工具......(我需要这样的东西已经有一段时间了,所以也许我只是梦想着那部分上。)

【讨论】:

    【解决方案2】:

    实际上,你甚至不需要 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多