jPCT-AE - a 3d engine for Android > Support

How to get a texture from a FrameBuffer?

(1/3) > >>

Darkflame:
Trying to get a texture from a framebuffer but its coming out totally transparent/unset :?


--- Code: ---//set up font
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTypeface(Typeface.create((String)null, Typeface.BOLD));
paint.setTextSize(16);
glFont = new GLFont(paint);


//created a new framebuffer to render the texture too
Texture textTexture = new Texture(60,60, RGBColor.BLACK);
FrameBuffer meep = new FrameBuffer(gl, 100, 100);

meep.setRenderTarget(textTexture);
meep.clear(RGBColor.BLACK);
glFont.blitString(meep, " test test test! ",
5, 5, 10, RGBColor.WHITE);
meep.display();

--- End code ---

(that texture is then applied to a mesh, but it doesn't show up)

Probably something I'm not understanding about the process here.

EgonOlsen:
There are a few things to consider:


* The render-to-texture code of jPCT-AE is totally untested. It's a straight port from the desktop version, so it should work if Android's drivers work correctly...but as we all know, they don't. So there is a chance that it won't work even if everything else is correct.
* Make sure that your texture has a power of two size that's smaller than the framebuffers. 60*60 isn't a good size, use 64*64 instead.
* Make sure to remove the render target before using the texture in the actual rendering.
* There's still a little ugliness in jPCT (both versions) when is comes to blitting: It requires that a world has been rendered at least once into the buffer to blit into. Any world will do. Try something like:

--- Code: ---                        Texture textTexture = new Texture(64,64, RGBColor.BLACK);
FrameBuffer meep = new FrameBuffer(gl, 100, 100);
                        World tw=new World();
                        tw.renderScene(meep);
                        tw.draw(meep);
                        meep.display();

meep.setRenderTarget(textTexture);
meep.clear(RGBColor.BLACK);
glFont.blitString(meep, " test test test! ",
5, 5, 10, RGBColor.WHITE);
meep.display();

--- End code ---

Where are you calling this? In onDrawFrame()?

Darkflame:

--- Quote from: EgonOlsen on May 15, 2010, 10:30:35 pm ---
* The render-to-texture code of jPCT-AE is totally untested. It's a straight port from the desktop version, so it should work if Android's drivers work correctly...but as we all know, they don't. So there is a chance that it won't work even if everything else is correct.
* Make sure that your texture has a power of two size that's smaller than the framebuffers. 60*60 isn't a good size, use 64*64 instead.
--- End quote ---

Done.
I noticed I couldnt have textures of 90x90 early because it got a
"- ERROR: Can't render into a texture larger than the current framebuffer!"
error. (despite the fact the framebuffer  is specified as 100,100)
Was this because it was rounding up internally to 128x128?


--- Quote ---
* Make sure to remove the render target before using the texture in the actual rendering.
* There's still a little ugliness in jPCT (both versions) when is comes to blitting: It requires that a world has been rendered at least once into the buffer to blit into. Any world will do. Try something like:

--- Code: ---                        Texture textTexture = new Texture(64,64, RGBColor.BLACK);
FrameBuffer meep = new FrameBuffer(gl, 100, 100);
                        World tw=new World();
                        tw.renderScene(meep);
                        tw.draw(meep);
                        meep.display();

meep.setRenderTarget(textTexture);
meep.clear(RGBColor.BLACK);
glFont.blitString(meep, " test test test! ",
5, 5, 10, RGBColor.WHITE);
meep.display();

--- End code ---

--- End quote ---

Thanks for your help, but I gave that a go and still nothing/transparent. :(
Not sure where to put that meep.removeRenderTarget(); though. Is it rendered into the texture on that ".display()", and thus any time after will do?


--- Quote ---Where are you calling this? In onDrawFrame()?

--- End quote ---

No, onSurfaceCreate() at the moment.
What I really want to do is create a texture based on some text at any point though.

My goal is to effectively make a "add marker here" function. Which, given some text, and a position, will display a billboard with the text on at that position.
So far Ive made the billboard, complete with my own rectangle object...


Now I'm trying to assign a custom texture at that point.


[attachment deleted by admin]

EgonOlsen:
No idea...maybe it just isn't working in the way it should because of some driver issues. It wouldn't be the first thing that is on Android. However, it's better if you can manage to render the text into an int[]-array or at least a Bitmap anyway. With both, you can create (Bitmap) or update (int[] via an ITextureEffect, the prefered way) a texture and use that as texture for your billboard. Raft's GlFont class creates textures with those letters too, so it may help as a starting point.

raft:

--- Quote ---
--- Quote ---Where are you calling this? In onDrawFrame()?

--- End quote ---
No, onSurfaceCreate() at the moment.

--- End quote ---
i would definitely try running it in onDrawFrame() in this case..

Navigation

[0] Message Index

[#] Next page

Go to full version