[android-developers] Re: NDK / glsl / Es 2.0 advice please?
Hi, OpenGL ES 2.0 (GLES2) is completely based on writting your own vertex and fragment shaders. Both types serve a specific purpose. Vertex shaders in their most basic form are responsible for transforming the incoming vertex position. This includes moving them from object to world space, from world space to camera or view space and finally projecting the camera/view space positions. Transformations and projections are achieved via matrices which you usually pass to your shader as so called uniforms. A vertex shader outputs the final vertex position and potentially other information for the fragment shader, like interpolated texture coordinates and normals. A vertex shader thus has to perform the equivalent of the fixed function pipeline transformation and lighting stage (with the later often being implemented in the fragment shader instead to get per pixel lighting). A fragment shader is responsible for outputting a fragments color based on various conditions. You might want to fetch a texel from a texture as the color, apply phong shading based on interpolated normals you receive from the vertex shader and so on. As you can see there's various types of parameters and arguments involved when programming shaders. In GLES2 there's 3 main types (there are other less frequently used types as well): attributes, uniforms and varyings. Attributes and uniforms are specified by you via calls to glVertexAttrib, glVertexAttribPointer or glUniform. Attributes represent vertex attributes like position, texture coordintates, per vertex colors or normals. Uniforms are normally used to pass in things like transformation and projection matrices that you calculate outside the shaders in your program. Varyings are generated within the vertex shader and passed to the fragment shader. Popular examples would be interpolated texture coordinates or normals for phong shading. So what does all this mean for your scenario? First, you will need to calculate the proper transformation and projection matrices yourself, keep track of them yourself and pass them in as uniforms to your vertex shader which then uses them to transform and project your vertices. There is no Android specific GLES2 reference as GLES2 is a standard developed by Khronos which keep the API the same for all platforms. The only difference between platforms is how to setup the GLES2 context and buffers. Usually this is done via EGL, another standard by Khronos. On Android you can use the GLSurfaceView from the hello-gl2 example for that purpose and not worry about it. To get information on the compilation process you can use the functions glGetShaderInfoLog (http://www.opengl.org/sdk/docs/man/xhtml/ glGetShaderInfoLog.xml) and glGetProgramInfoLog (http://www.opengl.org/ sdk/docs/man/xhtml/glGetProgramInfoLog.xml). You usually use the first one after you compiled a vertex or fragment shader and the second one after you linked together a vertex/fragment shader pair to a program. This will give you any errors or warnings the compiler produces. Note that the output is not standardized and will differ for different GPUs and their drivers. My advice would be to get the OpenGL ES 2.0 Programming Guide, a nice little book by the writers of the GLES2 standard which will guide you through all the features and standard procedures of GLES2. The basic concepts of GLES1 are still there in GLES2, however, you have a greater flexibility by providing your own implementation for various stages of the fixed function pipeline, including for example the transform and lighting stage. hth, Mario On 16 Apr., 06:20, HaMMeReD adamhamm...@gmail.com wrote: Working with NDK here. How are perspective correct projection supposed to occur in es 2.0. I can currently draw my geometry to the screen, but it is not getting transformed to 2d. Is there some sort of way of getting meaningful compiler errors out of the shader compiler? Is there a android specific reference to glsl support on it? Am I even supposed to be doing projections in my glsl? I was using hello-gl2 as a baseline, and then modified it to load additional geometry, which is rendering correctly although flat, without any translation or projection. Any advice on translation/ projection is appreciated too, since it seems that all of that has disappeared from es2.0. I've got a opengl 1.1 live screensaver that I've developed that I want to work on porting critical sections to NDK and es2.0, so any advice on porting gl11 to gl20 is appreciated. -- 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 athttp://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers
[android-developers] Re: NDK / glsl / Es 2.0 advice please?
Mario certainly covered it! I recommend just getting the purple book OpenGL ES 2.0 Programming Guide by Shreiner. It covers things pretty well. In short - ES 2.0 will not project it for you. You need to do that in your vertex shader. It's pretty easy though. Something like: uniform mat4 u_matViewProjection; attribute vec4 a_position; void main(void) { gl_Position = u_matViewProjection * a_position; } Should do the trick. On Apr 17, 4:31 am, Mario Zechner badlogicga...@gmail.com wrote: Hi, OpenGL ES 2.0 (GLES2) is completely based on writting your own vertex and fragment shaders. Both types serve a specific purpose. Vertex shaders in their most basic form are responsible for transforming the incoming vertex position. This includes moving them from object to world space, from world space to camera or view space and finally projecting the camera/view space positions. Transformations and projections are achieved via matrices which you usually pass to your shader as so called uniforms. A vertex shader outputs the final vertex position and potentially other information for the fragment shader, like interpolated texture coordinates and normals. A vertex shader thus has to perform the equivalent of the fixed function pipeline transformation and lighting stage (with the later often being implemented in the fragment shader instead to get per pixel lighting). A fragment shader is responsible for outputting a fragments color based on various conditions. You might want to fetch a texel from a texture as the color, apply phong shading based on interpolated normals you receive from the vertex shader and so on. As you can see there's various types of parameters and arguments involved when programming shaders. In GLES2 there's 3 main types (there are other less frequently used types as well): attributes, uniforms and varyings. Attributes and uniforms are specified by you via calls to glVertexAttrib, glVertexAttribPointer or glUniform. Attributes represent vertex attributes like position, texture coordintates, per vertex colors or normals. Uniforms are normally used to pass in things like transformation and projection matrices that you calculate outside the shaders in your program. Varyings are generated within the vertex shader and passed to the fragment shader. Popular examples would be interpolated texture coordinates or normals for phong shading. So what does all this mean for your scenario? First, you will need to calculate the proper transformation and projection matrices yourself, keep track of them yourself and pass them in as uniforms to your vertex shader which then uses them to transform and project your vertices. There is no Android specific GLES2 reference as GLES2 is a standard developed by Khronos which keep the API the same for all platforms. The only difference between platforms is how to setup the GLES2 context and buffers. Usually this is done via EGL, another standard by Khronos. On Android you can use the GLSurfaceView from the hello-gl2 example for that purpose and not worry about it. To get information on the compilation process you can use the functions glGetShaderInfoLog (http://www.opengl.org/sdk/docs/man/xhtml/ glGetShaderInfoLog.xml) and glGetProgramInfoLog (http://www.opengl.org/ sdk/docs/man/xhtml/glGetProgramInfoLog.xml). You usually use the first one after you compiled a vertex or fragment shader and the second one after you linked together a vertex/fragment shader pair to a program. This will give you any errors or warnings the compiler produces. Note that the output is not standardized and will differ for different GPUs and their drivers. My advice would be to get the OpenGL ES 2.0 Programming Guide, a nice little book by the writers of the GLES2 standard which will guide you through all the features and standard procedures of GLES2. The basic concepts of GLES1 are still there in GLES2, however, you have a greater flexibility by providing your own implementation for various stages of the fixed function pipeline, including for example the transform and lighting stage. hth, Mario On 16 Apr., 06:20, HaMMeReD adamhamm...@gmail.com wrote: Working with NDK here. How are perspective correct projection supposed to occur in es 2.0. I can currently draw my geometry to the screen, but it is not getting transformed to 2d. Is there some sort of way of getting meaningful compiler errors out of the shader compiler? Is there a android specific reference to glsl support on it? Am I even supposed to be doing projections in my glsl? I was using hello-gl2 as a baseline, and then modified it to load additional geometry, which is rendering correctly although flat, without any translation or projection. Any advice on translation/ projection is appreciated too, since it seems that all of that has disappeared from es2.0. I've got a opengl 1.1 live screensaver that I've developed that I want