QtでVS2013からBox2Dのデモプロジェクトを移植したいと思います。しかし、私は1つの珍しい問題があります。 VSでデモプロジェクトを実行すると、自分のOpenGL設定に関する情報が入ったメッセージが表示されます。QtアプリケーションでGLSL 1.40を有効にする
私はQtの上のコードを交換し、シェーダとQOpeGLラッパーとのOpenGLつくの呼び出しの初期設定を変更しました。
はまず、私はこのようなデフォルトの表面の書式変更:
QSurfaceFormat format;
format.setVersion(3, 1);
format.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);
をしかし、私はプログラムが3.0に私の表面の滞在の形式でデバッグするとき。
QOpenGLShader::compile(Vertex): ERROR: 0:1: '140' : version number not supported
ERROR: 0:2: 'layout' : syntax error
*** Problematic Vertex shader source code ***
#version 140
#line 1
uniform mat4 projectionMatrix;
layout(location = 0) in vec2 v_position;
layout(location = 1) in vec4 v_color;
layout(location = 2) in float v_size;
out vec4 f_color;
void main(void)
{
f_color = v_color;
gl_Position = projectionMatrix * vec4(v_position, 0.0f, 1.0f);
gl_PointSize = v_size;
}
はなぜVSがシェーダを作成およびOpenGL 3.1/GLSL 1.40で動作することができますが、Qtはない:私はシェーダを作成しようとすると
は、私は、このようなエラーメッセージが表示されますこれを行う?
GLの初期化(m_functions - QOpenGLExtraFunctions)
void MainOpenGLWidget::initializeGL()
{
makeCurrent();
qDebug() << "OPENGL " << QSurfaceFormat::defaultFormat().majorVersion() <<
"." << QSurfaceFormat::defaultFormat().minorVersion();
m_functions.initializeOpenGLFunctions();
m_functions.glClearColor(0, 0, 0, 0);
g_camera.m_width = 1024;
g_camera.m_height = 640;
g_debugDraw.Create(&m_functions);
}
が機能g_debugDraw.Create(...):
void Create(QOpenGLExtraFunctions *functions)
{
const char *vs = \
"#version 140\n"
"uniform mat4 projectionMatrix;\n"
"layout(location = 0) in vec2 v_position;\n"
"layout(location = 1) in vec4 v_color;\n"
"layout(location = 2) in float v_size;\n"
"out vec4 f_color;\n"
"void main(void)\n"
"{\n"
" f_color = v_color;\n"
" gl_Position = projectionMatrix * vec4(v_position, 0.0f, 1.0f);\n"
" gl_PointSize = v_size;\n"
"}\n";
...
m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, vs);
...
m_functions = *functions;
m_functions.glGenVertexArrays(1, &m_vaoId);
m_functions.glGenBuffers(3, m_vboIds);
m_functions.glBindVertexArray(m_vaoId);
m_functions.glEnableVertexAttribArray(m_vertexAttribute);
m_functions.glEnableVertexAttribArray(m_colorAttribute);
m_functions.glEnableVertexAttribArray(m_sizeAttribute);
...
}
ときコールm_program.addShaderFromSourceCode(QOpenGLShader::Vertex, vs);
簡単な解決策:QtをOpenGLに使用しないでください。あなたのコードはQtなしですでに書かれていたと言いますが、なぜそれを移植するのですか? – ybungalobill
@ybungalobillそれは私にとっては不可能ではない:)私は半分の完全なデスクトップアプリケーションとこのアプリケーションのためのこのちょうど新しい機能を持っています。私はこのアプリケーションを書き直すことはできません...私はこの問題を解決しない場合、Qpainterの私のbox2dポートを使用しています。しかし、私はこのポートを使用してOpenGLの動作がより速く、Qpainterを使用したくない。 – iMashine