From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 40AF5E007F9 for ; Wed, 18 Dec 2013 10:09:09 -0800 (PST) Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3dl43l1Wcpz3hjDL; Wed, 18 Dec 2013 19:09:07 +0100 (CET) X-Auth-Info: b2HEM0mko/AOx0ExGiN7SxlAdhbgtbQRPyqrabtgrz8= Received: from chi.localnet (unknown [195.140.253.167]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mnet-online.de (Postfix) with ESMTPSA id 3dl43l12pXzbbh6; Wed, 18 Dec 2013 19:09:07 +0100 (CET) From: Marek Vasut To: meta-freescale@yoctoproject.org Date: Wed, 18 Dec 2013 18:49:24 +0100 User-Agent: KMail/1.13.7 (Linux/3.10-2-amd64; KDE/4.10.5; x86_64; ; ) References: In-Reply-To: MIME-Version: 1.0 Message-Id: <201312181849.24538.marek.vasut@gmail.com> Cc: Fikret Alim Subject: Re: Using OpenCV and OpenGL together X-BeenThere: meta-freescale@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Usage and development list for the meta-fsl-* layers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 18:09:13 -0000 X-Groupsio-MsgNum: 6079 Content-Type: Multipart/Mixed; boundary="Boundary-00=_kAesSHo6G8m4YyH" --Boundary-00=_kAesSHo6G8m4YyH Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Wednesday, December 11, 2013 at 03:18:33 PM, Fikret Alim wrote: > Hello, > > > > I am trying to use OpenCV and OpenGL together for some image processing > tasks. I have already run OpenCV examples on IMX6, I can also compile and > run the examples under gpu sdk of Freescale with X11, but when I try to use > them together I have some problems. > > > > Actually, what I am trying to make has already been done by Freescale > > http://imxcv.blogspot.com/2012/03/gesture-recognition-on-imx6.html > > http://cache.freescale.com/files/32bit/doc/app_note/AN4629.pdf > > > > I have tried many times by using these examples in order to create a simple > working binary, but unfortunately I could not achieve that. I have attached > one of my trials (the source code, Makefile and the binary). I have > modified the 06_Texturing example given under GLES2_0 folder of gpu sdk. I > have compiled it without any problem, but when I load the binary to IMX6 > board and run the example, I see a black cube rotating. Your texturing is broken, right ? > I am waiting for > the video instead of black screen. I have attached the output of the > screen, also. If I add an imshow function after I get the image from the > camera, I can see it without any problem. But when it is used by OpenGL, I > can only see black screen as I said. The examples are broken, they don't check GL errors etc. Find attached patch, it should give you an idea how to fix your glplane.cpp in the examples. glEGLImageTargetTexture2DOES() usually returns GL error because the fragment shader is completely bonkers. Best regards, Marek Vasut --Boundary-00=_kAesSHo6G8m4YyH Content-Type: text/x-patch; charset="UTF-8"; name="glplane.cpp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="glplane.cpp.diff" --- a/src/glplane.cpp 2013-12-07 13:57:26.410103736 +0100 +++ b/src/glplane.cpp 2013-12-18 18:46:33.193693194 +0100 @@ -8,20 +8,12 @@ "{ \n" " gl_FragColor = texture2D(sampler2d,myTexCoord); \n" "} \n";*/ - "#ifdef GL_FRAGMENT_PRECISION_HIGH \n" - " precision highp float; \n" - "#else \n" - " precision mediump float; \n" - "#endif \n" - " \n" "uniform sampler2D s_texture; \n" - "varying vec3 g_vVSColor; \n" - "varying vec2 g_vVSTexCoord; \n" + "varying mediump vec2 g_vVSTexCoord; \n" " \n" "void main() \n" "{ \n" - " gl_FragColor = texture2D(s_texture,g_vVSTexCoord.xy); \n" - + " gl_FragColor = texture2D(s_texture,g_vVSTexCoord); \n" "} \n"; @@ -44,17 +36,13 @@ "uniform mat4 g_matProj; \n" " \n" "attribute vec4 g_vPosition; \n" - "attribute vec3 g_vColor; \n" "attribute vec2 g_vTexCoord; \n" " \n" - "varying vec3 g_vVSColor; \n" "varying vec2 g_vVSTexCoord; \n" " \n" "void main() \n" "{ \n" - " vec4 vPositionES = g_matModelView * g_vPosition; \n" - " gl_Position = g_matProj * vPositionES; \n" - " g_vVSColor = g_vColor; \n" + " gl_Position = g_matProj * g_matModelView * g_vPosition;\n" " g_vVSTexCoord = g_vTexCoord; \n" "} \n"; @@ -392,10 +380,10 @@ //-------------------------------------------------------------------------------------- void GLPlane::PlaneSetTexBuf (uint8_t *texture_data, int w, int h) { + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _texture); - //glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texture_data); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_data); - + glUniform1i(_s_texture_location, 0); } //-------------------------------------------------------------------------------------- @@ -470,24 +458,12 @@ // Pass the texture coordinates data glVertexAttribPointer (PLANE_TEXCOORD_ARRAY, 2, GL_FLOAT, 0, 0, texcoords); glEnableVertexAttribArray (PLANE_TEXCOORD_ARRAY); - - // enable depth test - glEnable (GL_DEPTH_TEST); - glDepthFunc (GL_LEQUAL); - glDepthMask (GL_TRUE); - - // cull backside of polygons - //glEnable(GL_CULL_FACE); - //glCullFace (GL_BACK); - glDisable(GL_CULL_FACE); - - // Binds this texture handle so we can load the data into it - //glBindTexture(GL_TEXTURE_2D, _texture); - /* Select Our Texture */ - glActiveTexture(GL_TEXTURE0); - //Select eglImage - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, g_imgHandle); - + + + + + + glDrawArrays (GL_TRIANGLES, 0, 6); @@ -632,6 +608,7 @@ //-------------------------------------------------------------------------------------- GLuint GLPlane::GenTextures (void) { +#if 0 GLuint texture_id = 0; // Use tightly packed data @@ -639,8 +616,38 @@ // Allocates one texture handle glGenTextures (1, &texture_id); +#endif + + // Texture object handle + GLuint textureId; + + // 2x2 Image, 3 bytes per pixel (R, G, B) + GLubyte pixels[4 * 3] = + { + 255, 0, 0, // Red + 0, 255, 0, // Green + 0, 0, 255, // Blue + 255, 255, 0 // Yellow + }; + + // Use tightly packed data + glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); + + // Generate a texture object + glGenTextures ( 1, &textureId ); + + // Bind the texture object + glBindTexture ( GL_TEXTURE_2D, textureId ); + + // Load the texture + glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels ); + + // Set the filtering mode + glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + - return texture_id; + return textureId; } //-------------------------------------------------------------------------------------- @@ -654,10 +661,10 @@ _texture_h = texture_h; _texture = GenTextures (); - +#if 0 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - +#endif return; } @@ -765,7 +772,7 @@ // Get uniform locations _modelview_location = glGetUniformLocation (_shader_program, "g_matModelView"); _projview_location = glGetUniformLocation (_shader_program, "g_matProj"); - + _s_texture_location = glGetUniformLocation (_shader_program, "s_texture"); return true; } --Boundary-00=_kAesSHo6G8m4YyH--