c++ - QOpenGLWidget using QOpenGLBuffer doesn't work -
i want replace demo project of box2d vs qt. because qt have opengl wrappers , use gles instead standard opengl rewrote source code of project qopengl wrappers (change opengl 3.1.0 , glsl 1.40 gles 2.0 , glsl gles 2.0), this:
struct glrenderpoints { void create(mainopenglwidget *widget) { const char *vs = \ "#ifdef gl_es\r\n" "precision lowp float;\r\n" "#endif\r\n" "uniform mat4 projectionmatrix;\n" "attribute vec2 v_position;\n" "attribute vec4 v_color;\n" "attribute float v_size;\n" "varying vec4 f_color;\n" "void main(void)\n" "{\n" " f_color = v_color;\n" " gl_position = projectionmatrix * vec4(v_position, 0.0, 1.0);\n" " gl_pointsize = v_size;\n" "}\n"; const char *fs = \ "#ifdef gl_es\r\n" "precision lowp float;\r\n" "#endif\r\n" "varying vec4 f_color;\n" "vec4 color;\n" "void main(void)\n" "{\n" " color = f_color;\n" "}\n"; m_widget = widget; m_program.addshaderfromsourcecode(qopenglshader::vertex, vs); m_program.addshaderfromsourcecode(qopenglshader::fragment, fs); m_vertexattribute = 0; m_program.bindattributelocation("v_position", m_vertexattribute); m_colorattribute = 1; m_program.bindattributelocation("v_color", m_colorattribute); m_sizeattribute = 2; m_program.bindattributelocation("v_size", m_sizeattribute); m_program.link(); m_projectionuniform = m_program.uniformlocation("projectionmatrix"); m_vbo = qopenglbuffer(qopenglbuffer::vertexbuffer); if (m_vbo.create()) { m_vbo.setusagepattern(qopenglbuffer::dynamicdraw); } m_cbo = qopenglbuffer(qopenglbuffer::vertexbuffer); if (m_cbo.create()) { m_cbo.setusagepattern(qopenglbuffer::dynamicdraw); } m_sbo = qopenglbuffer(qopenglbuffer::vertexbuffer); if (m_sbo.create()) { m_sbo.setusagepattern(qopenglbuffer::dynamicdraw); } m_count = 0; } void flush(qopenglfunctions *m_functions) { if (m_count == 0) return; m_program.bind(); qmatrix4x4 m_modelview = m_widget->buildprojectionmatrix(0.0f); m_program.setuniformvalue(m_projectionuniform, m_modelview); m_vbo.bind(); m_vbo.allocate(m_vertices, m_count); m_vbo.write(0, m_vertices, m_count * sizeof(b2vec2)); m_program.enableattributearray(m_vertexattribute); m_program.setattributebuffer(m_vertexattribute, gl_float, 0, 2); m_cbo.bind(); m_cbo.allocate(m_colors, m_count); m_cbo.write(0, m_colors, m_count * sizeof(b2color)); m_program.enableattributearray(m_colorattribute); m_program.setattributebuffer(m_colorattribute, gl_float, 0, 4); m_sbo.bind(); m_sbo.allocate(m_sizes, m_count); m_sbo.write(0, m_sizes, m_count * sizeof(float32)); m_program.enableattributearray(m_sizeattribute); m_program.setattributebuffer(m_sizeattribute, gl_float, 0, 1); m_functions->glenable(gl_program_point_size); m_functions->gldrawarrays(gl_points, 0, m_count); m_functions->gldisable(gl_program_point_size); m_vbo.release(); m_sbo.release(); m_cbo.release(); m_program.release(); m_count = 0; } enum { e_maxvertices = 512 }; b2vec2 m_vertices[e_maxvertices]; b2color m_colors[e_maxvertices]; float32 m_sizes[e_maxvertices]; int32 m_count; qopenglbuffer m_vbo; qopenglbuffer m_cbo; qopenglbuffer m_sbo; qopenglshaderprogram m_program; mainopenglwidget *m_widget; glint m_projectionuniform; glint m_vertexattribute; glint m_colorattribute; glint m_sizeattribute; };
but when call flush
in paintgl
method of widget see nothing. wrong code? don't understand problem is. shader code, or work qopenglbuffer's
.
Comments
Post a Comment