Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:56:03+00:00 2026-06-17T05:56:03+00:00

I’m developipng an 2D live wallpaper for Andoid using libgdx and its SpriteBatch class.

  • 0

I’m developipng an 2D live wallpaper for Andoid using libgdx and its SpriteBatch class. This is a watch, so all I need, from libgdx is just drawing multiple textures, rotating them to specific angle.

I’ve solved this problem using SpriteBatch class and all was fine.

But now I need to add magnifying lens effect to my scene. Task is to magnify specific area with specific ratio to simulate real lens.

I’ve solved this by rendering to FrameBuffer, getting texture region from FrameBuffer and finally, drawing this region with custom shader, using SpriteBatch.

THE PROBLEM: on Samsung devices (I’ve tried on galaxy note N7000, and on Galaxy Tab 10.1) there is a small rectangle in the center of magnifying area about 16x16px, where magnification ratio slightly increases. Sorry, I can’t post a screenshot now, because I don’t have Samsung device.
On other devices all works fine, tried in HTC Vivid, Acer A500, Google Nexus One.

I think, the problem if in Mali GPU on Samsung devices, but don’t know, how to fix it.

I’ve adapted fragment shader code from this question to SpriteBatch Add Fisheye effect to images at runtime using OpenGL ES
Here is it:

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

varying LOWP vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;

void main() {
vec2 m = vec2(0.622 , 0.4985); // lens center point, note that in live wallpaper center of texture is (0.5,0.5)
float lensSize = 0.045; //diameter of lens
float lensCut = 0.0342; //length of cut lines

vec2 d = v_texCoords - m;
float r = sqrt(dot(d, d)); // distance of pixel from mouse
float cuttop = m.y + lensCut;
float cutbottom = m.y - lensCut; 

vec2 uv;
if (r >= lensSize) {
    uv = v_texCoords;
} else  if ( v_texCoords.y >= cuttop) {
    uv = v_texCoords;
}  else  if (v_texCoords.y <= cutbottom) {
    uv = v_texCoords;
} else {
    uv = m + normalize(d) * asin(r) / (3.14159 * 0.37);
}

gl_FragColor = texture2D(u_texture, uv);
}

Vertex shader is default from SpriteBatch sources:

attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying vec4 v_color;
varying vec2 v_texCoords;

void main() {
    v_color = a_color;
    v_texCoords = a_texCoord0;
    gl_Position = u_projTrans * a_position;
}

Here is my render() method:

    GL20 gl = Gdx.graphics.getGL20();
    gl.glEnable(GL20.GL_TEXTURE_2D);
    gl.glActiveTexture(GL20.GL_TEXTURE0);

    gl.glClearColor(WallpaperService.bg_red, WallpaperService.bg_green, WallpaperService.bg_blue, 1f);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


    // Creating framebuffer, if it has gone
    if (mFrameBuffer == null) {
        mFrameBuffer = new FrameBuffer(Format.RGBA4444, BG_WIDTH, BG_HEIGHT, true);

        mFrameBufferRegion = new TextureRegion(mFrameBuffer.getColorBufferTexture());
        mFrameBufferRegion.flip(false, true);

    }

    //Camera setting according to background texture
    camera = new OrthographicCamera(BG_WIDTH, BG_HEIGHT);
    camera.position.set(BG_WIDTH / 2, BG_WIDTH / 2, 0);
    camera.update();
    batch.setProjectionMatrix(camera.combined);

    //Rendering scene to framebuffer
    mFrameBuffer.begin();
    batch.begin();
    //main Drawing goes here
    batch.end();

    //Drawing frame to screen with applying shaders for needed effects
    if (mFrameBuffer != null) {
        mFrameBuffer.end();

        camera = new OrthographicCamera(width, height);
        camera.position.set(width / 2, height / 2, 0);
        camera.update();
        batch.setProjectionMatrix(camera.combined);

        batch.begin();
        batch.setShader(null);

        batch.setShader(shader);

        batch.draw(mFrameBufferRegion, width / 2 - (BG_WIDTH / 2) + (MARGIN_BG_LEFT * ratio), height / 2
                - (BG_HEIGHT / 2) + (MARGIN_BG_TOP * ratio), (float) BG_WIDTH / 2, (float) BG_HEIGHT / 2,
                (float) BG_WIDTH, (float) BG_HEIGHT, (float) ratio, (float) ratio, 0f);

        batch.setShader(null);
        batch.end();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:56:04+00:00Added an answer on June 17, 2026 at 5:56 am

    I’ve managed to fix this issue. The problem is in Mali gpu.
    Mali doesn’t support high precision float calculations in fragment shader.
    When distance from center to point was near zero – r variable became zero.

    So I’ve added constant coefficient to my calculations and this did the trick.

    Here is working fragment shader:

    precision mediump float;
    
    varying lowp vec4 v_color;
    varying vec2 v_texCoords;
    
    
    uniform sampler2D u_texture;
    
    const float PI = 3.14159;
    const float koef = 10.0;
    void main() {
         vec2 uv;     
        vec2 m = vec2(0.622 , 0.4985); // lens center point, note that in live wallpaper center of texture is (0.5,0.5)
        float lensSize = 0.045; //radius of lens
        float lensCut = 0.0342; //height of cut
    
        float cuttop = m.y + lensCut;
        float cutbottom = m.y - lensCut;
        float cutleft = m.x-lensSize;
        float cutright = m.x+lensSize;
    
    //don't transform pixels, that aren't in lens area
         if ( v_texCoords.y >= cuttop) {
            uv = v_texCoords;
        }  else  if (v_texCoords.y <= cutbottom) {
            uv = v_texCoords; 
               }  else  if (v_texCoords.x <= cutleft) {
            uv = v_texCoords; 
               }  else  if (v_texCoords.x >= cutright) {
            uv = v_texCoords; 
            } else {
        vec2 p = v_texCoords*koef; //current point 
        vec2 d = p - m*koef; //vector differnce between current point and center point
        float r = distance(m*koef,p); // distance of pixel from center
    
        if (r/koef >= lensSize) {
            uv = v_texCoords;
          } else {
        uv =m + normalize(d) * asin(r) / (PI*0.37*koef);
        }  
        }
    
       gl_FragColor = texture2D(u_texture, uv);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.