代码之家  ›  专栏  ›  技术社区  ›  horseyguy

使用mingw交叉编译windows的opengl应用程序

  •  3
  • horseyguy  · 技术社区  · 16 年前

    呵呵,我在运行linux(ubuntu),

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

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

    谢谢

    2 回复  |  直到 15 年前
        1
  •  2
  •   asveikau    16 年前

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

    如果你找不到,甚至可能有一个VisualC++来导入导入库转换工具在互联网上的某个地方…(我已经有一段时间不需要这样的东西了,所以也许我只是梦见了那部分。)

        2
  •  0
  •   user1950676    8 年前

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