c++ - What's the proper way to bind a QImage to a texture to display video in QOpenGLWidget -
i'm trying implement efficient video player, started qt's textures example.
i have:
void hud::initializegl() { initializeopenglfunctions(); makeobject(); glenable(gl_depth_test); glenable(gl_cull_face); #define program_vertex_attribute 0 #define program_texcoord_attribute 1 qopenglshader *vshader = new qopenglshader(qopenglshader::vertex, this); const char *vsrc = "attribute highp vec4 vertex;\n" "attribute mediump vec4 texcoord;\n" "varying mediump vec4 texc;\n" "uniform mediump mat4 matrix;\n" "void main(void)\n" "{\n" " gl_position = matrix * vertex;\n" " texc = texcoord;\n" "}\n"; vshader->compilesourcecode(vsrc); qopenglshader *fshader = new qopenglshader(qopenglshader::fragment, this); const char *fsrc = "uniform sampler2d texture;\n" "varying mediump vec4 texc;\n" "void main(void)\n" "{\n" " gl_fragcolor = texture2d(texture, texc.st);\n" "}\n"; fshader->compilesourcecode(fsrc); program = new qopenglshaderprogram; program->addshader(vshader); program->addshader(fshader); program->bindattributelocation("vertex", program_vertex_attribute); program->bindattributelocation("texcoord", program_texcoord_attribute); program->link(); program->bind(); program->setuniformvalue("texture", 0); } void hud::paintgl() { clock_t begin = clock(); glclearcolor(clearcolor.redf(), clearcolor.greenf(), clearcolor.bluef(), clearcolor.alphaf()); glclear(gl_color_buffer_bit | gl_depth_buffer_bit); static int ctt = 0; qmatrix4x4 m; m.ortho(-0.2f, +0.2f, +0.2f, -0.2f, 4.0f, 15.0f); m.translate(0.0f, 0.0f, -5.0f); program->setuniformvalue("matrix", m); program->enableattributearray(program_vertex_attribute); program->enableattributearray(program_texcoord_attribute); program->setattributebuffer(program_vertex_attribute, gl_float, 0, 3, 5 * sizeof(glfloat)); program->setattributebuffer(program_texcoord_attribute, gl_float, 3 * sizeof(glfloat), 2, 5 * sizeof(glfloat)); //???// //how bind qimage texture efficiently??? //???// textures->bind();// textures qopengltexture gldrawarrays(gl_triangle_fan, 0 * 4, 4); clock_t end = clock(); double elapsed_secs = double(end - begin) / clocks_per_sec; qdebug() << elapsed_secs; }
the example used qopengltexture read 1 single qimage , bind quad painted paintgl() function.
however, how update content of texture display video @ 30 hz?
you should take @ qt video widget example basic video player. can stream video qgraphicsvideoitem can display in qgraphicsview, can contain other graphics items , can render opengl content if provide qopenglwidget viewport.
if want roll own might want use qt video functionalities , implement class based on qabstractvideosurface receive video frames media player. take @ handletype() of qvideoframe. if qabstractvideobuffer::gltexturehandle or qabstractvideobuffer::eglimagehandle might able draw screen using quad shader handle() texture id. if not write data qopengltexture. can upload textures in thread prevent blocking gui thread.
Comments
Post a Comment