Question

when I'm running my app on ipad1 I see different result then when I'm running the same app on ipad2. I'm interested in book size in the middle of screen.

iPad1 result

iPad2 result

My code is below.

- (void)drawGallery{

glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);

ResourceManager *rm = [ResourceManager sharedInstance];
GLuint currProgram = [rm getProgram:PROGRAM_BASIC_LIGHTNING];

glUseProgram(currProgram);

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, 768, 1024 + 2 * GALLERY_OFFSET_Y);

GLfloat modelviewProj[16];

for (Sheet *sh in self.interfaceManager.gallery.sheets){

    if ([self.interfaceManager.gallery shouldDrawSheet:sh]){

        [self MakePerspectiveMatrix:modelviewProj 
                            OriginX:0.0 
                            OriginY:0.0 
                              Width:SCREEN_WIDTH 
                             Height:SCREEN_HEIGHT
                           Rotation:sh.rotation
                       TranslationX:sh.translationX 
                       TranslationZ:sh.translationZ
                             ScaleX:1.0
                             ScaleY:SCREEN_HEIGHT/(SCREEN_HEIGHT + 2 * GALLERY_OFFSET_Y)];


        vertexDataTextured *model;
        if (sh.type == SHEET_TYPE_LEFT){
            model = (vertexDataTextured *)[rm getModel:MODEL_SHEET_LEFT];
        } else {
            model = (vertexDataTextured *)[rm getModel:MODEL_SHEET_RIGHT];
        }


        // update uniform values

        glUniformMatrix4fv(basic_lighting_uniforms[BASIC_LIGHTING_UNIFORM_MODEL_VIEW_PROJECTION_MATRIX], 1, GL_FALSE, modelviewProj);

        glUniform1f(basic_lighting_uniforms[BASIC_LIGHTING_UNIFORM_ROTATION], degreeToRadians(-sh.rotation));

        glActiveTexture(GL_TEXTURE0);
        GLuint texture = [rm getTexture:TEXTURE_COLORING_PICTURE Index1:self.currentBook.number Index2:sh.number];
        glBindTexture (GL_TEXTURE_2D, texture);


        glUniform1i(basic_lighting_uniforms[BASIC_LIGHTING_UNIFORM_TEXTURE], 0);

        glVertexAttribPointer(BASIC_LIGHTING_ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(vertexDataTextured), &model[0].vertex);
        glEnableVertexAttribArray(BASIC_LIGHTING_ATTRIB_VERTEX);

        glVertexAttribPointer(BASIC_LIGHTING_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(vertexDataTextured), &model[0].texCoord);
        glEnableVertexAttribArray(BASIC_LIGHTING_ATTRIB_TEX_COORDS);

        glDrawArrays(GL_TRIANGLES, 0, 6);  

        if (![self validateProgram:currProgram]) {
            NSLog(@"Failed to validate program: (%d)", currProgram);
        }
    }
}
}

Vertex Shader:

uniform mat4 modelViewProjectionMatrix;
uniform float rotation;
attribute lowp vec3 position;
attribute lowp vec2 texCoords;
varying lowp vec2 fTexCoords;
varying lowp vec4 computed_color;

void main()
{ 
    fTexCoords = texCoords;

    vec4 postmp = vec4(position.xyz, 1.0);
    vec4 newposition = modelViewProjectionMatrix * postmp;
    gl_Position = newposition;

    vec3 ambient_color = vec3(0.5, 0.5, 0.5);
    vec3 norm = vec3(sin(rotation), 0.0, cos(rotation));

    vec3 light_position1 = vec3(15.0, 0.0, 20.0);
    vec3 light_direction1 = normalize( vec3 (0.2, 0.0, 1.0) );
    vec4 light_diffuse_color1 = vec4 (0.4, 0.4, 0.4, 1.0);
    float ndotl1 = max(0.0, dot(light_direction1, norm));
    vec4 temp_color1 = ndotl1 * light_diffuse_color1 * 15.0 / (length(light_position1 - newposition.xyz));

    vec3 light_position2 = vec3(-30.0, 0.0, 25.0);
    vec3 light_direction2 = normalize( vec3(-0.2, 0.0, 1.0) );
    vec4 light_diffuse_color2 = vec4 (0.5, 0.5, 0.5, 1.0);
    float ndotl2 = max(0.0, dot(light_direction2, norm));
    vec4 temp_color2 = ndotl2 * light_diffuse_color2 * 15.0 / (length(light_position2 - newposition.xyz));

    computed_color = vec4(temp_color1.rgb + temp_color2.rgb + ambient_color, 1.0);
}

Fragment shader:

precision lowp float;
uniform sampler2D texture;
varying vec2 fTexCoords;
varying lowp vec4 computed_color;

void main()
{
    gl_FragColor = texture2D(texture, fTexCoords) * computed_color;
}
Was it helpful?

Solution

The problem was in lowp presicion for position. Thanks to Brad Larson.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top