GLFW+GLEW搭建opengl环境(备忘)
使用VS2017社区版本(免费版)
下载GLFW和GLEW源码。
使用CMAKE生成工程文件
打开右击GLFW和GLEW项目编译
GLFW默认是静态库
编译GLEW时调整为静态库。将生成的lib和源码中的include文件夹放好,新建空的C++项目。在项目属性设置好路径。



opengl32.lib包含在window sdk 10中了。不需要单独编译。

为了支持中文需要使用UTF-8无bom编码。测试代码如下。
#include <iostream>
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
#include <Windows.h>
// GLFW
#include <GLFW/glfw3.h>
#pragma comment(lib,"winmm.lib") // 告诉连接器与这个库连接,因为我们要播放多媒体声音
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
//#define DEBUG
// Function prototypes
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode); // Window dimensions
const GLuint WIDTH = , HEIGHT = ; // The MAIN function, from here we start the application and run the game loop
//#ifdef DEBUG
//int main()
//#else
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
//#endif
int main()
{
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
// Init GLFW
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, );
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, );
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Create a GLFWwindow object that we can use for GLFW's functions
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT,"墨迹",nullptr, nullptr);
if (window == nullptr)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -;
}
glfwMakeContextCurrent(window);
// Set the required callback functions
glfwSetKeyCallback(window, key_callback);
// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
glewExperimental = GL_TRUE;
// Initialize GLEW to setup the OpenGL Function pointers
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize GLEW" << std::endl;
return -;
} // Define the viewport dimensions
glViewport(, , WIDTH, HEIGHT); // Game loop
while (!glfwWindowShouldClose(window))
{
// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents(); // Render
// Clear the colorbuffer
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); // Swap the screen buffers
glfwSwapBuffers(window);
Sleep();
} // Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return ;
} // Is called whenever a key is pressed/released via GLFW
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
std::cout << key << std::endl;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
效果如下

程序400kb,无需动态库。

单独一个程序的话会比动态库要小。
GLFW+GLEW搭建opengl环境(备忘)的更多相关文章
- 基于OpenGL编写一个简易的2D渲染框架-02 搭建OpenGL环境
由于没有使用GLFW库,接下来得费一番功夫. 阅读这篇文章前请看一下这个网页:https://learnopengl-cn.github.io/01%20Getting%20started/02%20 ...
- Windows10+VS2017 用GLFW+GLAD 搭建OpenGL开发环境
本文参考:https://learnopengl-cn.github.io/ 一 下载GLFW(https://www.glfw.org/download.html) 和 GLAD(https:// ...
- 搭建OpenGL环境-Windows/VS2013
对于opengl的环境,简单搭建的话其实和opencv差不多,你会看到下面的过程与opencv类似,不同的就是某些文件需要自己找(因为不是集成的,各个拓展需要单独下载) 1.首先,对于opengl头文 ...
- vs2012搭建OpenGL环境
1. 下载glut库 glut库地址为:http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip glut全称为:OpenGL ...
- IOS 中openGL使用教程1(openGL ES 入门篇 | 搭建openGL环境)
OpenGL版本 iOS系统默认支持OpenGl ES1.0.ES2.0以及ES3.0 3个版本,三者之间并不是简单的版本升级,设计理念甚至完全不同,在开发OpenGL项目前,需要根据业务需求选择合适 ...
- ubuntu下搭建openGL环境
1. 建立基本编译环境 sudo apt-get install build-essential 2. 安装OpenGL Library sudo apt-get install ...
- iOS-----openGL--openGL ES iOS 入门篇--->搭建openGL环境
OpenGL版本 iOS系统默认支持OpenGl ES1.0.ES2.0以及ES3.0 3个版本,三者之间并不是简单的版本升级,设计理念甚至完全不同,在开发OpenGL项目前,需要根据业务需求选择合适 ...
- TF版网络模型搭建常用代码备忘
本文主要介绍如何搭建一个网络并训练 最近,我在写代码时经常碰到这样的情况,明明记得代码应该怎么写,在写出来的代码调试时,总是有些小错误.原因不是接口参数个数不对,就是位置不对.为了节约上网查找时间,现 ...
- Ubuntu下使用Docker搭建MySQL步骤备忘
docker 安装和 pull MySQL镜像这里就不介绍了,很多介绍,建议去docker官方网站查看. 本文主要介绍MySQL container 运行起来之后的一些配置 在往下看之前,确保 doc ...
随机推荐
- 基于VUE实现的新闻后台管理系统-一
基于VUE实现的新闻后台管理系统 前段时间拿到一个关于新闻后台的API,测试数据库使用SQLite,Restful服务是用Go写的,只要运行特定环境下的脚本(run.*)就会启动一个服务,依次后台为接 ...
- 浅谈网络I/O多路复用模型 select & poll & epoll
http://blog.csdn.net/nk_test/article/details/50662946
- Java虚拟机性能监控与调优实战
From: https://c.m.163.com/news/a/D7B0C6Q40511PFUO.html?spss=newsapp&fromhistory=1 Java虚拟机性能监控与调 ...
- ColorCode是一个在线随机取色工具,可以随机获取十六进制、RGB、HSl等颜色。
ColorCode是一个在线随机取色工具,可以随机获取十六进制.RGB.HSl等颜色. ColorCode 彩蛋爆料直击现场 ColorCode是一个在线随机取色工具,可以随机获取十六进制.RGB.H ...
- InnoExtractor可以解压一些安装文件,以获得其中的特殊文件
you can use InnoExtractor unpack the installer file and get uniSimpleEnc.dcu file. https://www.board ...
- Python 爬虫从入门到进阶之路(八)
在之前的文章中我们介绍了一下 requests 模块,今天我们再来看一下 Python 爬虫中的正则表达的使用和 re 模块. 实际上爬虫一共就四个主要步骤: 明确目标 (要知道你准备在哪个范围或者网 ...
- 【协议】TCP与UDP
转载地址:https://blog.csdn.net/qq_34988624/article/details/85856848 1.为什么会有TCP/IP协议 在世界上各地,各种各样的电脑运行着各自不 ...
- 【Netty整理03-NIO】Java 实现 NIO demo
jdk提供的NIO使用: 概览:https://blog.csdn.net/the_fool_/article/details/83000648 博主抄写了网上的demo,略作修改与调整,原文链接: ...
- 【Netty整理02-详细使用】Netty入门
重新整理版:https://blog.csdn.net/the_fool_/article/details/83002152 参考资料: 官方文档:http://netty.io/wiki/user- ...
- Maven版本管理-Maven Release Plugin插件
一.什么是版本管理 首先,这里说的版本管理(version management)不是指版本控制(version control),但是本文假设你拥有基本的版本控制的知识,了解subversion的基 ...