All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: meta-freescale@yoctoproject.org
Cc: Fikret Alim <fikret.alim@gmail.com>
Subject: Re: Using OpenCV and OpenGL together
Date: Wed, 18 Dec 2013 18:49:24 +0100	[thread overview]
Message-ID: <201312181849.24538.marek.vasut@gmail.com> (raw)
In-Reply-To: <CAHuguRpHiFQ6+5=oNBmYEXVuF5-aPE_FVzUXGo5Z+bySku1jKA@mail.gmail.com>

[-- Attachment #1: Type: Text/Plain, Size: 1665 bytes --]

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

[-- Attachment #2: glplane.cpp.diff --]
[-- Type: text/x-patch, Size: 4720 bytes --]

--- 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;
 }
 

  reply	other threads:[~2013-12-18 18:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11 14:18 Using OpenCV and OpenGL together Fikret Alim
2013-12-18 17:49 ` Marek Vasut [this message]
2013-12-18 18:18 ` Fabio Estevam
2013-12-19  7:39   ` Fikret Alim
2013-12-19 11:55     ` Andre Silva
2013-12-19 13:56       ` Fikret Alim
2013-12-19 14:40         ` Andre Silva
2013-12-19 14:47           ` Fikret Alim
2013-12-19 14:51             ` Andre Silva
2013-12-19 15:33             ` Andre Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201312181849.24538.marek.vasut@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=fikret.alim@gmail.com \
    --cc=meta-freescale@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.