http://programanddesign.com/cpp/qt-opengl-code-example/
I am trying out above example and included
#include <GL/glu.h>
#include <GL/glut.h>
as well. but I am getting a gluOrtho2D undefined error. what am I doing wrong here ?
You need to put the OpenGL and GLU libraries in your object, the '#include' directive is not an library, it's just a reference of what the library can do for you. Libraries have the .so extension on linux, .dylib on MacOS and .dll / .lib on windows, you need to tell us What you are using to compile, ( MinGW, VisualStudip, QtCreator ) and also tell us what libraries are you linking with. for OpenGL, in linux is -lGL, in windows is -lOpenGL32.
When you have a "undefined reference" you have to check if you have linked your libraries!
Compile with "-l" flag or, if you use -for instance- eclipse go to: project->propreties->C++Build->Settings->GCC C++ Linker->Libraries and add your library!
Include all these libraries: Example: Here new2.cpp is main c++ file and Output.out is an executable file that is created by compiling the new2.cpp file in g++ compiler. And I had also included the libraries with -I and linked them with -l. At last I have executed the result by doing ./Output.out
mandeep@mandeep-HP:~/Desktop$ g++ new2.cpp -o Output.out -I/usr/include/GL -I/usr/lib -lGL -lglut -lGLU mandeep@mandeep-HP:~/Desktop$ ./Output.out
Follow these two steps if you are using windows.
#include <QtOpenGL>
to your .h file of the class. QT += opengl
in your .pro file.