Learning OpenGL in Ubuntu [closed]
Asked Answered
A

4

49

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?

Ananthous answered 13/5, 2009 at 18:13 Comment(1)
I admit the topic-closings on Stack Overflow are becoming a little Nazi, but I'm sure many people have this problem; it would be better suited at GameDev StackExchangeBorras
P
73

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

Purser answered 1/1, 2010 at 14:8 Comment(2)
is there a way to get the opengl 4.5 functionality? or at least 4.1?Paleontography
fprintf(stdout, "%s\n", glGetString(GL_VERSION)); outputs 3.0 Mesa 17.3.0-devel although I have 4.5 OpenGL core profile version string: 4.5 (Core Profile) Mesa 17.3.0-develPaleontography
E
9

I'll guess that it is the compilation process that is the biggest difference initially. Here is a useful Makefile for compiling simple OpenGL apps on Ubuntu.

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 Makefile that should be in the same directory. Compile by writing make from terminal or :make from Vim.

Good luck

Erek answered 13/11, 2011 at 5:28 Comment(0)
A
4

a little update for the makefile because I found this old answers from @Millthorn and it didn't worked: you don't need to define the include path since it's in standard lib https://mcmap.net/q/356567/-where-are-the-opengl-libraries-get-stored-on-ubuntu-i-need-this-to-mention-in-my-make-file

a minimal makefile to compile open GL could look like this:

LDFLAGS=-lglut -lGL -lGLU -lGLEW -lm
all: your_app

http://surflab.cise.ufl.edu/wiki/Getting_Started_with_OpenGL_in_Ubuntu

Annuity answered 7/7, 2013 at 11:17 Comment(0)
F
1

Maybe you would like to use Qt to draw the windows and widgets.

Here's a tutorial based on the Nehe guides to show you how to create OpenGL images with Qt.

To learn OpenGL, the OpenGL Red Book is a must read. There's an online version. It has very good explanations and examples.

Factional answered 13/5, 2009 at 22:21 Comment(1)
another good tutorial learnopengl.comSacha

© 2022 - 2024 — McMap. All rights reserved.