c++ - How to draw a rectangle in SDL 2 and what exactly is a renderer -
c++ - How to draw a rectangle in SDL 2 and what exactly is a renderer -
my questions focuses on sdl 2
i dont understand renderer is. can have multiple renderers or there one? for example, how can draw rectangle color on background different color using renderer? believe reply lies in functions: sdl_renderdrawrect()
, sdl_renderfillrect()
right? said problem dont understands renders. know how surfaces , bliting works dont know renderer symbolizes. if show me how think understand how renders works. far have this:
#include <sdl.h> int main(int argc, char* argv[]) { //initialization sdl_init(sdl_init_everything); //window sdl_window *mainwindow = sdl_createwindow("my game window", sdl_windowpos_centered, sdl_windowpos_centered, 640, 480, sdl_window_shown ); //renderer sdl_renderer *background = sdl_createrenderer(mainwindow, -1, 0); sdl_setrenderdrawcolor(background, 255, 255, 255, 255); sdl_renderclear(background); sdl_delay(3000); //clean sdl_destroywindow(mainwindow); sdl_quit(); homecoming 0; }
for first part of question see this question.
as why code doesnt much:
you right need utilize either sdl_renderdrawrect()
, or sdl_renderfillrect()
. sdl_renderdrawrect
draw unfilled rectangle. sdl_renderfillrect
filled (hopefully obvious).
with sdl_renderer
need phone call sdl_renderpresent
re-create "scene" screen.
... //renderer sdl_renderer* renderer = sdl_createrenderer(mainwindow, -1, 0); sdl_setrenderdrawcolor(renderer, 255, 255, 255, 255); sdl_renderclear(renderer); // fill scene white sdl_setrenderdrawcolor(renderer, 255, 0, 0, 255); // rect color (solid red) sdl_rect rect(0, 0, 100, 50); // rectangle sdl_renderfillrect(renderer, &rect); sdl_renderpresent(renderer); // re-create screen sdl_delay(3000); ...
c++ sdl-2
Comments
Post a Comment