mingw w64 v8.0.0_MinGW+OpenGL

MinGW下面的OpenGL是没有Windows的Window支持的,也就是说,无法处理鼠标、键盘等事件的,如果你使用VS,那么还有可能使用MFC,但是现在使用的工具是MinGW,它没有这样的框架,所以选择使用GLUT,它是Graphics Library Utility Toolkit的缩写。

如果使用GLUT,我下载的已编译的版本非常的古老,是GLUT for Win32,也就是2000年左右的版本,非常古老,而我需要的是X64版本的,非常巧,看见有人介绍FREE GLUT,它是glut的免费版本,而且在GitHub上有2017年测试的例子的代码,也就是如果我能使用freeglut的X64版本,并编译运行它,我就算完成任务了。

Using freeglut or GLUT with MinGW​www.transmissionzero.co.uk
ba85eb0b52914ca38a524009430c649a.png
Setting Up freeglut With MinGW
freeglut is intended to be a 100% compatible replacement for the original GLUT libraries. 兼容、可替换原GLUT库。Unlike GLUT for Win32, freeglut is an up to date and actively maintained project, so I would recommend using freeglut if you have the choice. You can download my freeglut MinGW package (with PGP signature and PGP key), which contains import libraries, headers, and a Windows DLL. Using this, you can either dynamically link against the freeglut DLL,可动态链接, or statically link the library into your application,亦可静态链接.
Once you have downloaded the freeglut MinGW package, create a folder on your PC which is readable by all users, for example “C:Program FilesCommon FilesMinGWfreeglut”. Copy the “lib” and “include” folders from the zip archive to that location. 单独存放头文件和库文件。
The freeglut DLL should either be placed in the same folder as your application,动态链接文件与你的应用程序放在一起吧, or can be installed in a system-wide folder which appears in your %PATH% environment variable(不推荐). On a 32 bit Windows system this is typically “C:WindowsSystem32”, and on a 64 bit Windows system this is typically “C:WindowsSysWOW64”.

e5e84264b29aea61d648bb9107f06853.png

没讲-D,-L选项。

da219400c4a7f19edda5f233a275a092.png

完工。

tasks.json

{
 // See https://go.microsoft.com/fwlink/?LinkId=733558
 // for the documentation about the tasks.json format
 "version": "2.0.0",
 "tasks": [
        {
 "label": "build helloopengl",
 "type": "shell",
 "command": "C:MinGW-W64x86_64-8.1.0-release-win32-seh-rt_v6-rev0mingw64bing++.exe",
 "args": ["-g","-o","helloopengl","helloopengl.cpp","-D FREEGLUT_STATIC","-IC:/freeglut/include","-LC:/freeglut/lib/x64","-lfreeglut_static","-lopengl32","-lwinmm","-lgdi32","-Wl,--subsystem,windows"],
 "group": {
 "kind": "build",
 "isDefault": true
            }
        }
    ]
}

helloopengl.cpp

/*
 * This is a very basic Windows C application for testing GLUT (and compatible
 * implementations such as freeglut). It displays a red square, and exits when
 * the escape key is pressed.
 */
 
#include <stdlib.h>
#include <GL/glut.h>

/* Keyboard callback function */
void keyboard(unsigned char key, int x, int y)
{
 switch (key)
  {
    /* Exit on escape key press */
 case 'x1B':
    {
 exit(EXIT_SUCCESS);
 break;
    }
  }
}

/* Display callback function */
void display()
{
 glClear(GL_COLOR_BUFFER_BIT);

  /* Display a red square */
 glColor3f(1.0f, 0.0f, 0.0f);

 glBegin(GL_POLYGON);
 glVertex2f(-0.5f, -0.5f);
 glVertex2f( 0.5f, -0.5f);
 glVertex2f( 0.5f,  0.5f);
 glVertex2f(-0.5f,  0.5f);
 glEnd();

 glFlush();
}

/* Main method */
int main(int argc, char** argv)
{
 glutInit(&argc, argv);

  /* Create a single window with a keyboard and display callback */
 glutCreateWindow("GLUT Test");
 glutKeyboardFunc(&keyboard);
 glutDisplayFunc(&display);

  /* Run the GLUT event loop */
 glutMainLoop();

 return EXIT_SUCCESS;
}

Debug Output:

=thread-group-added,id="i1"
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <GNU General Public License>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<Bugs in GDB>.
Find the GDB manual and other documentation resources online at:
<GDB Documentation>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
[New Thread 18044.0x465c]

Breakpoint 1, main (argc=1, argv=0x4f2a40) at helloopengl.cpp:45
45	  glutInit(&argc, argv);
Loaded 'C:WindowsSYSTEM32ntdll.dll'. Symbols loaded.
Loaded 'C:Windowssystem32kernel32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32KernelBase.dll'. Symbols loaded.
Loaded 'C:Windowssystem32advapi32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32msvcrt.dll'. Symbols loaded.
Loaded 'C:WindowsSYSTEM32sechost.dll'. Symbols loaded.
Loaded 'C:Windowssystem32rpcrt4.dll'. Symbols loaded.
Loaded 'C:Windowssystem32gdi32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32user32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32lpk.dll'. Symbols loaded.
Loaded 'C:Windowssystem32usp10.dll'. Symbols loaded.
Loaded 'C:Windowssystem32opengl32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32glu32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32ddraw.dll'. Symbols loaded.
Loaded 'C:Windowssystem32dciman32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32setupapi.dll'. Symbols loaded.
Loaded 'C:Windowssystem32cfgmgr32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32oleaut32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32ole32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32devobj.dll'. Symbols loaded.
Loaded 'C:Windowssystem32dwmapi.dll'. Symbols loaded.
Loaded 'C:Windowssystem32winmm.dll'. Symbols loaded.
Loaded 'C:Windowssystem32imm32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32msctf.dll'. Symbols loaded.
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
Loaded 'C:Windowssystem32uxtheme.dll'. Symbols loaded.
=library-unloaded,id="C:Windowssystem32version.dll",target-name="C:Windowssystem32version.dll",host-name="C:Windowssystem32version.dll",thread-group="i1"
[New Thread 18044.0x1ae8]
[New Thread 18044.0x620]
[New Thread 18044.0x2a8c]
[New Thread 18044.0x3188]
[New Thread 18044.0x429c]
Loaded 'C:Windowssystem32ig75icd64.dll'. Symbols loaded.
Loaded 'C:Windowssystem32igdusc64.dll'. Symbols loaded.
Loaded 'C:Windowssystem32cryptbase.dll'. Symbols loaded.
Loaded 'C:Windowssystem32clbcatq.dll'. Symbols loaded.
Loaded 'C:WindowsSYSTEM32imeIMESC5IMSCTIP.dll'. Symbols loaded.
Loaded 'C:WindowsWinSxSamd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18837_none_a4d981ff711297b6comctl32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32imesharedIMETIP.DLL'. Symbols loaded.
Loaded 'C:Windowssystem32imesharedimecfm.dll'. Symbols loaded.
Loaded 'C:WindowsSYSTEM32imeIMESC5ImSCCore.dll'. Symbols loaded.
Loaded 'C:WindowsSYSTEM32imeIMESC5ImSCCfg.DLL'. Symbols loaded.
Loaded 'C:Windowssystem32shell32.dll'. Symbols loaded.
Loaded 'C:Windowssystem32shlwapi.dll'. Symbols loaded.
=library-unloaded,id="C:Windowssystem32imeImesc5PMIGRATE.dll",target-name="C:Windowssystem32imeImesc5PMIGRATE.dll",host-name="C:Windowssystem32imeImesc5PMIGRATE.dll",thread-group="i1"
=library-unloaded,id="C:Windowssystem32userenv.dll",target-name="C:Windowssystem32userenv.dll",host-name="C:Windowssystem32userenv.dll",thread-group="i1"
=library-unloaded,id="C:Windowssystem32profapi.dll",target-name="C:Windowssystem32profapi.dll",host-name="C:Windowssystem32profapi.dll",thread-group="i1"
=library-unloaded,id="C:Windowssystem32imeImesc5PMIGRATE.dll",target-name="C:Windowssystem32imeImesc5PMIGRATE.dll",host-name="C:Windowssystem32imeImesc5PMIGRATE.dll",thread-group="i1"
=library-unloaded,id="C:Windowssystem32userenv.dll",target-name="C:Windowssystem32userenv.dll",host-name="C:Windowssystem32userenv.dll",thread-group="i1"
=library-unloaded,id="C:Windowssystem32profapi.dll",target-name="C:Windowssystem32profapi.dll",host-name="C:Windowssystem32profapi.dll",thread-group="i1"
[New Thread 18044.0x31d8]
[New Thread 18044.0x2fc4]
[New Thread 18044.0x3efc]
[Thread 18044.0x2a8c exited with code 0]
[Thread 18044.0x3188 exited with code 0]
[Thread 18044.0x620 exited with code 0]
[Thread 18044.0x429c exited with code 0]
[Thread 18044.0x2fc4 exited with code 0]
[Thread 18044.0x1ae8 exited with code 0]
[Thread 18044.0x31d8 exited with code 0]
[Inferior 1 (process 18044) exited normally]
The program 'C:projectshelloopenglhelloopengl.exe' has exited with code 0 (0x00000000).

总结:它是如何找到opengl32.lib、winmm.lib、gdi32.lib的?虽然系统安装了SDK,但是我并没有在tasks.json中的命令行的参数中指定这些库文件的路径啊?

4abea309ec5500e1d16239f7437fa97e.png
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值