Skip to content Skip to sidebar Skip to footer

Opengl Es 2.0 / Glsl Not Rendering Data (kotlin)

I am trying to implement a basic shading program with GLES 2/3, and have pieced together this code from various tutorials. Everything looks correct to me, and it compiles fine, but

Solution 1:

If you want to use color values in range [0.0, 1.0] then you've to use glVertexAttrib4f rather than glVertexAttribI4i:

glVertexAttribI4i(aColor,1,1,1,1)

glVertexAttrib4f(aColor,1.0f,1.0f,1.0f,1.0f)

glVertexAttribI* assumes the values to be signed or unsigned fixed-point values in range [-2147483647, 2147483647] or [0, 4294967295]. A value of 1 is almost black.


The type of the u_LightPos is floating point (vec3):

uniform vec3 u_LightPos; 

You've to use glUniform3f rather than glUniform3ito set the value of a floating point uniform variable:

glUniform3i(uLightPos,-1,-10,-1)

glUniform3f(uLightPos,-1f,-10f,-1f)

I recommend to verify if the shader is complied successfully by glGetShaderiv (parameter GL_COMPILE_STATUS). Compile error messages can be retrieved by glGetShaderInfoLog


I recommend to add an ambient light component (for debug reasons) e.g.:

v_Color = a_Color*(diffuse + 0.5);

If you can "see" the geometry with the ambient light, then there are some possible issues:

  1. the light source is on the back side of the geometry, so the back side is lit, but not the front side. That cause that only the almost black, unlit side is visible from the point of view.

  2. The distance of the light source to the geometry is "too large". distance becomes a very huge value and so diffuse is very small and all the geometry is almost black.

  3. The light source is in the closed volume of the geometry.

  4. All the normal vectors point away from the camera. That may cause that dot(normal, lightVector) is less than 0.0.

Post a Comment for "Opengl Es 2.0 / Glsl Not Rendering Data (kotlin)"