how to set the FrameBuffer to alpha

Started by Davi, October 29, 2011, 07:37:32 PM

Previous topic - Next topic

Davi

I want to use camera as the background in my AR project,but I don't know how to set the FrameBuffer(fb) to be transparent in my onDrawFrame() function. my code as below:

        onDrawFrame(GL10 gl){
                 fb=new FrameBuffer(gl, this.getWidth(),this.getHeight);
                 RGBColor transp = new RGBColor(?,?,?,?);
fb.clear(transparent);
world.renderScene(fb);
world.draw(fb);
fb.display();
        }

it always show black or other color background,can you tell me how to set it to be transparent?

EgonOlsen

You simply clear with an RGBColor with alpha. That's all there is to do from the engine side. You might have to do some additional setup work, which i don't really know. Maybe this threads helps: http://www.jpct.net/forum2/index.php/topic,1586.0.html

Davi

#2

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

      world = new World();
      world.setAmbientLight(150, 150, 150);   
      TextureManager.getInstance().addTexture("tris3", new Texture(BitmapFactory.decodeResource(this.getResources(), R.drawable.tris3)));
      snork = Loader.loadMD2(LoadAssets.loadf("tris3.md2"), scale);
      snork.setTexture("tris3");
      snork.strip();
      snork.build();
      world.addObject(snork);
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
      if (fb != null) {
         fb = null;
      }

      this.width=width;
      this.height=height;
      fb = new FrameBuffer(gl,width, height);
}
onDrawFrame(GL10 gl) {
      doAnim();
      world.renderScene(fb);
      world.draw(fb);
      fb.display();
}

above is my key code to show texture,the md2 model loading is ok and the camera vedio as the background but the texture can't show on the model,I don't know what wrong is?if I  change the OnDrawFrame(GL10 gl) function to below:

OnDrawFrame(GL10 gl) {
      fb=new FrameBuffer(gl, this.getWidth(),this.getHeight());
      doAnim();
      world.renderScene(fb);
      world.draw(fb);
      fb.display();
}

run above code,it can see the texure on the model but it can't show the camera as the background,the background is just black!!
Please help me ?

EgonOlsen

I don't get it...what's your actual problem now? That either the camera is visible in the background but then there's no texture or if there's a texture, then there's no camera background? Maybe a screen shot would help to clarify this... ???

Davi

#4
yeh,That either the camera is visible in the background but then there's no texture or if there's a texture, then there's no camera background.
there is a screen shot in attachments.
I don't know where the problem is ?please help me?

[attachment deleted by admin]

EgonOlsen

Can you post the complete log from the latter case?

Davi

#6
the logcat is the issue of no texture:

I/jPCT-AE (11870): Loading Texture...
I/jPCT-AE (11870): Loading file from InputStream
I/jPCT-AE (11870): Expanding buffers...16384 bytes
I/jPCT-AE (11870): Expanding buffers...24576 bytes
I/jPCT-AE (11870): Expanding buffers...32768 bytes
I/jPCT-AE (11870): Expanding buffers...40960 bytes
I/jPCT-AE (11870): Expanding buffers...49152 bytes
I/jPCT-AE (11870): Expanding buffers...57344 bytes
I/jPCT-AE (11870): Expanding buffers...65536 bytes
I/jPCT-AE (11870): Expanding buffers...73728 bytes
I/jPCT-AE (11870): Expanding buffers...81920 bytes
I/jPCT-AE (11870): Expanding buffers...163840 bytes
I/jPCT-AE (11870): Expanding buffers...245760 bytes
I/jPCT-AE (11870): Expanding buffers...327680 bytes
I/jPCT-AE (11870): Expanding buffers...409600 bytes
I/jPCT-AE (11870): File from InputStream loaded...346308 bytes
I/jPCT-AE (11870): Magic number: 844121161
I/jPCT-AE (11870): Version: 8
I/jPCT-AE (11870): Skin width: 256
I/jPCT-AE (11870): Skin height: 256
I/jPCT-AE (11870): Frame size: 1612
I/jPCT-AE (11870): Number of skins: 5
I/jPCT-AE (11870): Number of Vertices: 393
I/jPCT-AE (11870): Number of Texture coordinates: 561
I/jPCT-AE (11870): Number of triangles: 764
I/jPCT-AE (11870): Number of GL-commands: 3833
I/jPCT-AE (11870): Number of Frames: 198
I/jPCT-AE (11870): Reading Texture coordinates...
I/jPCT-AE (11870): Done!
I/jPCT-AE (11870): Reading polygonal data...
I/jPCT-AE (11870): Done!
I/jPCT-AE (11870): Reading keyframes...
I/jPCT-AE (11870): Done!
I/jPCT-AE (11870): Coverting MD2-format into jPCT-format...
I/jPCT-AE (11870): Processing: stand...
I/jPCT-AE (11870): Processing: run...
I/jPCT-AE (11870): Processing: attack...
I/jPCT-AE (11870): Processing: pain...
I/jPCT-AE (11870): Processing: jump...
I/jPCT-AE (11870): Processing: flipoff...
I/jPCT-AE (11870): Processing: salute...
I/jPCT-AE (11870): Processing: taunt...
I/jPCT-AE (11870): Processing: wave...
I/jPCT-AE (11870): Processing: point...
I/jPCT-AE (11870): Processing: crstand...
I/jPCT-AE (11870): Processing: crwalk...
I/jPCT-AE (11870): Processing: crattack..
I/jPCT-AE (11870): Processing: crpain...
I/jPCT-AE (11870): Processing: crdeath...
I/jPCT-AE (11870): Processing: deatha...
I/jPCT-AE (11870): Processing: deathb...
I/jPCT-AE (11870): Processing: deathc...
I/jPCT-AE (11870): Done!
I/jPCT-AE (11870): Normal vectors calculated in 88ms!
I/jPCT-AE (11870): OpenGL vendor:     Qualcomm
I/jPCT-AE (11870): OpenGL renderer:   Adreno 205
I/jPCT-AE (11870): OpenGL version:    OpenGL ES-CM 1.1
I/jPCT-AE (11870): OpenGL renderer initialized (using 2 texture stages)
I/jPCT-AE (11870): Using vm based buffer copies!
I/jPCT-AE (11870): Remapping 642 vertex indices!
I/jPCT-AE (11870): Creating vertex cache (15408 bytes)!
I/jPCT-AE (11870): Vertex indices will be mapped!
I/jPCT-AE (11870): Subobject of object 0/object2 compiled to indexed fixed point data using 2292 vertices in 70ms!
I/jPCT-AE (11870): Object 0/object2 compiled to 1 subobjects in 88ms!
I/jPCT-AE (11870): Object 'object2' uses one texture set!
I/jPCT-AE (11870): VBO created for object 'object2'

what's wrong with that?

EgonOlsen

No idea. Can you provide a test case for this?

EgonOlsen

In addition, it would be nice to see the log output when you do a call to Logger.setLogLevel(Logger.DEBUG); at the beginning of the application.

Davi

#9
I found that,if I draw camera Texture without using jpct-ae,and then draw md2 model texture using jpct-ae,it can't show the model texture. if I comment the code about drawing camera Texture, and then draw md2 model texture,it can show the texture.it's so strange!!!
maybe camera Texture effects the model texture.
question: jpct-ae's texture whether can be effected by any other thing or not? how to solve it? please

Davi

oh,thank you ,I have figure it out. when I draw camera texture,I have disable some key code:
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

so,if use above codes before I draw other texure,it will never show texture on other models.

EgonOlsen

#11
Is it a new sport to kludge gl commands directly into the app while you are actually using a 3D engine that does this for you? As i've already written recently in another thread, you are NOT supposed to do this. You are disabling texturing, texture coordinates and vertex arrays with that stuff. It's a miracle that at least something appears on screen after that. How should the engine be able to handle this, if you pull the rug out from under it's feet by modifying the gl state at will? IF you have to do this for whatever reason, make sure that you reset it to the former state afterwards, i.e. read and store the current, set your new, do your stuff and reset the stored state. Everything else will screw up your rendering.
In addition, i don't see the need for these lines just to put the camera into the background. It has been done before and as far as i know, nobody needed to fiddle around with gl directly to do it. And finally, if you want to switch to GL ES 2.0 at some time, your app will go BOOM with these lines in it...