Main Menu
Menu

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.

Show posts Menu

Messages - ginopeloso

#1
Support / Re: assign a GL texture to an Object3D
April 07, 2017, 05:14:17 PM
After setting mipmap, created the FrameBuffer without the GL10 param and calling mGLView.setEGLContextClientVersion(2); now I see a black texture rather than the video, but no errors... also added synchronization when updating the texture but still nothing. I feel I'm near!  :'(
#2
Support / Re: assign a GL texture to an Object3D
April 07, 2017, 07:51:30 AM
Actually I just tried with an image and the message appears too, but the image is correctly shown as texture (the image has been applied with a JPCT Texture), so the problem is not that error but something else related to the external texture.
#3
Support / Re: assign a GL texture to an Object3D
April 06, 2017, 05:23:28 PM
Yes, I'm doing those exactly there.


        public void onDrawFrame(GL10 gl) {
            if (textureId < 0) {
                startPlayer();  // this method contains the SurfaceTexture initialization (the previous post's code)
            }

            if (updateVideoTexture) {
                surfaceTexture.updateTexImage();
                updateVideoTexture = false;
            }

            ...
        }
#4
Support / Re: assign a GL texture to an Object3D
April 06, 2017, 03:21:17 PM
Just now, the result is the same  :-\
#5
Support / Re: assign a GL texture to an Object3D
April 06, 2017, 11:18:06 AM
I'm trying to follow this post to play a video as a texture over an Object3D. Is it necessary to create my own shader?
In other OpenGL projects I already played a video as a texture, here I'm having problems.

I do these steps:


        // create a new texture
        int[] textureIdVector = new int[1];
        GLES20.glGenTextures(1, textureIdVector, 0);
        textureId = textureIdVector[0];
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        // create an external texture
        Texture externalTexture = new Texture(32, 32);
        externalTexture.setExternalId(textureId, GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
        TextureManager.getInstance().addTexture("video", externalTexture);

        // create the SurfaceTexture, the Surface and the MediaPlayer
        surfaceTexture = new SurfaceTexture(textureId);
        Surface surface = new Surface(surfaceTexture);
        mediaPlayer.setSurface(surface);
        surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
            @Override
            public void onFrameAvailable(SurfaceTexture surfaceTexture) {
                // in the onDrawFrame method I call "surfaceTexture.updateTexImage()"
                updateVideoTexture = true;
            }
        });

        // tv is my Object3D on which I want to apply the video texture
        tv.setTexture("video");

        mediaPlayer.setLooping(true);
        mediaPlayer.start();


If I try with an image as texture it works good, since I don't have an external texture but just a jpct's Texture object. This way, instead, I see nothing. The video correctly starts, because I hear its sound but I can't see it over the object.

Another thing, when I create the SurfaceTexture passing the OpenGL's texture id I see this message in logs:
W/Adreno-EGL: <qeglDrvAPI_eglQueryContext:4370>: EGL_BAD_ATTRIBUTE

Can someone say where is the problem in all this code?
#6
Support / Loading texture in a more efficent way
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?


        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);
        bitmap.recycle();

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

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


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
#7
It worked perfectly!  :D :D :D
Also the fact that the OpenGL's zero is on the bottom...

There was another error: I was using the FrameBuffer's constructor with the GL10 parameter (the one for OpenGL ES 1.0/1.1)...
#8
Using the following code:


NPOTTexture blitTexture = new NPOTTexture(mFrameBuffer.getWidth()/2, mFrameBuffer.getHeight(), RGBColor.GREEN);

mFrameBuffer.setRenderTarget(blitTexture);
mWorld.renderScene(mFrameBuffer);
mWorld.draw(mFrameBuffer);
mFrameBuffer.display();
mFrameBuffer.removeRenderTarget();

mFrameBuffer.blit(blitTexture, 0, 0, 0, 0, blitTexture.getWidth(), blitTexture.getHeight(), false);
mFrameBuffer.blit(blitTexture, 0, 0, mFrameBuffer.getWidth() / 2, 0, blitTexture.getWidth(), blitTexture.getHeight(), false);
mFrameBuffer.display();


I see two green rectangles (look at the first line). It means that blitTexture has been correctly blitted on the FrameBuffer; the problem is that mFrameBuffer does not render on blitTexture
#9
I have to display the same scene on the left half and on the right one (when I started the question I had two worlds, now I have just one world and need to display the same scene of that world on two parts of the screen).
#10
Following your explanation I wrote the following code (which does not work as expected):


// create a NPOTTexture with same height and half width of the framebuffer
NPOTTexture blitTexture = new NPOTTexture(mFrameBuffer.getWidth()/2, mFrameBuffer.getHeight(), RGBColor.GREEN);

// draw the scene on the texture
mFrameBuffer.setRenderTarget(blitTexture);
mWorld.renderScene(mFrameBuffer);
mWorld.draw(mFrameBuffer);
mFrameBuffer.removeRenderTarget();

// draw the texture on the left half of the framebuffer...
mFrameBuffer.blit(blitTexture, 0, 0, 0, 0, blitTexture.getWidth(), blitTexture.getHeight(), false);
// ...and also on the right half
mFrameBuffer.blit(blitTexture, 0, 0, mFrameBuffer.getWidth()/2, 0, blitTexture.getWidth(), blitTexture.getHeight(), false);


mFrameBuffer has the same size of the screen.
I only see the texture rendered on the left part (I think there is a big misunderstanding on the usage of the "blit" method).
#11
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).
#12
Support / Re: How to do 2D click to 3D object picking?
November 05, 2014, 05:57:50 PM
What if I don't want the first object in the direction of my click but the one behind it?
In my model I have some objects which are transparent (like glasses); if the user clicks these ones I have to ignore them and try to pick another object behind the clicked one in the same direction of the click (if this one is transparent again the one behind, until I pick a non-transparent object or nothing)

I tried with the following code but did not succeed; the app continues to pick always the same object:

SimpleVector dir = Interact2D.reproject2D3D(camera, frameBuffer, screenX, screenY);
Object[] res = world.calcMinDistanceAndObject3D(camera.getPosition(), dir, 10000);
Object3D clickedObject = (Object3D)res[1];
while (clickedObject != null && clickedObject.getName().startsWith("transparent")) {
dir.z = clickedObject.getTransformedCenter().z;
res = world.calcMinDistanceAndObject3D(camera.getPosition(), dir, 10000);
clickedObject = (Object3D)res[1];
}


Is there a way for doing it?
#13
Support / Click coordinates in object space
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 Interact2D.reproject2D3D I obtain the coordinates of the click in Camera Space.
With 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 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.

Thanks!