0

私はOpenGLが初めてです。私はJOGLを使用しています。

WorldEntityレンダリングできるものを表すクラスがあります。や などの属性がpositionありsizeます。レンダリングするために、私はこの方法を使用しています:

    /**
     * Renders the object in the world.
     */
    public void render() {
        gl.glTranslatef(getPosition().x, getPosition().y, getPosition().z);
        gl.glRotatef(getRotationAngle(), getRotation().x, getRotation().y, getRotation().z);
//        gl.glScalef(size, size, size);

        gl.glCallList(drawID);

//        gl.glScalef(1/size, 1/size, 1/size);
        gl.glRotatef(-getRotationAngle(), getRotation().x, getRotation().y, getRotation().z);
        gl.glTranslatef(-getPosition().x, -getPosition().y, -getPosition().z);
    }

私が使用してきたパターンは、エンティティの各属性 (位置や回転など) を適用し、それを元に戻して、次のエンティティがレンダリングされる状態を壊さないようにします。

Uncommenting out the scaling lines causes the app to be much more sluggish as it renders a modest scene on my modest computer. I'm guessing that the float division is too much to handle thousands of operations per second. (?)

What is the correct way to go about this? Can I find a less computationally intensive way to undo a scaling transformation? Do I need to sort objects by scale and draw them in order to reduce scaling transformations required?

Thanks.

4

2 に答える 2

5

ここで行列を使用します (ご容赦ください。私は OpenGL/C プログラミングのバックグラウンドを持っています)。

glMatrixMode(GL_MODELVIEW); // set the matrix mode to manipulate models

glPushMatrix(); // push the matrix onto the matrix stack

// apply transformations
glTranslatef(getPosition().x, getPosition().y, getPosition().z);
glRotatef(getRotationAngle(), getRotation().x, getRotation().y, getRotation().z);
glScalef(size, size, size);

glCallList(drawID); // drawing here

glPopMatrix(); // get your original matrix back

……少なくとも、私はそう思います。

于 2010-09-20T21:23:00.050 に答える
0

部門がパフォーマンスの問題を引き起こす可能性はほとんどありません。rfw はこれを実装する通常の方法を提供しましたが、私の推測では、GPU がボトルネックであり、マトリックス スタックを使用してもパフォーマンスが向上しないという事実が原因で、レンダリングが「遅く」なっていると思います。

描画オブジェクトのサイズを大きくすると、より多くのピクセルを処理する必要があり、GPU は非常にハードに動作する必要があります。この時点での CPU の動作 (分割) は関係ありません。

私の言いたいことを証明するために、スケーリング コードをそのままにしておきますが、サイズは 1 前後にします。

于 2010-09-21T08:32:12.273 に答える