SDL2多个渲染器? [英] SDL2 Multiple renderers?

查看:309
本文介绍了SDL2多个渲染器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SDL和C ++游戏开发的新手.我一直在这里学习代码:

I'm new to game development, SDL and C++. I have been learning with the code here:

http://gamedevgeek.com/tutorials/managing-game-states -in-c/

相关位:

多种状态不仅在演示中很重要,而且在一般游戏中也很重要.每个游戏都以介绍状态开始,然后移至某种菜单,最后开始播放.当您最终被击败时,游戏会进入游戏结束状态,通常会返回菜单.在大多数游戏中,一次可能处于一种以上状态.例如,您通常可以在玩游戏时调出菜单.

Multiple states are not only important in demos, but also in games in general. Every game starts off in an introduction state, then moves to a menu of some kind, a finally play begins. When you’re finally defeated, the game moves to a game-over state, usually followed by a return to the menu. In most games it is possible to be in more than one state at a time. For example, you can usually bring up the menu during game play.

我的问题是:要一次显示多个状态,例如在游戏顶部显示菜单,每个状态都必须有自己的渲染器吗?

My question is: To have multiple states display at once, such as displaying a menu on top of game play, must each state have it's own Renderer?

推荐答案

您将Image.png *(或其他格式)传递到纹理上,然后将纹理放置在表面"上(可以使用此),然后将其传递到渲染器.因此,您要做的就是更改剪辑和纹理,然后按!RIGHT ORDER将其传递给Renderer!

You pass an Image.png*(or other format) onto a Texture, Then you place the Texture on a "surface"(you can clip the texture with this) which is then passed onto a Renderer. So, all you have to do is change the clip and texture, and pass it to the Renderer In the !RIGHT ORDER!

示例:您将首先渲染背景,然后渲染精灵,然后渲染效果,等等.

Example: You would Render the background first, and then Sprites, and then Effects, etc...

我希望这会有所帮助.

下面的代码是从LAZY FOO网站上获得的!检查它非常有用,以便开始SDL2

BELOW CODE WAS TAKEN FROM LAZY FOO WEBSITE!! CHECK IT OUT VERY USEFULL TO BEGIN SDL2

http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php

//While application is running
        while( !quit )
        {
            //Handle events on queue
            while( SDL_PollEvent( &e ) != 0 )
            {
                //User requests quit
                if( e.type == SDL_QUIT )
                {
                    quit = true;
                }
            }

            //Clear the last frame 
            SDL_RenderClear( gRenderer );

            //Render texture to screen
            SDL_RenderCopy( gRenderer, gTexture1, NULL, NULL );
            SDL_RenderCopy( gRenderer, gTexture2, NULL, NULL );
            SDL_RenderCopy( gRenderer, gTexture3, NULL, NULL );
            SDL_RenderCopy( gRenderer, gTexture4, NULL, NULL );

            //Update screen
            SDL_RenderPresent( gRenderer );}

如上面的代码所示,

SDL_RenderCopy使用SAME渲染器渲染不同的纹理.因此,您需要的是许多纹理.

as you can see in the above CODE the SDL_RenderCopy uses the SAME renderer for RENDERING different TEXTURES. so what you need, is, many textures.

我确定可能会使用多个渲染器,但我不知道为什么要这么做?

I'm certain there might be a use for multiple renderers but I have no idea why you would do that?

//第二天// 所以我检查了一下,发现如果您有多窗口应用程序,则可以使用多个渲染器.

//the next day// So I checked this out, and Saw that if you have a Multiple Window Application you Can use Multiple renderers.

这篇关于SDL2多个渲染器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆