SDL2 Multiple renderers?

て烟熏妆下的殇ゞ 提交于 2019-12-12 16:38:41

问题


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/

The relevant bit:

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?


回答1:


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...

I hope this helps.

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

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.



来源:https://stackoverflow.com/questions/21792146/sdl2-multiple-renderers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!