Log in or register to post comments

Vuforia render camera in custom/Gdx render engine

January 23, 2014 - 3:53am #1

Hi,

I'm working on the integration of Vuforia in a libgdx render.

I followed this page : https://developer.vuforia.com/resources/dev-guide/opengl-state-changes-video-background-renderer  but i'm not sure to undesrtand what is called and when because my code looks like that : 

 

Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

Gdx.gl.glDisable(GL10.GL_CULL_FACE);
Gdx.gl.glDisable(GL10.GL_DEPTH_TEST);

State state = mRenderer.begin();     
mRenderer.drawVideoBackground();

Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
Gdx.gl.glEnable(GL10.GL_CULL_FACE);

my3DCamera.update();

//now render the 3D scene
mbatch.begin(camera);
cube.render(mbatch, lights);
mbatch.end();

mRenderer.end();
 
 
The result is the background being rendered in a little part of the phone screen... and the 3D cube being renderer well in the center of the screen.
I don't understand what is the problem ...
 
Any idea or advice would be very appreciated.
 
thanks a lot.

Vuforia render camera in custom/Gdx render engine

October 21, 2014 - 12:14pm #16

Hi, I found this thread looking for how to display the videobackground. I tried your code and got the same effect. 

To fix it I took a different approuch that what this thread shows.

When setting the camera up the position was set to (0, 0). I changed this to half width and half height like so:

CameraDevice cameraDevice = CameraDevice.getInstance();
        VideoMode vm = cameraDevice.getVideoMode(CameraDevice.MODE.MODE_DEFAULT);
        VideoBackgroundConfig config = new VideoBackgroundConfig();
        config.setPosition(new Vec2I(mScreenWidth/2, mScreenHeight/2));  //  <---- this was config.setPosition(new Vec2I(0, 0)); in the original example code
 
After making that change the Renderer now displays the video across the entire screen with objects rendered by libGDX on top of it.
 
Hopefully this can help anyone else who runs into this problem.

Vuforia render camera in custom/Gdx render engine

January 30, 2014 - 5:28am #15

Nice, thanks for sharing.

Vuforia render camera in custom/Gdx render engine

January 30, 2014 - 4:40am #14

To conclude on how to make a Vuforia integration with libgdx, here is a sample on how to render a 3D object using the vuforia bind() method : 

https://gist.github.com/VinceAngel/8707565

 

 

Vuforia render camera in custom/Gdx render engine

January 30, 2014 - 2:40am #13

ok i think i found what you ment:

 

         VideoBackgroundTextureInfo texInfo = Renderer.getInstance()
            .getVideoBackgroundTextureInfo();
        // These calculate a slope for the texture coords
        float uRatio = ((float) texInfo.getImageSize().getData()[0] / (float) texInfo
            .getTextureSize().getData()[0]);
        float vRatio = ((float) texInfo.getImageSize().getData()[1] / (float) texInfo
            .getTextureSize().getData()[1]);

 

 

Vuforia render camera in custom/Gdx render engine

January 30, 2014 - 2:19am #12

If you download the Vuforia samples, you will find one that is called "BackgroundTextureAccess".

 

Vuforia render camera in custom/Gdx render engine

January 30, 2014 - 2:16am #11

where can I find the "Background Texture Access sample code" you mentioned`?

Vuforia render camera in custom/Gdx render engine

January 28, 2014 - 2:26am #10

That's correct; the video background texture may contain some black areas (borders), due to the difference between the texture size and the actual width/height of the video image; check the Background Texture Access sample code, which shows all the maths involved to compute the right UV texture coordinates so to be able to capture only the relevant part of the texture.

 

Vuforia render camera in custom/Gdx render engine

January 28, 2014 - 1:45am #9

A little more question if you don't mind : 

 

How the texture coordinates are managed on the binding ?

I mean, is the texture full of camera's pixels ? I have some black borders on my rect rendering the texture, and my UV's are from 0 to 1.

Thanks!

 

Edit : 

This is in my logs :

01-28 10:41:41.366: I/Vuforia_Sample_Applications(10499): Configure Video Background : Video (640 , 480), Screen (854 , 480), mSize (854 , 640)

Something to understand about that ?

Vuforia render camera in custom/Gdx render engine

January 27, 2014 - 8:03am #8

Yes, that would be nice.

Vuforia render camera in custom/Gdx render engine

January 27, 2014 - 7:36am #7

Ok thanks.

I thing I got it, it's more or lesse running, I'll fix some issues.

Maybe you'll be interesseted in an article on vuforia integration with libgdx 3D engine when working ?

Vuforia render camera in custom/Gdx render engine

January 27, 2014 - 7:07am #6

The bindVideoBackground simply binds a texture; this is equivalent to binding a texture in OpenGL; 

this emans that any subsequent geometry that you render will be textured by that texture (the video background), provided that:

- you don't bind another texture in your own engine (i.e. you don' overwrite the video texture with your own)

- your mesh has texture coordinates

 

Vuforia render camera in custom/Gdx render engine

January 27, 2014 - 6:54am #5

So, If I bindVideoBackground instead fo rendering it, do I need to make something more ?

Are there some limitations ?

For now, each frame I call begin() then bindVideoBackground(n), [Here I try to render a quad with the binded texture in my 3D engine] and of course end()

Thanks.

Vuforia render camera in custom/Gdx render engine

January 23, 2014 - 1:36pm #4

In order to render the Video Background, you can use the method bindVideoBackground() (instead of using drawVideoBackground);

this method simply binds the video BG texture, so you should not need to copy any buffer into a texture (i.e. Vuforia generates the texture internally and inds it);

then you could try to apply the texture to a geometry of your choice, such as a simple Quad; if this works, then you could resize the quad so to fit the screen.

The Background Texture Access shows the maths for computing the quad size for rendering the BG texture.

If you experiment a bit using the biindVideoBackground(), it should be possible to find the correct setup.

 

Vuforia render camera in custom/Gdx render engine

January 23, 2014 - 9:36am #3

My engine is at an upper level, it is based on OpenGL, but there are some objects such as perspertive camera, orthographic camera, Modelinstances for 3D objects.

The 2D objects can be rendered via a batch based on an ortho2D projection, but the settings are a mystery for me, even with the vuforia examples.

 

I also tried to get the image buffer to make the BG render by myself, but the buffer had issues beeing converted to a texture...

Vuforia render camera in custom/Gdx render engine

January 23, 2014 - 9:00am #2

Is you engine acting on OpenGL state such as the glViewport coordinates, or the near and far clip planes ?

Also, you may want to check thr Background Texture Access sample, which shows how to render the video texture on a mesh, and illustrates all the OpenGL commands involved in the process.

This might shed some light on possible conflicts with your engine.

 

Log in or register to post comments