Opengl doesn't work with Qt
-
wrote on 27 Jun 2011, 17:27 last edited by
If you really want ot use GLUT, I think you'll have to find a Windows port of GLUT, and install it, e.g. "this one":http://www.xmission.com/~nate/glut.html. Then, you must add the library, as well as the path to where you installed it, to the LIBS variable. And possible set the include path as well.
But, most of the things you get from using GLUT are things you don't really need when you use OpenGL with Qt. It makes sense to use GLUT or Qt, but not really both.
-
wrote on 27 Jun 2011, 17:35 last edited by
Is it something different with the glut which I am currently using in c++ under the same windows ??? because in c++ I have no problem with openGl and all its library only in Qt ...
-
wrote on 27 Jun 2011, 17:44 last edited by
You are saying that you can use GLUT from plain C++ code, but not from Qt code? In that case you must have it installed somewhere already. You just need to tell where, in your .pro file, so that qmake can find it. I.e., you must add something like:
@
LIBS += -lglut
LIBS += -LC:/location/of/glut
@
I'm not sure this is what's missing, though. Since you don't get an error saying it cannot find the glut library. Looks like it actually finds it, but not the symbols it needs. Strange.Which compiler are you using? The same one you use when compiling plain C++ code?
-
wrote on 27 Jun 2011, 17:53 last edited by
Yes I am using in plain C++ without problem,
But I can not find any file like lglut in my pc(where can I get this file) ??????
I have only glut, glut32 (header file and lib file )....
but I never tried the second line which you mentioned above, I will try the second one seems by the second line error should be gone hopefully by the way now I uninstall the Qt and trying to get the new version as soon as I install I will apply this and I will let you know about it .... many many thanks to you that spend your time for my problem ..... -
wrote on 27 Jun 2011, 18:03 last edited by
-l stands for library and -L for library path, see "qmake doc":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#libs
[quote author="fery13" date="1309197219"]Yes I am using in plain C++ without problem,
But I can not find any file like lglut in my pc(where can I get this file) ??????
I have only glut, glut32 (header file and lib file ).... [/quote] -
wrote on 27 Jun 2011, 18:08 last edited by
-lglut is like a command line option, which you use to tell qmake to use a library. -l is the option and glut the argument. On Windows, the file should be called glut.lib. -L is used to add a directory in which to look for libraries.
I don't think this is the problem, though. It seems to find GLUT and is unable to link with it. Maybe you simply cannot do this, because using those functions mentioned above together with Qt really makes no sense.
-
wrote on 27 Jun 2011, 18:27 last edited by
Try @LIBS += -L/path/to/your/lib -lLibfile_without_exstension@
-
wrote on 27 Jun 2011, 19:08 last edited by
Just had a look in my OpenGL installation, which is the one that comes with mingw / Qt Creator, and it contains glu, but not glut. So your glut must come from somewhere else.
-
wrote on 28 Jun 2011, 12:02 last edited by
That's strange I tried all, but still errors, also I re install Qt ... here is my .pro:
@
#-------------------------------------------------Project created by QtCreator 2011-06-23T18:42:17
#-------------------------------------------------
TARGET = open1
TEMPLATE = app
DEPENDPATH += .
INCLUDEPATH += .
SOURCES += open1.cpp
HEADERS += open1.h
open1_global.hCONFIG += opengl
releaseQT += opengl
LIBS += -lglut
LIBS += C:\Users\FGHASSEMIT\Documents\qt\GL\glut.lib
@
and here errors ::-1: error: cannot find -lglut
:-1: error: collect2: ld returned 1 exit status.................
this is the same if I write glut32 instead of glut ....
:(Edit: Added @ tags
-
wrote on 28 Jun 2011, 12:07 last edited by
Try also adding:
@
LIBS += -LC:/path/to/your/glut/lib
@ -
wrote on 28 Jun 2011, 12:16 last edited by
I did then I have again error :
:-1: error: LC:/Users/FGHASSEMIT/Documents/qt/GL/glut.lib: Invalid argument
I guess LC is used for Linux ....
-
wrote on 28 Jun 2011, 12:18 last edited by
You are now trying to link with glut twice... Your .pro file should contain
@
LIBS += -lglut
LIBS += -LC:\Users\FGHASSEMIT\Documents\qt\GL
@
or just
@
LIBS += C:\Users\FGHASSEMIT\Documents\qt\GL\glut.lib
@
but not both.Nevertheless, I think you should try to get rid of the glut dependency, because using it with Qt will most likely create problems.
-
wrote on 28 Jun 2011, 12:18 last edited by
sorry I forget to put dash (-) behind so the errors turn to be like this :
C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference to
__glutInitWithExit' C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference to
glutInitDisplayMode'
C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference toglutInitWindowSize' . . . C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference to
_imp__glBegin'
C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference to_imp__glVertex2f' C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference to
_imp__glEnd'
C:\Users\FGHASSEMIT\open1\open1.cpp:-1: error: undefined reference to `_imp__glFlush'
:-1: error: collect2: ld returned 1 exit status -
wrote on 28 Jun 2011, 12:26 last edited by
I agree with ludde. You are trying to use glut to reproduce functionality that is already in Qt. Some glut functions can still make sense to use within Qt (ie for drawing basic geometric shapes such as a sphere).
Take a look at my repository to see a few very simple OpenGL apps that use Qt rather than glut for the windowing functionality. Just use svn to checkout:
@
https://svn.theharmers.co.uk/svn/codes/public/opengl/trunk/
@cd into one of the directories e.g. 06-solar-system then run:
@
qmake
make
@
20/24