Setting up Opengl ES2 in Qt
-
Hi
I'm tring to dive in to the world of shaders. Before using Qt Opengl functions I'm tring to use raw OpenGL,
I'm following the triangle example from the book ES 2.0 Programming Guide. I created a function in a QGLWiddget@GLuint graph3DWidget::LoadShader(const char *shaderSrc, GLenum type)
{
GLuint shader;
GLint compiled;// Create the shader object
shader = glCreateShader(type);
if(shader == 0)
return 0;
// Load the shader source
glShaderSource(shader, 1, &shaderSrc, NULL);// Compile the shader
glCompileShader(shader);
// Check the compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if(!compiled)
{
GLint infoLen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);if(infoLen > 1) { char* infoLog = (char *)malloc(sizeof(char) * infoLen); glGetShaderInfoLog(shader, infoLen, NULL, infoLog); qDebug("Error compiling shader:\n%s\n", infoLog); //esLogMessage("Error compiling shader:\n%s\n", infoLog); free(infoLog); } glDeleteShader(shader); return 0; } return shader;
}@
Errors:
@debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:48: undefined reference to
_imp____glewCreateShader' debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:52: undefined reference to
imp____glewShaderSource'
debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:55: undefined reference to_imp____glewCompileShader' debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:57: undefined reference to
imp____glewGetShaderiv'
debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:61: undefined reference to_imp____glewGetShaderiv' debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:66: undefined reference to
imp____glewGetShaderInfoLog'
debug/graph3dwidget.o:C:\nokiaqtapps\QtMobileOpenGL-build-desktop-Qt_4_7_4_for_Desktop-_MinGW_4_4__Qt_SDK__Debug/../QtMobileOpenGL/graph3dwidget.cpp:71: undefined reference to `_imp____glewDeleteShader'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtMobileOpenGL.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project QtMobileOpenGL (target: Desktop)
When executing build step 'Make'@I'm using windows 7 64bits, and latest QtSDK with mingw. I installed glew 1.7.0 64bits version, pre compiled. I copied the glew.h and glew32.lib to
C:\QtSDK\mingw\include\GL and glew32.dll to windows\system32 and to C:\QtSDK\mingw\bin.The errors I got show that problably there's a incompatible version in glew library, but I using latest version. I also have used glew include before QGLWidget include
@#include <GL/glew.h>
#include <QGLWidget>
//#include <QtOpenGL>
//#include <GL/gl.h>@I'm thinking also if perhaps these precompiled glew binarys are incomptible with mingw ?
Any ideias ???? -
I did not compile Qt for 64 bit. I just tested the 32 bit glew, I still have errors. I've been goggling it seems that glew32.lib is for use with Visual Studio, for mingw it should be compiled so I can get a glew32.a. Right now I'm googling on how to compile glew with mingw, also any help on this will be greatly apreciated.
Many thanks so far
Joao -
visual studio libs and mingw are not compatible. Even more, apparently different versions of visual studio libs may not be compatible. However, never tested.
There is also the possibility to use visual studio express with Qt, if you cannot get forward with the glew lib compilation. The visual studio express edition you can just downlaod. Unfortunately you cannot use the qt addins then.For the compiling of glew with mingw, do you have makefiles for glew? Maybe you can load to qt creator and compile from there. Unfortunately, I have no experience with mingw.
-
glew has a makefile, I tried compiling in linux with the command make, also got errors
@/bin/sh: 1: config/config.guess: not found
/bin/sh: 1: config/config.guess: not found
Makefile:40: *** "Platform '' not supported". Stop.
@In windows I coulnt compile it in QtCreator. Also I know about VS express but I'm trying to avoid it.
Seems I'm stuck. I'll digg further to try to comple it in windows.Also in linux I installed glew with apt-get. Didnt recognize functions like glCreateShader(). Then I manually copied glew.h to /usr/include/GL. Now I got the same type of errors I got in windows:
@graph3dwidget.o: In function
graph3DWidget::LoadShader(char const*, unsigned int)': make: Leaving directory
/home/joao/qt4projects/QtMobileOpenGL-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release'
graph3dwidget.cpp:(.text+0x47): undefined reference to__glewCreateShader' graph3dwidget.cpp:(.text+0x78): undefined reference to
__glewShaderSource'
graph3dwidget.cpp:(.text+0x80): undefined reference to__glewCompileShader' graph3dwidget.cpp:(.text+0x92): undefined reference to
__glewGetShaderiv'
graph3dwidget.cpp:(.text+0xb9): undefined reference to__glewGetShaderiv' graph3dwidget.cpp:(.text+0xde): undefined reference to
__glewGetShaderInfoLog'
graph3dwidget.cpp:(.text+0xfd): undefined reference to `__glewDeleteShader'
collect2: ld returned 1 exit status
make: *** [QtMobileOpenGL] Error 1
The process "/usr/bin/make" exited with code 2.
Error while building project QtMobileOpenGL (target: Desktop)
When executing build step 'Make'@ -
Hi John_god,
Are you trying to build an opengl ES 2.0 based app in a desktop version? I guess it won't work... as far as I remenber, only openGL 4.0 compliant context can manage OGL ES specific code, and I assume that QGL API cannot do that yet.
If you want to get start with shaders, just begin with desktop opengl 3.2 core profile, migration to opengl ES 2.0 is easy afterward.