mingw 编译 glfw3 的 helloworld
glfw3 为基础开发 GUI 似乎是一个不错选项,有很多人尝试这么做了。今天也小试一把。
工具: mingw(不是 mingw-w64),头文件 GLFW/ ,库文件 glfw3.dll
需要注意,mingw-w64 的话,glfw3.dll 版本要匹配。需要用 mingw-w64 重新编译?
openGL 基本上 windows 都已经有安装了,不需要额外安装。(确认 C:\Windows\System32\opengl32.dll 存在)
代码:
#include "GLFW/glfw3.h" int main(void)
{
GLFWwindow* window; /* Initialize the library */
if (!glfwInit())
return -; /* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(, , "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -;
} /* Make the window's context current */
glfwMakeContextCurrent(window); /* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT); /* Swap front and back buffers */
glfwSwapBuffers(window); /* Poll for and process events */
glfwPollEvents();
} glfwTerminate();
return ;
}
编译指令:
gcc test.c glfw3.dll -lopengl32
第一次编译的时候,因为没有添加 -lopengl32,一直报错,找了好久:
undefined reference to `__imp_glClear'
添加 -lopengl32 之后就没问题了。
=========================================
另外还有两个使用 glad 来载入 openGL 的例子。可以看下面:
=========================================
关于 windows 下 openGL/GLFS/glu 会默认打开一个 cmd console,可以参考这个这里:
https://stackoverflow.com/questions/5995433/removing-console-window-for-glut-freeglut-glfw
我选取的是 FreeConsole() 这个方案,不过,需要在所有 include 的最前面添加 #include <Winsock2.h>。这个方案其实是在程序开始之初,直接把 console 释放掉,所以启动 GUI 程序时,会有黑影一闪而过。
=========================================
GLFS+IMGUI 的一个 demo :https://github.com/urddru/imgui-glfw
项目使用 cmake 来编译,可能需要小改点编译规则,需要 cmake 基础。
最新文章
- shell编程
- SharePoint开发——利用CSOM逐级获取O365中SharePoint网站的List内容
- Oracle rowid
- Leetcode_Best Time to Buy and Sell Stock
- WINDOWS 下搭建 OC 集成开发环境
- Qt5 多显示器获取不同显示器的分辨率和位置的方法
- DevExpress.XtraReports.UI.XtraReport 动态报表
- UVa 990 - Diving for Gold
- Android通过Apk插件调起微信支付
- LINUX:alias命令详解
- linux 更改用户的默认shell
- DBUS基础知识
- 配置使用dwr完成收邮件提示
- [JavaScript]ECMA-6 箭头函数
- 完美解决cannot resolve symbol servlet 的报错
- 华为交换机以 LACP 模式实现链路聚合
- MySQL高级知识系列目录
- laravel发布订阅
- yii2 对象跟数组输出数据到view视图方法
- SQL--数据库--基本操作
热门文章
- Vue axios异步获取后台数据alert提示undefined
- python的multitask模块安装
- python中列表(list)函数及使用
- 重新学习Spring注解——servlet3.0
- 循环递减算法 [a,b,c] 求 ab,ac,bc
- 接口测试中,数据驱动时,参数各类型,空或None的处理
- VIJOS-P1282 佳佳的魔法照片
- Winform 弹框增加确定按钮并点击确定后进行下一步操作
- 用ant.design的设计注意点---表单
- Oracle EBS 11i x86-64 的预安装