本文介绍了在 Ubuntu 中学习 OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 OpenGL 并通过 提高我的 C++ 技能href="http://nehe.gamedev.net/" rel="noreferrer">Nehe 指南,但所有示例均适用于 Windows,我目前使用的是 Linux.我真的不知道如何让事情在 Linux 下工作,并且站点上为 Linux 移植的代码中有更多的代码没有解释(到目前为止,我唯一得到的工作是 SDL 示例:http://nehe.gamedev.net/data/lessons/linuxsdl/lesson01.tar.gz).是否有任何其他资源更具体地针对 Linux 下的 OpenGL?

解决方案

首先要做的是安装 OpenGL 库.我推荐:

freeglut3freeglut3-devlibglew1.5libglew1.5-devlibglu1-台面libglu1-台面开发libgl1-台面-glxlibgl1-台面开发

安装它们后,编译时链接到它们:

g++ -lglut -lGL -lGLU -lGLEW example.cpp -o example

在 example.cpp 中,像这样包含 OpenGL 库:

#include #include #include #include #include 

然后,要启用更高级的 opengl 选项(如着色器),请将其放在 glutCreateWindow 调用之后:

GLenum err = glewInit();如果(GLEW_OK != 错误){fprintf(stderr, "Error %s
", glewGetErrorString(err));退出(1);}fprintf(stdout, "Status: Using GLEW %s
", glewGetString(GLEW_VERSION));如果(GLEW_ARB_vertex_program)fprintf(stdout, "状态:ARB 顶点程序可用.
");如果(glewGetExtension(GL_ARB_fragment_program"))fprintf(stdout, "状态:ARB 片段程序可用.
");如果(glewIsSupported(GL_VERSION_1_4 GL_ARB_point_sprite"))fprintf(stdout, "状态:ARB 点精灵可用.
");

这应该会启用所有 OpenGL 功能,如果没有,那么它应该会告诉您问题所在.

I'm trying to learn OpenGL and 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 SDL example: 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?

解决方案

The first thing to do is install the OpenGL libraries. I recommend:

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:

#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:

GLenum err = glewInit();
if (GLEW_OK != err)
{
    fprintf(stderr, "Error %s
", glewGetErrorString(err));
    exit(1);
}
fprintf(stdout, "Status: Using GLEW %s
", glewGetString(GLEW_VERSION));

if (GLEW_ARB_vertex_program)
    fprintf(stdout, "Status: ARB vertex programs available.
");

if (glewGetExtension("GL_ARB_fragment_program"))
    fprintf(stdout, "Status: ARB fragment programs available.
");

if (glewIsSupported("GL_VERSION_1_4  GL_ARB_point_sprite"))
    fprintf(stdout, "Status: ARB point sprites available.
");

That should enable all OpenGL functionality, and if it doesn't, then it should tell you the problems.

这篇关于在 Ubuntu 中学习 OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:36