本文介绍了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/

相关位:

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

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多个渲染器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 12:46
查看更多