c++ - Qt 4.7 - glTexSubImage2D returns GL_INVALID_OPERATION -
i'm using qglwidget draw own picture via opengl in qt 4.7.2. use opengl because want stretch image fast , less cpu usage.
for have 3 methods. 1 initialize opengl environment, 1 update image data different thread , 1 draw image itself.
the problem in updateimage method call of gltexsubimage2d() return gl_invalid_operation error. tried debug gdebugger 1 error. if context 1 of program see texture size 0x0, after call of gltexsubimage2d();
init opengl
void class::openglinit(void){ qglcontext* context = const_cast<qglcontext *>(qglcontext::currentcontext()); if (!context) { qdebug() << "can not current opengl context"; return; } context->makecurrent(); glgentextures(1,&texture); glbindtexture(gl_texture_2d, texture); glpixelstorei(gl_unpack_alignment, 1); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_clamp_to_edge); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge); gltexparameteri(gl_texture_2d,gl_texture_base_level,0); gltexparameteri(gl_texture_2d,gl_texture_max_level,0); glteximage2d(gl_texture_2d, 0, gl_rgba, 1024, 1024, 0, gl_rgba, gl_unsigned_int_8_8_8_8, null); glbindtexture(gl_texture_2d,0); }
update image
void class::updateimage(void){ datapointer = (u_int8_t*) malloc(1024*1024*4); memcpy(datapointer,externalbuffer,1024*1024*4); glbindtexture(gl_texture_2d, texture); gltexsubimage2d(gl_texture_2d,0, 0,0,1024,1024,gl_rgba,gl_unsigned_int_8_8_8_8,datapointer); //this line returns gl_invalid_operation }
draw image
void class::paintevent(qpaintevent *event){ qpainter painter(this); painter.beginnativepainting(); glclearcolor(0.0f,0.0f,0.0f,0.0f); glclear(gl_color_buffer_bit|gl_depth_buffer_bit); //draw black screen glenable(gl_texture_2d); glbindtexture(gl_texture_2d, texture); glbegin(gl_quads); //draw picture gltexcoord2f(0, 0); glvertex2f(0, 0); gltexcoord2f(1024, 0); glvertex2f(1024, 0); gltexcoord2f(1024, 1024); glvertex2f(1024,1024); gltexcoord2f(0, 1024); glvertex2f(0, 1024); glend(); gldisable(gl_texture_2d); painter.endnativepainting(); }
i notice mentioned "update image thread", right? error might due missing ogl context in thread call 'updateimage'. please try call in same thread ogl context init , make current.
Comments
Post a Comment