2011-07-20 16 views
1

私は、レベルビルダアプリケーションを使ってゲームのコンテンツを作成しています。 iPadの画面の一部は専用のコントロールパネルですが、残りはビルドされているレベルのグラフィック表示です。コントロールパネルに影響を与えずに、レベルエリアをズームイン/ズームアウトする必要があります。私はレンダリングのためにOpenGL ESを使用しています。誰も私にここにいくつかのポインタを与えることができますか?別のビューポートで画面を分割することはできますか?iOS - OpenGL ESを使用したディスプレイの一部だけをズームする

答えて

1

OpenGL ES(おそらく2.0)でレンダリングしている場合は、レンダリングのスケーリングを完全に制御できます。スケールが適用される場所を決めて、どのようにレンダリングするかを決めます。

あなたのコードは現在、このように少し見えると思います。

Get view scale 
Apply view scale to view matrix 
Render level 
Render control panel 

これは次のようになります。

Render control panel 
Get view scale 
Apply view scale to view matrix 
Render level 

コントロールパネルを形質転換するために使用されないべきあなたがレベルを形質転換するために使用行列(または任意の変換ものあなたが持っています)。

2

トリックは、OpenGLは状態マシンであり、「グローバル初期化」のようなものはないことを理解することです。間違って書かれたチュートリアルに従って、ウィンドウのサイズ変更ハンドラで投影行列の設定をしている限り、あなたは立ち往生します。あなたは、ビューポート/ハサミとそのサブ部分をレンダリングする前に、描画ハンドラ内で投影を設定することを、

void render_perspective_scene(void); 

void render_ortho_scene(void); 

void render_HUD(); 

void display() 
{ 
    float const aspect = (float)win_width/(float)win_height; 

    glViewport(0,0,win_width,win_height); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glFrustum(-aspect*near/lens, aspect*near/lens, -near/lens, near/lens, near, far); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    render_perspective_scene(); 

    glEnable(GL_SCISSOR_TEST); 
    // just clear the depth buffer, so that everything that's 
    // drawn next will overlay the previously rendered scene. 
    glClear(GL_DEPTH_BUFFER_BIT); 
    glViewport(ortho_x, ortho_y, ortho_width, ortho_height); 
    glScissor(ortho_x, ortho_y, ortho_width, ortho_height); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(-aspect*scale, aspect*scale, -scale, scale, 0, 1); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    render_ortho_scene(); 

    // Same for the HUD, only that we render 
    // that one in pixel coordinates. 
    glViewport(hud_x, hud_y, hud_width, hud_height); 
    glScissor(hud_x, hud_y, hud_width, hud_height); 
    glClear(GL_DEPTH_BUFFER_BIT); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(0, win_width, 0, win_height, 0, 1); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    render_HUD(); 
} 

重要な部分がある:あなたが実際にやっていることは、このようなものです。

関連する問題