Its been 17 days I'm struggling to write a simple program in OpenGL using QT, but all tutorials searched on Google are failed. I'v compiled my QT 5.0.1 with -opengl desktop using msvc2010 to make desktop opengl default.
I'v read tutorial by Sean Harmer, but it is depended on QT to resolve opengl functions.
According to some people, it is not possible to use glew in QT, as QT's built in libraries prevent glew from including its headers, but according to Sean Harmer HERE , it is possible (but it is not explained there how).
Even using QGLWidget I'm not able to use OpenGL extensions.
Now all I want is to use all OpenGL functions separate and all windowing functions from QT separate, i.e. no interference in OpenGL by QT.
If anybody explain me the procedure with simple triangle example and using any extension, I'l be so thankful..
I'v used glew library in my project and #included glew.h in very start of my program, but when compiled it gives error: glwidget.obj:-1: error: LNK2001: unresolved external symbol imp__glewGenVertexArrays
My .pro file
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Trial
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp
HEADERS += mainwindow.h \
glwidget.h
FORMS += mainwindow.ui
RESOURCES += \
resources.qrc
win32: LIBS += -L$$PWD/../../../../../OpenGL/glew-1.9.0/lib/ -lglew32s
INCLUDEPATH += $$PWD/../../../../../OpenGL/glew-1.9.0/include
DEPENDPATH += $$PWD/../../../../../OpenGL/glew-1.9.0/include
win32: PRE_TARGETDEPS += $$PWD/../../../../../OpenGL/glew-1.9.0/lib/glew32s.lib
Output by glewInfo : GLEW version 1.9.0 Reporting capabilities of pixelformat 1 Running on a GeForce GT 540M/PCIe/SSE2 from NVIDIA Corporation OpenGL version 4.3.0 is supported
void GLWidget::initializeGL()
{
GLenum err = glewInit();
if(err != GLEW_OK)
{
printf("%s",glewGetErrorString(err));
}
glEnable(GL_DEPTH_TEST);
qglClearColor(QColor(Qt::red));
shaderProgram.addShaderFromSourceFile(QGLShader::Vertex, ":/vertexShader.vsh");
shaderProgram.addShaderFromSourceFile(QGLShader::Fragment, ":/fragmentShader.fsh");
shaderProgram.link();
shaderProgram.bind();
const GLubyte *oglVersion = glGetString(GL_VERSION);
printf( "%s\n",oglVersion );
GLfloat vertices[3][3] ={{ -0.5, -0.5, -1 },
{ 0, 0.5, -1},
{ 0.5, -0.5, -1}};
vertexArray.create();
vertexArray.setUsagePattern(QOpenGLBuffer::StaticDraw);
vertexArray.allocate( vertices, 3 * 3 * sizeof( GLfloat ) );
vertexArray.bind();
shaderProgram.setAttributeBuffer( "vVertex", GL_FLOAT, 0, 3 );
shaderProgram.enableAttributeArray( "vVertex" );
GLuint arr[5];
glGenBuffers(5,arr);
}
QGLWidgets
. But without specific error messages, the.pro
file you have used, etc. we can't help you. – TurnoverGLEW_STATIC
token. Presumably you are also callingglewInit()
once you have valid context. – Turnoverglewinfo
)? Also, post yourinitializeGL()
method. – Turnoveruse /NODEFAULTLIB:library glew32s.lib
. – Turnoverbut it is not explained there how
Move all non-qt OpenGL rendering into separate .h/.cpp files and don't include Qt headers from those files. Can't think of any reason why this wouldn't work. – Unhandy