テクスチャへのレンダリングを機能させようとしています。これまでのところ、テクスチャとすべてを描画するために必要なすべての GL ガビンを実行します。唯一の問題は、スケーリングがすべてオフになることです。
ビューポートをテクスチャのサイズに設定し、gluOrtho2d (テクスチャに描画する方法) を -halfwidth, halfwidth, -halfheight, halfheight に設定したいと考えました。これは、描画位置 0,0 が中央にある必要があることを意味します。半幅、半高の位置は右上隅などにある必要があります。
しかし、私は本当に奇妙な効果を得ています.正しいスケールでテクスチャに描画していないようです.
ありがとう
public void renderToTexture(GLRenderer glRenderer, GL10 gl)
{
boolean checkIfContextSupportsExtension = checkIfContextSupportsExtension(gl, "GL_OES_framebuffer_object");
if(checkIfContextSupportsExtension)
{
GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
int mFrameBuffer = createFrameBuffer(gl,texture.getWidth(), texture.getHeight(), texture.getGLID());
if (mFrameBuffer == -1)
{
return;
}
gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, mFrameBuffer);
int halfWidth = texture.getWidth()/2;//width/2;
int halfHeight = texture.getHeight()/2;//height/2;
gl.glViewport(0,0,texture.getWidth(), texture.getHeight());
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, -halfWidth, halfWidth , -halfHeight, halfHeight);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glClearColor(0f, 1f, 0f, 1f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
//draw the old version of the texture to framebuffer:
Quad quad = new Quad(texture.getWidth(), texture.getHeight());
quad.setTexture(texture);
SpriteRenderable sr = new SpriteRenderable(quad);
sr.renderTo(glRenderer, gl, 1);
//draw the new gl objects etc to framebuffer
for (Renderable renderable : renderThese)
{
if (renderable.isVisible()) {
renderable.renderTo(glRenderer, gl, 1);
}
}
//default to the old framebuffer
gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
}
}
画像:
これはテクスチャ レンダリング前のゲームです。
これは、画像 1 に示すように、「アリーナ」背景テクスチャに「血しぶき」(現在は豚!) がレンダリングされた後です。元のテクスチャが小さすぎて中央 (数ピクセル) と豚「blood splat」はジグザグにジャンプし、テクスチャーの中心をめくって小さくなっていきます...
(申し訳ありませんが、投稿に画像を投稿するのに十分な担当者がいません!)