2017-04-21 16 views
10

私はいくつかのfbxモデルをレンダリングするためにlibgdxを試していますが、これは成功しましたが、私は一点で立ち往生しています。libgdxの球体上にテキストを描く

私はModelInstanceの助けを借りてバスケットボールのfbxファイルをレンダリングしています。今はそのバスケットボールにテキストを描画したいと思います。私はバスケットボールにテキストを描くことができますが、そのバスケットボールの一部として見えていない線形です。 私はそのボールと同じカーブの方法でテキストをしたい。

これは私がたくさんtext--

batch = new SpriteBatch(); 
batch.setProjectionMatrix(camera.combined); 

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font/Lato-Bold.ttf")); 
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); 
    parameter.size = 30; 
    parameter.color = com.badlogic.gdx.graphics.Color.WHITE; 
    parameter.magFilter = Texture.TextureFilter.Linear; // used for resizing quality 
    parameter.minFilter = Texture.TextureFilter.Linear; 
    generator.scaleForPixelHeight(3); 

    BitmapFont aFont = generator.generateFont(parameter); 
    aFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); 

aFont.draw(batch, options.get(i), aBound.getCenterX(), aBound.getCenterY() + textHeight/2); 

描いています方法です - モデルの>にBoundingBox(すなわち、バスケットボール)

+0

同じマトリックス上に別のエンティティとしてテキストを描画しています。あなたがbasketBallなどのために使用しているテクスチャビットマップにテキストを描画するためにこれを実現する1つの方法は、球形になります。 – Qamar

答えて

1

あなたがここに達成しようとしている何がlibGdxで少し複雑です。しかし、ボールの上に別のスプライトオブジェクトとしてテキストを描画しているので、あなたのアプローチは間違っています。

これを達成する正しい手順は、テキストをテクスチャに描画し、テクスチャをボールにマップしてバインドすることです。

手順は、4つの部分に分けることができ

-

  1. モデルにテクスチャをマッピングし、フォントの生成およびテキストを描画スプライトバッチ
  2. セットアップフレームバッファオブジェクト
  3. セットアップ
  4. モデルのレンダリング

注釈として、他のテクスチャを使用することができますリアルタイムでテキストを更新したくない場合は、事前に作成したテクスチャを任意のテキストで簡単に使用することができます。次のように

コードは - フォント生成およびフレームバッファオブジェクト

//Create a new SpriteBatch object 
batch = new SpriteBatch(); 

//Generate font 
FreeTypeFontGenerator generator = new 
FreeTypeFontGenerator(Gdx.files.internal("font/Lato-Bold.ttf")); 
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new 
FreeTypeFontGenerator.FreeTypeFontParameter(); 
parameter.size = 30; 
parameter.color = com.badlogic.gdx.graphics.Color.WHITE; 
parameter.magFilter = Texture.TextureFilter.Linear; // used for resizing quality 
parameter.minFilter = Texture.TextureFilter.Linear; 
generator.scaleForPixelHeight(10); 

//Get bitmap font 
BitmapFont aFont = generator.generateFont(parameter); 
aFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, 
Texture.TextureFilter.Linear); 

//Generate new framebuffer object of 128x128 px. This will be our texture 
FrameBuffer lFb = new FrameBuffer(Pixmap.Format.RGBA4444,128,128,false); 

スプライトバッチのセットアップ

//Set the correct resolution for drawing to the framebuffer 
lFb.begin(); 
Gdx.gl.glViewport(0,0,128,128); 
Gdx.gl.glClearColor(1f, 1f, 1f, 1); 

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
Matrix4 lm = new Matrix4(); 
//Set the correct projection for the sprite batch 
lm.setToOrtho2D(0,0,128,128); 
batch.setProjectionMatrix(lm); 

最後にテキストを描画するの設定

テクスチャ

batch.begin(); 
aFont.draw(batch,"Goal!",64,64); 
batch.end(); 
lFb.end(); 

レンダリングモデル

//Generate the material to be applied to the ball 
//Notice here how we use the FBO's texture as the material base 
Material lMaterial = new Material(TextureAttribute.createDiffuse(lFb.getColorBufferTexture())); 

//Since I do not have a sphere model, I'll just create one with the newly 
//generated material   
ballModel = mb.createSphere(1.0f,1.0f,1.0f,8,8,lMaterial, 
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates); 

//Finally instantiate an object of the model 
ballInstance = new ModelInstance(ballModel); 

にモデルをテクスチャ地図

mBatch.begin(mCamera); 
mBatch.render(ballInstance); 
mBatch.end(); 
//Rotate the ball along the y-axis 
ballInstance.transform.rotate(0.0f,1.0f,0.0f,0.5f); 

結果 -

Render text to sphere libGDX

関連する問題