ubuntu14.04上使用glfw
来源:互联网 发布:广数980g76编程实例 编辑:程序博客网 时间:2024/06/01 09:43
第〇步:
下载glfw:http://www.glfw.org/download.html,下载解压好,暂且成目录名字为 glfw3-3.x.x
ubuntu下安装:sudo apt-get install libglew-dev glew-utils
第一步:编译glfw:
(1): 安装依赖库,sudo
apt-get build-dep glfw, sudo
apt-get install cmake xorg-dev libglu1-mesa-dev
(2):进入 glfw3-3.x.x 目录,建立build子目录, 命令行执行 cmake-gui, 源码目录选择glfw3-3.x.x, 目标目录选择build。 configure,generate
(3): 命令行模式,cd build,执行 make, sudo make install .
第二步:使用glfw(关键)
建立main.cpp, 敲入下面源码:
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace std;
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
const GLuint WIDTH = 800, HEIGHT = 600;
int main()
{
cout << "Starting GLFW context, OpenGL3.3" << endl;
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
if(window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glViewport(0, 0, WIDTH, HEIGHT);
while(!glfwWindowShouldClose(window))
{
glfwPollEvents();
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
glfwTerminate();
return 0;
}
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);
}
编译: g++ -c main.cpp
g++ mian.o -o main.exec -lGL - lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi -lXcursor -lXinerama
编译也可用CmakeLists.txt:
project(OpenGL_1)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
LINK_LIBRARIES(glfw3)
LINK_LIBRARIES(X11)
LINK_LIBRARIES(Xxf86vm)
LINK_LIBRARIES(Xrandr)
LINK_LIBRARIES(pthread)
LINK_LIBRARIES(Xi)
LINK_LIBRARIES(Xcursor)
LINK_LIBRARIES(Xinerama)
LINK_LIBRARIES(GL)
LINK_LIBRARIES(GLU)
add_executable(${PROJECT_NAME} ${SRC_LIST})
- ubuntu14.04 上使用glfw
- ubuntu14.04上使用glfw
- ubuntu14.04上使用virt-manager备忘录
- 在Ubuntu14.04上使用多媒体
- Ubuntu14.04上VNC安装与使用
- GLFW
- Linux: adb 在 Ubuntu14.04 (64bit) 上无法使用
- 在Ubuntu14.04上使用devstack安装OpenStack
- Ubuntu14.04 上使用 Nginx 部署 Flask 应用
- 在ubuntu14.04上使用Android SDK创建模拟失败
- Ubuntu14.04上安装和使用tftp服务
- ubuntu14.04在vmware10上无法使用unity
- 在ubuntu14.04上使用ambari搭建hadoop集群
- 在ubuntu14.04上使用git clone遇到问题
- 在Ubuntu14.04上下载NDK和使用OLLVM混淆
- 使用glfw建立opengl应用程序
- glfw使用固定管线设置
- ubuntu14.04上安装vncserver
- jQueryUI-autocomplete的使用
- idea配置maven
- 浅谈动态规划(三)
- C++11老关键字的新含义(auto, using,extern)
- 程序的调用机制及目标文件有什么
- ubuntu14.04上使用glfw
- CPUFreq驱动随笔(一)
- 页面置换算法及磁盘调度算法
- yii2.0目录结构
- 【Luogu】 P1726 上白泽慧音
- 零基础学习wince开发-环境搭建
- A1014. Waiting in Line (30)
- HTTP协议详解
- 数据库范式那些事