C ++ SDL2:如何将矩形渲染到多个视口中

问题描述 投票:0回答:1

我是SDL2(2.0.10版)的新手,我从Lazy Foo教程中教它。在Lesson of The ViewPort示例代码中,仅在左视口中渲染第一张图像,而在其他视口中则不渲染。在不同视口中的矩形渲染也不起作用。我想要在不同视口中渲染rect时,我做错了什么:

while( !quit ){

while( SDL_PollEvent( &e ) != 0 ){
if( e.type == SDL_QUIT ){
 quit = true;
}
}

//Clear screen
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
SDL_RenderClear( gRenderer );

//Top left corner viewport
SDL_Rect topLeftViewport;
topLeftViewport.x = 0;
topLeftViewport.y = 0;
topLeftViewport.w = SCREEN_WIDTH / 2;
topLeftViewport.h = SCREEN_HEIGHT / 2;
SDL_RenderSetViewport( gRenderer, &topLeftViewport );

SDL_Rect fillRect = { 10, 10, 100, 100 };
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0x00, 0x00, 0xFF );
SDL_RenderFillRect( gRenderer, &fillRect );

SDL_Rect topRightViewport;
topRightViewport.x = SCREEN_WIDTH / 2;
topRightViewport.y = 0;
topRightViewport.w = SCREEN_WIDTH / 2;
topRightViewport.h = SCREEN_HEIGHT / 2;
SDL_RenderSetViewport( gRenderer, &topRightViewport );

SDL_Rect fillRect2 = { 10, 10, 100, 100 };
SDL_SetRenderDrawColor( gRenderer, 0x00, 0xFF, 0x00, 0xFF );
SDL_RenderFillRect( gRenderer, &fillRect2 );

SDL_RenderPresent( gRenderer );
}
c++ viewport sdl-2 game-development
1个回答
0
投票

正如我所看到的,您在100x100的10、10处绘制了一个矩形两次,此坐标未考虑视口坐标。在某种程度上,如果您想通过更改视口裁剪来实现此目的不相关,只需在所需的位置绘制正方形即可。

© www.soinside.com 2019 - 2024. All rights reserved.