Android displays YUV data with OpenGL ES2.0 and requires two coordinate system solutions on the phone

Source: Internet
Author: User

Title, do not know that you understand this topic did not, to a link:http://blog.csdn.net/wangchenggggdn/article/details/8896453 (hereinafter referred to as Link ①),

There are a lot of people talking about this problem, I am one of them, but I asked all of them, I also post (http://bbs.csdn.net/topics/390769358)

Looking for a solution, but it didn't get a usable solution.


From mid-April 2014 to this problem, tangled for two weeks, finally after reading a lot of information, in April, the last Monday, temporarily resolved the problem.

The distance was nearly 3 months, because this time I left the QQ mailbox, accidentally leaked my so little information, there are several netizens plus I q asked me this question,

I'm just going to come back and write an article explaining that this is my first original blog in csdn above serious, word from my hand.


Nonsense not much to say, the text came:

Since the reference link ① did the YUV display, the coordinate problem has been there, the following two sets of coordinate system is the culprit,

M 2S, Huawei etc//////////////////////////glfloat squarevertices_zero[] = {0.0f,1.0f,1.0f,1.0f,0.0f, 0.0f,1.0f,0.0f,}; Glfloat coordvertices_zero[] = { -1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, 1.0f,};//////////////////////red rice, Taiwan electric pad, Kindle pad, ss_sch-1939d, etc.//////////////////////////glfloat squarevertices_one[] = { -1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, 1.0f,}; Glfloat coordvertices_one[] = {0.0f,1.0f,1.0f,1.0f,0.0f,0.0f,1.0f,0.0f,};

Finally, in frustration, the disease Touyi, every find a good look at the information, and finally by this article (http://guide.eoeandroid.com/#OpenGL) Several characters "OpenGL version and device compatibility " to deeply attracted. So I put a few more eyes. Ha ha!

And then, by acquiring the OpenGL extensions for different devices, I found some irregular rules ...


The problem becomes clear and the solution is as follows:

The first step: when Createsurfaceview, determine which coordinate system should be used:

</pre><pre name= "code" class= "CPP" ><span style= "White-space:pre" ></span>char *glExtension = Null;glextension = glgetstring (gl_extensions); if (Strstr (glextension, "gl_amd_compressed_atc_texture")! = NULL) {// LOGD ("===%s===", Strstr (Glextension, "gl_amd_compressed_atc_texture")); Vertex_texture_index = 0;} Else{//loge ("===%s===", Strstr (Glextension, "gl_amd_compressed_atc_texture")); Vertex_texture_index = 1;}
of course, that "gl_amd_compressed_atc_texture" is only my own choice to judge the conditions, you can also according to their own observation to choosean extension as a judge


Step Two: Select the texture coordinate system at render time

if (Vertex_texture_index = = 0) {glvertexattribpointer (Attrib_vertex, 2, gl_float, 0, 0, Squarevertices_zero);  2:2 numbers denote a coordinate glenablevertexattribarray (Attrib_vertex); Glvertexattribpointer (Attrib_texture, 2, gl_float, 0, 0, Coordvertices_zero); Glenablevertexattribarray (attrib_texture);} else if (Vertex_texture_index = = 1) {Glvertexattribpointer (Attrib_vertex, 2, gl_float, 0, 0, squarevertices_one);  2:2 numbers denote a coordinate glenablevertexattribarray (Attrib_vertex); Glvertexattribpointer (Attrib_texture, 2, gl_float, 0, 0, Coordvertices_one); Glenablevertexattribarray (attrib_texture);}

At this point, I have solved the problem here. I would like to provide some help to those who need it.


Of course, I'm not really sure if that extension is fully compatible with all devices, so.

In the future if any friend has a better solution, please inform!!!




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.