Author Topic: how to set the FrameBuffer to alpha  (Read 5184 times)

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
how to set the FrameBuffer to alpha
« on: October 29, 2011, 07:37:32 pm »
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:
Code: [Select]
        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?
« Last Edit: October 29, 2011, 07:41:51 pm by Davi »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to set the FrameBuffer to alpha
« Reply #1 on: October 29, 2011, 10:32:42 pm »
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

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
Re: how to set the FrameBuffer to alpha
« Reply #2 on: October 30, 2011, 03:27:35 am »
Code: [Select]
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:
Code: [Select]
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 ?
« Last Edit: October 31, 2011, 02:25:25 am by Davi »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to set the FrameBuffer to alpha
« Reply #3 on: October 30, 2011, 07:53:47 pm »
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... ???

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
Re: how to set the FrameBuffer to alpha
« Reply #4 on: October 31, 2011, 02:32:32 am »
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]
« Last Edit: October 31, 2011, 02:50:13 am by Davi »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to set the FrameBuffer to alpha
« Reply #5 on: October 31, 2011, 07:03:56 am »
Can you post the complete log from the latter case?

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
Re: how to set the FrameBuffer to alpha
« Reply #6 on: October 31, 2011, 09:44:30 am »
the logcat is the issue of no texture:
Code: [Select]
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?
« Last Edit: October 31, 2011, 02:21:46 pm by Davi »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to set the FrameBuffer to alpha
« Reply #7 on: October 31, 2011, 03:11:00 pm »
No idea. Can you provide a test case for this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to set the FrameBuffer to alpha
« Reply #8 on: October 31, 2011, 07:55:51 pm »
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.

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
Re: how to set the FrameBuffer to alpha
« Reply #9 on: November 02, 2011, 03:17:10 am »
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
« Last Edit: November 02, 2011, 03:22:01 am by Davi »

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
Re: how to set the FrameBuffer to alpha
« Reply #10 on: November 02, 2011, 04:00:48 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to set the FrameBuffer to alpha
« Reply #11 on: November 02, 2011, 10:17:44 am »
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...
« Last Edit: November 02, 2011, 02:57:07 pm by EgonOlsen »