[android-developers] Re: OpenGL Problem
The *more information* you provide, the better your results will be. But the easiest solutions: If you draw all in 3d see glEnable(GL_DEPTH_TEST) also glDepthFunc If 2D you can create sprites with alpha channel (png), disable GL_DEPTH_TEST, set blending GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_ONE,GLES20.GL_ONE_MINUS_SRC_ALPHA); and draw in back to front order -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
I solved all my problmes, there was a little stupid little issues during the copy of my Vertex and CoordTexture on the buffers... Thanks lot however, the theory I read is a good exercise for the next time! Bye! On 28 Dic, 01:52, Robert Green rbgrn@gmail.com wrote: Well said Kostya. Pedro - I defined the formula to get your normal above. A normal is a unit vector (a 3D vector of length 1.) Each vertex must have a normal for proper shading, as that's how light is calculated. The normal of a vertex of a sphere is a easy to calculate. Think of it as the direction from the center of the sphere through the vertex. That's your vector. I provided a formula, though you'll have to javafy it a little to make that work for you. If you're struggling to understand this, I suggest reading some 3D primer books before moving on. They are very, very helpful. Cheers On Dec 27, 7:59 am, Kostya Vasilyev kmans...@gmail.com wrote: Pedro, A normal is a unit vector (length == 1) that is perpendicular to the surface. Normals are used for shading, so don't worry about them too much for now. Texture coordinates, as was already pointed out here, are in 2D space, i.e. two coordinates. The reason is that textures are 2-dimensional, and texture coordinates specify which point within the texture should be mapped to a particular vertex in 3D space. Imagine that the texture is a stretchable, initially square, piece of fabric. Each UV coordinate represents a point within that square. For each vertex, the point within the texture specified for that vertex by UV coordinates is glued to the vertex. Then the texture is allowed to stretch between vertexes. What sort of texture coordinates you generate is entirely up to you. A simple way to texture map a sphere is to wrap the texture into a vertical cylinder around the sphere, then pull the top and bottom towards the sphere, so you have singularities at the top and bottom of the sphere. If you generate your sphere as a bunch of horizontal bands, each having equal angular size, and further subdivided around into equal patches, then you can your use loop variables (band / patch index) to compute UV coordinates. Just remember that UV are 0 to 1 (unless you want tiling). -- Kostya 27.12.2010 18:35, pedr0 пишет: But normal.x what is it? Is the abs(x) ? On 23 Dic, 20:41, Robert Greenrbgrn@gmail.com wrote: UV unwrapping/mapping is standard practice in 3d games. It's how the artist lines up the textures onto the skin/model. You're doing UV coordinate generation, which is similar but is mathematically specified instead of placed by a 3D modeling application. On Dec 23, 12:37 am, pedr0pulsarpie...@gmail.com wrote: What do you think about it? http://en.wikipedia.org/wiki/UV_mapping On 23 Dic, 09:19, pedr0pulsarpie...@gmail.com wrote: Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechnerbadlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Greenrbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: openGL problem
I'm not sure why are you disabling depth test for a sphere and also you should clear color/depth buffer in onDrawFrame On Dec 27, 12:10 pm, pedr0 pulsarpie...@gmail.com wrote: img198(dot)imageshack(dot)us/img198/6370/failfs.png -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: openGL problem
This a link of my issues -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: openGL problem
img198(dot)imageshack(dot)us/img198/6370/failfs.png -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
But normal.x what is it? Is the abs(x) ? On 23 Dic, 20:41, Robert Green rbgrn@gmail.com wrote: UV unwrapping/mapping is standard practice in 3d games. It's how the artist lines up the textures onto the skin/model. You're doing UV coordinate generation, which is similar but is mathematically specified instead of placed by a 3D modeling application. On Dec 23, 12:37 am, pedr0 pulsarpie...@gmail.com wrote: What do you think about it? http://en.wikipedia.org/wiki/UV_mapping On 23 Dic, 09:19, pedr0 pulsarpie...@gmail.com wrote: Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechner badlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Green rbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: OpenGL Problem with Sphere Texture Mapping
Pedro, A normal is a unit vector (length == 1) that is perpendicular to the surface. Normals are used for shading, so don't worry about them too much for now. Texture coordinates, as was already pointed out here, are in 2D space, i.e. two coordinates. The reason is that textures are 2-dimensional, and texture coordinates specify which point within the texture should be mapped to a particular vertex in 3D space. Imagine that the texture is a stretchable, initially square, piece of fabric. Each UV coordinate represents a point within that square. For each vertex, the point within the texture specified for that vertex by UV coordinates is glued to the vertex. Then the texture is allowed to stretch between vertexes. What sort of texture coordinates you generate is entirely up to you. A simple way to texture map a sphere is to wrap the texture into a vertical cylinder around the sphere, then pull the top and bottom towards the sphere, so you have singularities at the top and bottom of the sphere. If you generate your sphere as a bunch of horizontal bands, each having equal angular size, and further subdivided around into equal patches, then you can your use loop variables (band / patch index) to compute UV coordinates. Just remember that UV are 0 to 1 (unless you want tiling). -- Kostya 27.12.2010 18:35, pedr0 пишет: But normal.x what is it? Is the abs(x) ? On 23 Dic, 20:41, Robert Greenrbgrn@gmail.com wrote: UV unwrapping/mapping is standard practice in 3d games. It's how the artist lines up the textures onto the skin/model. You're doing UV coordinate generation, which is similar but is mathematically specified instead of placed by a 3D modeling application. On Dec 23, 12:37 am, pedr0pulsarpie...@gmail.com wrote: What do you think about it? http://en.wikipedia.org/wiki/UV_mapping On 23 Dic, 09:19, pedr0pulsarpie...@gmail.com wrote: Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechnerbadlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Greenrbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
Well said Kostya. Pedro - I defined the formula to get your normal above. A normal is a unit vector (a 3D vector of length 1.) Each vertex must have a normal for proper shading, as that's how light is calculated. The normal of a vertex of a sphere is a easy to calculate. Think of it as the direction from the center of the sphere through the vertex. That's your vector. I provided a formula, though you'll have to javafy it a little to make that work for you. If you're struggling to understand this, I suggest reading some 3D primer books before moving on. They are very, very helpful. Cheers On Dec 27, 7:59 am, Kostya Vasilyev kmans...@gmail.com wrote: Pedro, A normal is a unit vector (length == 1) that is perpendicular to the surface. Normals are used for shading, so don't worry about them too much for now. Texture coordinates, as was already pointed out here, are in 2D space, i.e. two coordinates. The reason is that textures are 2-dimensional, and texture coordinates specify which point within the texture should be mapped to a particular vertex in 3D space. Imagine that the texture is a stretchable, initially square, piece of fabric. Each UV coordinate represents a point within that square. For each vertex, the point within the texture specified for that vertex by UV coordinates is glued to the vertex. Then the texture is allowed to stretch between vertexes. What sort of texture coordinates you generate is entirely up to you. A simple way to texture map a sphere is to wrap the texture into a vertical cylinder around the sphere, then pull the top and bottom towards the sphere, so you have singularities at the top and bottom of the sphere. If you generate your sphere as a bunch of horizontal bands, each having equal angular size, and further subdivided around into equal patches, then you can your use loop variables (band / patch index) to compute UV coordinates. Just remember that UV are 0 to 1 (unless you want tiling). -- Kostya 27.12.2010 18:35, pedr0 пишет: But normal.x what is it? Is the abs(x) ? On 23 Dic, 20:41, Robert Greenrbgrn@gmail.com wrote: UV unwrapping/mapping is standard practice in 3d games. It's how the artist lines up the textures onto the skin/model. You're doing UV coordinate generation, which is similar but is mathematically specified instead of placed by a 3D modeling application. On Dec 23, 12:37 am, pedr0pulsarpie...@gmail.com wrote: What do you think about it? http://en.wikipedia.org/wiki/UV_mapping On 23 Dic, 09:19, pedr0pulsarpie...@gmail.com wrote: Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechnerbadlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Greenrbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechner badlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Green rbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
What do you think about it? http://en.wikipedia.org/wiki/UV_mapping On 23 Dic, 09:19, pedr0 pulsarpie...@gmail.com wrote: Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechner badlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Green rbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
UV unwrapping/mapping is standard practice in 3d games. It's how the artist lines up the textures onto the skin/model. You're doing UV coordinate generation, which is similar but is mathematically specified instead of placed by a 3D modeling application. On Dec 23, 12:37 am, pedr0 pulsarpie...@gmail.com wrote: What do you think about it? http://en.wikipedia.org/wiki/UV_mapping On 23 Dic, 09:19, pedr0 pulsarpie...@gmail.com wrote: Thanks a lot, especially at Robert Green for his very good explanation! The absurd thing is that the code which I posted above is 100% right in a iPhone iOS, but when I port the same code on the Android platform I have these issues. I will try to do what you are talking about normals and I let you know about my progress! Thanks again. pedr0 On 23 Dic, 04:10, Mario Zechner badlogicga...@gmail.com wrote: On 22 Dez., 20:42, Robert Green rbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
pedro, your problem has nothing to do with android. I think you may need a 3D refresher to solve it. Normals are not UVs. Your UVs will depend on how you want to map, but the easiest way to do it is to map from the sphere center out using angles, like this. Since GL has 2D texture coordinate 0,0 as upper left, you will want to define where upper left is on your sphere. I'd use straight up and center as a unit vector, or (0, 0, 1) if z is up in your world. If y is up, then (0,1,0) will be 0,0 in UVs. so starting with that, you can calculate the UV of any point by getting the difference of angle of that starting angle and the new point. Remember that if they both come from the sphere center, you'll have complete 2PI radian coverage on both axis... so naturally dividing the resulting angle by 2PI will give you a UV number between 0 and 1. The process is like this (assuming z=up) For each point: // for U just look at the sphere from overhead U = (atan2(point.x - center.x, point.y - center.y) + PI) / (2PI) hyp = distance(point, center); V = ((point.z - center.z) / hyp) + 1) / 2 I believe that is correct and there will be a more elegant way to do it but today my head is in 2D math world so I can't remember how to dot it out. The idea though is that for every point, you can determine the angle needed for U by looking at the sphere from overhead and just using an arctan of the xy differences (assuming z=up) of the center to the point. The resulting range is in radians (- PI to PI) so you have to add PI to change it from 0 to 2PI and then dividing by 2PI gives you 0 to 1. Then for the V value, you can just examine the height (z) of the point and in conjunction with its distance from the center, you've got an opposite over hypotenuse which is the same as the sine of the angle, which is what you want to get a evenly distributed texture top to bottom. The number will also be ranged from -1 to 1 so you need to add 1 and divide it by 2 to get the 0 to 1 range. The texture should touch in the corners and if you use the right one, look seamless. If any of my math is wrong, please correct it after debugging, but at least this should get you going in the right direction. Cheers On Dec 22, 9:09 am, pedr0 pulsarpie...@gmail.com wrote: Please see the link and reply inside this post if you have not an account on OpenGL forum, the question is over there. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflatN... Thanks a lot. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
Also I should add that your sphere normal should be (sphereCenter - point).Normalize() and will be a 3D vector. Normals are 3D, UVs are 2D. On Dec 22, 9:09 am, pedr0 pulsarpie...@gmail.com wrote: Please see the link and reply inside this post if you have not an account on OpenGL forum, the question is over there. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflatN... Thanks a lot. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
Oh here is a faster method - http://www.mvps.org/directx/articles/spheremap.htm For each point (Assuming Y=up): 3DVec normal = (sphereCenter - point).normalize(); float U = asin(normal.x)/PI + 0.5 float V = asin(normal.y)/PI + 0.5 for z=up: float U = asin(normal.x)/PI + 0.5 float V = asin(normal.z)/PI + 0.5 But in your code example I don't know if you were calculating normals correctly. Your normal should be a vector pointing from the center of your sphere out the vertex, which is done by subtracting and then normalizing to make it a unit-vector. On Dec 22, 11:33 am, Robert Green rbgrn@gmail.com wrote: pedro, your problem has nothing to do with android. I think you may need a 3D refresher to solve it. Normals are not UVs. Your UVs will depend on how you want to map, but the easiest way to do it is to map from the sphere center out using angles, like this. Since GL has 2D texture coordinate 0,0 as upper left, you will want to define where upper left is on your sphere. I'd use straight up and center as a unit vector, or (0, 0, 1) if z is up in your world. If y is up, then (0,1,0) will be 0,0 in UVs. so starting with that, you can calculate the UV of any point by getting the difference of angle of that starting angle and the new point. Remember that if they both come from the sphere center, you'll have complete 2PI radian coverage on both axis... so naturally dividing the resulting angle by 2PI will give you a UV number between 0 and 1. The process is like this (assuming z=up) For each point: // for U just look at the sphere from overhead U = (atan2(point.x - center.x, point.y - center.y) + PI) / (2PI) hyp = distance(point, center); V = ((point.z - center.z) / hyp) + 1) / 2 I believe that is correct and there will be a more elegant way to do it but today my head is in 2D math world so I can't remember how to dot it out. The idea though is that for every point, you can determine the angle needed for U by looking at the sphere from overhead and just using an arctan of the xy differences (assuming z=up) of the center to the point. The resulting range is in radians (- PI to PI) so you have to add PI to change it from 0 to 2PI and then dividing by 2PI gives you 0 to 1. Then for the V value, you can just examine the height (z) of the point and in conjunction with its distance from the center, you've got an opposite over hypotenuse which is the same as the sine of the angle, which is what you want to get a evenly distributed texture top to bottom. The number will also be ranged from -1 to 1 so you need to add 1 and divide it by 2 to get the 0 to 1 range. The texture should touch in the corners and if you use the right one, look seamless. If any of my math is wrong, please correct it after debugging, but at least this should get you going in the right direction. Cheers On Dec 22, 9:09 am, pedr0 pulsarpie...@gmail.com wrote: Please see the link and reply inside this post if you have not an account on OpenGL forum, the question is over there. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflatN... Thanks a lot. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL Problem with Sphere Texture Mapping
On 22 Dez., 20:42, Robert Green rbgrn@gmail.com wrote: 3DVec normal = (sphereCenter - point).normalize(); 3DVec normal = (point - sphereCenter).normalize(); Or your world will be upside down. Unless my brain is totally borked :) (could well be, 4am here...) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en