Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - ginopeloso

Pages: [1]
Support / Loading texture in a more efficent way
« on: August 02, 2015, 06:57:13 pm »
I need to load a texture starting from a non-squared image. The final image must be squared (with both height and width power of 2), than I am forced to load the bitmap in memory, complete it with a useless part (in order to obtain a squared bitmap) and then create a texture with it. The whole process consumes too much memory (I have very big textures, 1024x1024, 2048x2048 or also 4096x4096). Is there a smarter way for creating textures?

Code: [Select]
        int maxTextureSize = calcMaxTextureSize(); // the max size in pixels that GLSurfaceView can render on this device (tipically 2048, or 4096 for newer devices, however a power of 2)

        // do not load bitmap, just decode its bounds
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inSampleSize = 1;
        BitmapFactory.decodeFile(filepath, options);

        int width = options.outWidth;
        int height = options.outHeight;

        // scale down the image if it is bigger than the maxTextureSize
        while (width / (float) options.inSampleSize > maxTextureSize || height / (float) options.inSampleSize > maxTextureSize) {
            options.inSampleSize *= 2; // inSampleSize must be a power of 2 (1, 2, 4, 8, etc... that's why this line)

        // now load the bitmap
        options.inJustDecodeBounds = false;

        Bitmap bitmap = BitmapFactory.decodeFile(filepath, options); // decode the real bitmap, ONE
        int dim = Math.max(bitmap.getWidth(), bitmap.getHeight());

        // now put it in a squared bitmap (it will be used as a texture, then it must be square (dim x dim))
        Bitmap textureBitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.RGB_565); // TWO bitmaps
        Canvas canvas = new Canvas(textureBitmap);
        canvas.drawBitmap(bitmap, 0, 0, null);

        // The texture must be a power-of-2 bitmap, then resize it... THREE bitmaps
        Bitmap scaledTexture = Bitmap.createScaledBitmap(textureBitmap, maxTextureSize, maxTextureSize, false);

        Texture texture = new Texture(scaledTexture, false);
        TextureManager.getInstance().addTexture(textureName, texture); // ANOTHER bitmap in memory

As you can see there are too many passes, and too many bitmaps allocated in memory before I can have the final texture:
1. Decode the original bitmap, not the whole one but the maximum size supported by the device
2. Put it on a square (with a useless part)
3. Resize it, in order to have a power-of-2 texture
4. Create a Texture object with that bitmap

Support / Need to render two worlds on two GLSurfaceView
« on: July 20, 2015, 05:57:08 pm »
I know it is not possible to have two GLSurfaceView on the same layout. Basically I need to render the same scene (the same world) on two separated parts of my screen. I've read it is possible to use TextureViews, but I can't draw my FrameBuffer on a TextureView...
The question is simple: is there a way for drawing the same World on two parts of the same GLSurfaceView (one on the left half of the screen and one on the right half).

Support / Click coordinates in object space
« on: October 24, 2014, 05:06:36 pm »
I have the following situation: a user clicks on the screen and the app gets the screen coordinates of the click.

With the method
Code: [Select]
Interact2D.reproject2D3D I obtain the coordinates of the click in Camera Space.
Code: [Select]
Interact2D.reproject2D3DWS I obtain the coordinates in World Space. How can I obtain the same coordinates in Object Space?

I need to change the X and the Y of the rotation pivot of the object in the point of the object where the user clicks. As the doc says the method
Code: [Select]
Object3D.setRotationPivot sets the rotation pivot of the object. The rotation pivot is the point in objectspace around which the object will be rotated using its rotation matrix.


Pages: [1]