Linux 在 Ubuntu 中学习 OpenGL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/859501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Learning OpenGL in Ubuntu
提问by victor
I'm trying to learn OpenGLand improve my C++ skills by going through the Nehe guides, but all of the examples are for Windows and I'm currently on Linux. I don't really have any idea how to get things to work under Linux, and the code on the site that has been ported for Linux has way more code in it that's not explained (so far, the only one I've gotten to work is the SDLexample: http://nehe.gamedev.net/data/lessons/linuxsdl/lesson01.tar.gz). Is there any other resource out there that's a bit more specific towards OpenGL under Linux?
我正在尝试通过阅读Nehe 指南来学习OpenGL并提高我的 C++ 技能,但所有示例都适用于 Windows,而我目前使用的是 Linux。我真的不知道如何让事情在 Linux 下工作,并且站点上为 Linux 移植的代码中有更多的代码没有解释(到目前为止,我唯一得到的工作是SDL示例:http: //nehe.gamedev.net/data/lessons/linuxsdl/lesson01.tar.gz)。有没有其他资源更具体地针对 Linux 下的 OpenGL?
采纳答案by Ned Bingham
The first thing to do is install the OpenGL libraries. I recommend:
首先要做的是安装 OpenGL 库。我建议:
freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev
Once you have them installed, link to them when you compile:
安装它们后,在编译时链接到它们:
g++ -lglut -lGL -lGLU -lGLEW example.cpp -o example
In example.cpp, include the OpenGL libraries like so:
在 example.cpp 中,包含 OpenGL 库,如下所示:
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
Then, to enable the more advanced opengl options like shaders, place this after your glutCreateWindow Call:
然后,要启用更高级的 opengl 选项(如着色器),请将其放在 glutCreateWindow 调用之后:
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "Error %s\n", glewGetErrorString(err));
exit(1);
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
if (GLEW_ARB_vertex_program)
fprintf(stdout, "Status: ARB vertex programs available.\n");
if (glewGetExtension("GL_ARB_fragment_program"))
fprintf(stdout, "Status: ARB fragment programs available.\n");
if (glewIsSupported("GL_VERSION_1_4 GL_ARB_point_sprite"))
fprintf(stdout, "Status: ARB point sprites available.\n");
That should enable all OpenGL functionality, and if it doesn't, then it should tell you the problems.
这应该启用所有 OpenGL 功能,如果没有,那么它应该会告诉您问题。
回答by Gaston
Maybe you would like to use Qt to draw the windows and widgets.
也许您想使用 Qt 来绘制窗口和小部件。
Here's a tutorial based on the Nehe guides to show you how to create OpenGL images with Qt.
这是一个基于 Nehe 指南的教程,向您展示如何使用 Qt 创建 OpenGL 图像。
To learn OpenGL, the OpenGL Red Bookis a must read. There's an online version. It has very good explanations and examples.
要学习 OpenGL,必须阅读OpenGL 红皮书。有一个在线版本。它有很好的解释和例子。
回答by Ben
I'll guess that it is the compilation process that is the biggest difference initially. Here is a useful Makefilefor compiling simple OpenGL apps on Ubuntu.
我猜最初最大的区别是编译过程。这是一个有用的Makefile,用于在 Ubuntu 上编译简单的 OpenGL 应用程序。
INCLUDE = -I/usr/X11R6/include/
LIBDIR = -L/usr/X11R6/lib
FLAGS = -Wall
CC = g++ # change to gcc if using C
CFLAGS = $(FLAGS) $(INCLUDE)
LIBS = -lglut -lGL -lGLU -lGLEW -lm
All: your_app # change your_app.
your_app: your_app.o
$(CC) $(CFLAGS) -o $@ $(LIBDIR) $< $(LIBS) # The initial white space is a tab
Save this to a file called Makefilethat should be in the same directory. Compile by writing make from terminal or :makefrom Vim.
将其保存到应位于同一目录中的名为Makefile的文件中。通过从终端编写make 或从 Vim编写:make 进行编译。
Good luck
祝你好运
回答by Karl Adler
a little update for the makefile because I found this old answers from @Millthorn and it didn't worked: you dont need to definde the include path since it's in standard lib https://stackoverflow.com/a/2459788/1059828
makefile 的一些更新,因为我从@Millthorn 找到了这个旧答案,但它没有用:您不需要定义包含路径,因为它在标准库中https://stackoverflow.com/a/2459788/1059828
a minimal makefile to compile open GL could look like this:
编译开放 GL 的最小 makefile 可能如下所示:
LDFLAGS=-lglut -lGL -lGLU -lGLEW -lm
all: your_app
http://surflab.cise.ufl.edu/wiki/Getting_Started_with_OpenGL_in_Ubuntu
http://surflab.cise.ufl.edu/wiki/Getting_Started_with_OpenGL_in_Ubuntu