Thursday, 20 July 2017

c++ - Learning OpenGL in Ubuntu




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?


Answer



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



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\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.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...