iOS - 使用 openGL ES 仅缩放部分显示

发布于 2024-11-25 04:15:14 字数 151 浏览 1 评论 0原文

我正在开发一个关卡构建器应用程序来构建游戏内容。 iPad 屏幕的一部分是专用控制面板,其余部分是正在构建的关卡的图形表示。我需要在不影响控制面板的情况下放大和缩小关卡区域。我使用 openGL ES 进行渲染。有人可以在这里给我一些指示吗?我可以用不同的视口分割屏幕,然后只缩放一个吗?

I'm working on a level builder app to build content for a game. Part of the iPad screen is a dedicated control panel, while the rest is a graphical representation of the level being built. I need to zoom the level area in and out without affecting the control panel. I'm using openGL ES for rendering. Can anyone give me some pointers here? Can I split the screen with different viewports and so just scale one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪漫之都 2024-12-02 04:15:14

诀窍是要理解 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();
}

重要的部分是,在渲染该子部分之前,您在绘图处理程序中设置视口/剪刀和投影。

The trick is to understand that OpenGL is a state machine and there is no such thing like "global initialization". As long as you follow the badly written tutorials and have your projection matrix setup in the window resize handler you'll be stuck. What you actually do is something like this:

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();
}

The important part is, that you set the viewport/scissor and the projection within the drawing handler prior to rendering that sub-part.

少女净妖师 2024-12-02 04:15:14

如果您使用 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

用于转换关卡的矩阵(或您拥有的任何转换内容)不应该用于转换控制面板。

If you're rendering with OpenGL ES (presumably 2.0), then you have full control over the scaling of what you render. You decide where the scale gets applied, and you decide how things are rendered.

I'd guess your code currently looks a bit like this.

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

When it should look like this.

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

The matrices (or whatever transformation stuff you have) you use for transforming the level should not be used for transforming the control panel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文