2013-11-20 3 views
4

libgdx와 PixMap을 사용하여 오버레이로 수정 된 텍스처를 반환하는 메서드를 만들려고합니다.libgdx는 pixmap을 사용하여 오버레이에서 텍스처를 만듭니다.

나는이 개 이미지가 가정하면부터는 다음 textureInput enter image description here

에서 기본 이미지와는 FileHandle 오버레이 오버레이 이미지를

enter image description here

그것은이 텍스처 생성한다 :

enter image description here

그래서 textureInput의 RGB 값과 overLay의 알파 값을 사용하여 최종 이미지를 만들어야합니다. Pixmap 클래스를 사용하여이 작업을 수행 할 수 있다고 생각하지만 정확히 어떻게 찾을 수없는 것 같습니다.

public Texture getOverlayTexture(FileHandle overLay, FileHandle textureInput){ 
    Pixmap inputPix = new Pixmap(textureInput); 
    Pixmap overlayPix = new Pixmap(overLay); 

    Pixmap outputPix = new Pixmap(inputPix.getWidth(), inputPix.getHeight(), Format.RGBA8888); 

    // go over the inputPix and add each byte to the outputPix 
    // but only where the same byte is not alpha in the overlayPix 

    Texture outputTexture = new Texture(outputPix, Format.RGBA8888, false); 

    inputPix.dispose(); 
    outputPix.dispose(); 
    overlayPix.dispose(); 
    return outputTexture; 
} 

난 그냥 여기에서 이동하는 위치에 같은 방향의 비트를 찾고 있어요 : 여기

내가 방법의 구조이어야한다 수집하는 것입니다. 어떤 도움이라도 대단히 감사합니다. 이 질문이 너무 애매하거나 내 접근 방식이 완전히 해제 된 경우 사과드립니다.

감사합니다.

+0

당신이 알파 채널을 사용하여이를 달성 할 수 없음을? –

+0

어떻게하면됩니까? – user2989675

답변

4

마침내 이것을 수행하는 방법을 발견했습니다.

게임을 설정하는 방법은 각 항목이 자체적으로 그려지는 것입니다. 그들은 spritebatch가 주어지며 그것을 가지고 할 수 있습니다. 나는 여러 가지 이유에서 그렇게했다. 항목 목록을 포함하는 항목 관리자가 있습니다. 각 항목에는 다양한 속성이 있습니다. 각 항목에는 다른 독립 메소드와 함께 자체 렌더링 메소드가 있습니다. 여기에 마지막 일 것입니다 :

정상적인 항목의 알파 마스킹 사용하지 않는 방법 렌더링 : 그래서

public void render(SpriteBatch batch, int renderLayer) { 
    if(renderLayer == Integer.parseInt(render_layer)){    // be in the correct render layer 
     batch.draw(item.region, 
       item.position.x,         // position.x 
       item.position.y,         // position.y 
       0,             //origin x 
       0,             //origin y 
       item.region.getRegionWidth() ,      //w 
       item.region.getRegionHeight(),      //h 
       item.t_scale,          //scale x 
       item.t_scale,          //scale y 
       item.manager.radiansToDegrees(item.rotation));  //angle 
    } 
} 

을가, 올바른 이미지, 위치, 규모 감있는의 SpriteBatch를 넘겨진다을하고 회전, 그리고 그 것입니다.

내가 여기 어떻게 놀아 후 : 검은 형태를 포함 alphaMask라는 TextureRegion이 있습니다

public void render(SpriteBatch batch, int renderLayer) { 
    if(renderLayer == Integer.parseInt(render_layer)){ 
     batch.enableBlending(); 

     //draw the alpha mask 
     drawAlphaMask(batch, item.position.x, item.position.y, item.region.getRegionWidth(), item.region.getRegionHeight()); 

     //draw our foreground elements 
     drawForeground(batch, item.position.x, item.position.y, item.region.getRegionWidth(), item.region.getRegionHeight()); 
     batch.disableBlending(); 
    } 
} 

: https://gist.github.com/mattdesl/6076846을 잠시 동안,이 마지막으로 알파 마스크를 사용해야하는 항목에 대한했다. 그것은 모든 이미지,하지만의이 인스턴스에서의이 모양/이미지를 가정 해 봅시다 수 있습니다

private void drawAlphaMask(SpriteBatch batch, float x, float y, float width, float height) { 
    //disable RGB color, only enable ALPHA to the frame buffer 
    Gdx.gl.glColorMask(false, false, false, true); 

    // Get these values so I can be sure I set them back to how it was 
    dst = batch.getBlendDstFunc(); 
    src = batch.getBlendSrcFunc(); 

    //change the blending function for our alpha map 
    batch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ZERO); 

    //draw alpha mask sprite 
    batch.draw(alphaRegion, 
      x,             // position.x 
      y,             // position.y 
      0,             // origin x 
      0,             // origin y 
      alphaRegion.getRegionWidth(),      // w 
      alphaRegion.getRegionHeight(),      // h 
      item.t_scale,          // scale x 
      item.t_scale,          // scale y 
      item.manager.radiansToDegrees(item.rotation));  // angle 
    //flush the batch to the GPU 
    batch.flush(); 
} 

는 다양한 있습니다

여기 A "beam"

그 이상이라는 기능입니다 해당 이미지를 사용 어떤 "모양"에도 적용 할 수있는 "재료" 어떤 경우이든 그 중 하나가 spriteRegion 변수에 할당됩니다.그래서 위라는 drawForeground 방법과 같이 해당 이미지 사용

enter image description here

:

private void drawForeground(SpriteBatch batch, float clipX, float clipY, float clipWidth, float clipHeight) { 
    //now that the buffer has our alpha, we simply draw the sprite with the mask applied 
    Gdx.gl.glColorMask(true, true, true, true); 
    batch.setBlendFunction(GL10.GL_DST_ALPHA, GL10.GL_ONE_MINUS_DST_ALPHA); 

    batch.draw(spriteRegion, 
      clipX,          // corrected center position.x 
      clipY,          // corrected center position.y 
      0,             //origin x 
      0,             //origin y 
      spriteRegion.getRegionWidth() ,       //w 
      spriteRegion.getRegionHeight(),        //h 
      item.t_scale,          //scale x 
      item.t_scale,          //scale y 
      item.manager.radiansToDegrees(item.rotation));  //angle 


    //remember to flush before changing GL states again 
    batch.flush(); 

    // set it back to however it was before 
    batch.setBlendFunction(src, dst); 
} 

모두가 바로 바탕 화면 빌드에서 작동하는지, 그리고 "생성 할 수의 그것은 이것이다 지금 가정 해 봅시다 안드로이드와 GW에서 그러나

enter image description here

: 멋지게 게임에서 벽돌 빔 "(또는 무엇이든) T는 빌드하기 때문에 (결국 libgdx를 사용하고 있습니다) 알파 마스크를 통합하지 않고 전체 벽돌 사각형을 렌더링했습니다. 주변을 둘러 보는이 많이 나는이 발견되면

는 : https://github.com/libgdx/libgdx/wiki/Integrating-libgdx-and-the-device-camera

그리고 안드로이드에서이 문제를 해결하기를 나는이 같은 MainActivity.java에서 onCreate 방법 수정 :

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration(); 
    cfg.useGL20 = false; 
    cfg.r = 8; 
    cfg.g = 8; 
    cfg.b = 8; 
    cfg.a = 8; 
    initialize(new SuperContraption("android"), cfg); 

    if (graphics.getView() instanceof SurfaceView) { 
     SurfaceView glView = (SurfaceView) graphics.getView(); 
     // force alpha channel - I'm not sure we need this as the GL surface 
     // is already using alpha channel 
     glView.getHolder().setFormat(PixelFormat.TRANSLUCENT); 
    } 
} 

을 그리고 그 안드로이드를 수정 .

libgdx에게 webGl에게 알파 채널을주의 깊게 알리기 위해 GWT에 알리는 방법을 알 수 없기 때문에 여전히 gwt에서 제대로 작동하는 방법을 알아낼 수 없습니다. 나는 더 쉽거나 덜 비싼 방법으로 이런 일을하는 방법에 관심이있다.

GWT에서이 작업을 수행하는 방법을 아는 분은 다른 답으로 게시하십시오. 여기

은 당신이 텍스처 문제를보고 싶다면 GWT가 구축되지 않은 작업 :

https://supercontraption.com/assets/play/index.html

+0

대단히 고마워, 나를 도와 줬어! 다음은 스 니펫에 대한 내 솔루션 기반입니다. 그것은 미니 맵 배경을 렌더링하고 나중에 미니 맵 텍스처에 픽셀이있는 것을 그립니다 : http://pastebin.com/TXW4G7vv 나를 위해 작동하지 않는 유일한 것은 적절한 블렌딩 이었기 때문에 ' 'GL_ONE_MINUS_DST_ALPHA' 대신'GL_ONE_MINUS_SRC_ALPHA' –

관련 문제