[英]OpenGL program doesn't start in Qt Creator
我在Linux Mint上使用Qt Creator,并且尝试运行opengl程序。 该建筑物没有给出任何错误,但是当我尝试在Qt Creator中运行该程序时,会出现一个终端窗口,并且什么也没有发生。 当我直接在终端中运行程序时,得到以下输出:
OpenGL version supported by this platform (3.3.0 NVIDIA 295.40):
OpenGL 3.3.0 NVIDIA 295.40, GLSL 3.30 NVIDIA via Cg compiler
Ready for OpenGL 2.0
Segmentation fault (core dumped)
我的代码:
#include <stdio.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutInitWindowPosition(100, 100);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Aquarium");
glutDisplayFunc(onDisplay);
glutMouseFunc(onMouse);
glutIdleFunc(onIdle);
glutKeyboardFunc(onKeyboard);
glutReshapeFunc(onReshape);
printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION));
printf("OpenGL %s, GLSL %s\n",glGetString(GL_VERSION),glGetString(GL_SHADING_LANGUAGE_VERSION));
glewInit();
if (glewIsSupported("GL_VERSION_2_0"))
printf("Ready for OpenGL 2.0\n");
else {
printf("OpenGL 2.0 not supported\n");
exit(1);
}
onInitialization();
glutMainLoop();
return 0;
}
我已经定义了事件处理程序,并且也有onInitialization()方法。 如果我尝试在onInitialization()方法的开头打印某些内容,则该程序除了我之前编写的行以外不会写其他任何东西。 因此,它不会进入我认为的onInitialization()内部。 我什至无法在Qt Creator中调试该程序。 是什么原因造成的? 导致我无法在Qt Creator中启动程序的原因是什么? 我有一个.pro文件:
QT -= gui core
TARGET = main
CONFIG += console
TEMPLATE = app
LIBS += /usr/lib/libglut.so /usr/lib/compiz/libopengl.so /usr/lib/i386-linux-gnu/libGLU.so /usr/lib/i386-linux-gnu/libGLEW.so
QMAKE_CXXFLAGS += -W -Wall -Wextra -pedantic
SOURCES += main.cpp
使用相同的设置,我已经能够在Windows下运行程序(当然,LIBS在那里有所不同)。
onInitialization():
void onInitialization( ) {
printf("onInitialization");
soft.controlpoints.push_back(Point(5., 5., 5.));
soft.speeds.push_back(Point(0., 0., 0.));
soft.controlpoints.push_back(Point(5, -5., 5.));
soft.speeds.push_back(Point(0., 0., 0.));
soft.controlpoints.push_back(Point(5., -5., -5.));
soft.speeds.push_back(Point(0., 0., 0.));
soft2.controlpoints.push_back(Point(5., 5., 5.));
soft2.speeds.push_back(Point(0., 0., 0.));
soft2.controlpoints.push_back(Point(5, -5., 5.));
soft2.speeds.push_back(Point(0., 0., 0.));
soft2.controlpoints.push_back(Point(5., -5., -5.));
soft2.speeds.push_back(Point(0., 0., 0.));
soft2.controlpoints.push_back(Point(-5., 5., -5.));
soft2.speeds.push_back(Point(0., 0., 0.));
soft.set_r();
soft2.set_r();
aquarium.objects.push_back(&water);
aquarium.objects.push_back(&fish);
aquarium.objects.push_back(&field);
aquarium.objects.push_back(&soft2);
aquarium.createMaterials();
aquarium.createVoxelArray();
glEnable(GL_DEPTH_TEST);
lastMovingTime = 0.;
setShadowMapShaders();
setAquariumShaders();
}
它甚至不打印“ onInitialization”字符串。 方法中的对象是全局变量,并且实现了此处调用的所有方法。 是什么原因导致它不显示“ onInitialization”字符串? soft.controlpoints,soft.speeds和aquarium.object是公共字段。 即使我注释了所有其他内容,该字符串也不会出现,但是会创建窗口。 而且它仍然没有从Qt Creator内部运行。
事实证明,问题出在文件读取器方法(读取GLSL着色器代码)中,这是因为Qt Creator的工作目录未在包含着色器源文件的目录上设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.