Hello, Computer Graphics (MinGW)
来源:互联网 发布:ftp默认端口号 编辑:程序博客网 时间:2024/05/14 16:29
今天终于开始了计算机图形学的学习,首先先配置一下环境。我本人不大喜欢使用复杂的IDE(Visual Studio 之类),我比较喜欢使用 Editor + Compiler 这样的组合,比较轻量。今天来谈谈如何避开Visual Studio,直接使用MinGW配置OpenGL。
[Warning] 姿势水平限定: 使用 gcc 进行编译、连接。
如果你没有听说过 gcc , 那么请不要继续往下阅读。
安装
首先下载FreeGlut For MinGW。
里面除了根目录下的俩说明文档,大概是这样一个目录结构
├─bin│ │ freeglut.dll│ ││ └─x64│ freeglut.dll│├─include│ └─GL│ freeglut.h│ freeglut_ext.h│ freeglut_std.h│ glut.h│└─lib │ libfreeglut.a │ libfreeglut_static.a │ └─x64 libfreeglut.a libfreeglut_static.a
首先,把这三个目录直接解压到你项目的目录1下。
然后就没有然后了,安装已经结束了。
编码
本文先不纠结于编码,请在项目根目录新建一个main.c
├─main.c├─bin│ └─x64├─include│ └─GL└─lib └─x64
并在里面粘贴以下代码
#include <stdlib.h>#include <GL/glut.h>void keyboard(unsigned char key, int x, int y);void display(void);int main(int argc, char** argv){ glutInit(&argc, argv); glutCreateWindow("GLUT Test"); glutKeyboardFunc(&keyboard); glutDisplayFunc(&display); glutMainLoop(); return EXIT_SUCCESS;}void keyboard(unsigned char key, int x, int y){ switch (key) { case '\x1B': exit(EXIT_SUCCESS); break; }}void display(){ glClear(GL_COLOR_BUFFER_BIT); 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();}
好的,保存一下,接下来开始编译-连接。
编译-连接
打开命令行,定位到项目根目录。
如果你使用64位系统: $ gcc -o bin\x64\main.exe main.c -I"include" -L"lib\x64" -lfreeglut -lopengl32 -Wl,--subsystem,windows
如果你使用32位系统: $ gcc -o bin\main.exe main.c -I"include" -L"lib" -lfreeglut -lopengl32 -Wl,--subsystem,windows
其中,”include”, “lib”, “lib/x64” 均为相对路径(相对于命令行当前定位),当然你也可以使用绝对路径。
如果没有问题,bin
目录下会出现一个main.exe
,可以尝试运行之。
在运行 main.exe 时,它会去它所在的目录找
freeglut.dll
文件,如果找不到或者版本不对,它会闪退。
运行
64位: $ bin\x64\main.exe
32位: $ bin\main.exe
大功告成!
- 并不一定是项目的目录下,你可以有其他的方法:例如将合适的bin文件放在环境变量里,将include中的文件扔到gcc的标准库内,将lib中的文件放到windows的标准库内……等等,但是在本文中会使用一种更为普遍的方式。 ↩
- Hello, Computer Graphics (MinGW)
- Mathematics for Computer Graphics
- Sprite in computer graphics
- Mathematics for Computer Graphics
- Mathematics for Computer Graphics
- Mathematics for Computer Graphics
- mathmetics for computer graphics
- Mathematics for Computer Graphics
- Computer Graphics会议
- Computer Graphics Research Software
- Computer Graphics-January 12
- Mathematics for Computer Graphics
- hdoj4716A Computer Graphics Problem
- 随便说一说computer graphics
- Computer Graphics, Computer vision and Image processing
- good Links of Computer Graphics
- Rendering (computer graphics)---From Wikipedia
- Computer Graphics for Java Programmers
- 进程间通信方式(全)
- Leetcode 87. Scramble String
- 发表在science 上的一种新的聚类算法
- java在线支付
- 安卓开发:提供ListView效率,实现双击回到顶部,删除子项
- Hello, Computer Graphics (MinGW)
- iOS开发之本地通知UILocalNotification
- 七牛镜像加速配置说明
- android_属性动画
- unity3d 最新5.0 AssetBundles用法
- GreenDao详解
- word2vec的数学原理详解
- Java打印杨辉三角
- 中介者模式