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.

Messages - ginopeloso

Pages: [1]
Support / Re: assign a GL texture to an Object3D
« on: April 07, 2017, 05:14:17 pm »
After setting mipmap, created the FrameBuffer without the GL10 param and calling
Code: [Select]
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!  :'(

Support / Re: assign a GL texture to an Object3D
« on: 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.

Support / Re: assign a GL texture to an Object3D
« on: April 06, 2017, 05:23:28 pm »
Yes, I'm doing those exactly there.

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

            if (updateVideoTexture) {
                updateVideoTexture = false;


Support / Re: assign a GL texture to an Object3D
« on: April 06, 2017, 03:21:17 pm »
Just now, the result is the same  :-\

Support / Re: assign a GL texture to an Object3D
« on: 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:

Code: [Select]
        // create a new texture
        int[] textureIdVector = new int[1];
        GLES20.glGenTextures(1, textureIdVector, 0);
        textureId = textureIdVector[0];

        // 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);
        surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
            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


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:
Code: [Select]
W/Adreno-EGL: <qeglDrvAPI_eglQueryContext:4370>: EGL_BAD_ATTRIBUTE
Can someone say where is the problem in all this code?

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 / Re: Need to render two worlds on two GLSurfaceView
« on: July 24, 2015, 10:04:39 am »
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)...

Support / Re: Need to render two worlds on two GLSurfaceView
« on: July 23, 2015, 05:23:38 pm »
Using the following code:

Code: [Select]
NPOTTexture blitTexture = new NPOTTexture(mFrameBuffer.getWidth()/2, mFrameBuffer.getHeight(), RGBColor.GREEN);


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);

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

Support / Re: Need to render two worlds on two GLSurfaceView
« on: July 23, 2015, 03:02:02 pm »
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).

Support / Re: Need to render two worlds on two GLSurfaceView
« on: July 23, 2015, 02:35:37 pm »
Following your explanation I wrote the following code (which does not work as expected):

Code: [Select]
// 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

// 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).

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 / Re: How to do 2D click to 3D object picking?
« on: 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:
Code: [Select]
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?

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]