drawing an SDL_Rect not working
I am trying to build an RTS in C++ using SDL. Now I'm trying to make a
rectangle which will select units(resizable selection box). It will be a
transarent yellow rectangle. When I run the program and try to selectg
multiplyunits. Nothing happens(I mean drawing the rect. Selecting is not
made yet)
This is the code(in main.cpp):
...
Uint32 selection_colour;
SDL_Rect box_rect;
int M1X = 0;
int M1Y = 0;
int M2X = 0;
int M2Y = 0;
int W;
int H;
...
void init()
{
...
selection_colour = SDL_MapRGBA(screen->format, 0xFF, 0xFF, 0, 0.3);
...
}
...
while(running)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{
M2X = event.motion.x;
M2Y = event.motion.y;
W = M2X - M1X;
H = M2Y - M1Y;
box_rect.x = M1X;
box_rect.y = M1Y;
box_rect.w = W;
box_rect.h = H;
}
}else
{
M1X = event.motion.x;
M1Y = event.motion.y;
}
}
SDL_FillRect(screen, &box_rect, selection_colour);
SDL_Flip(screen);
}
any suggestions??
No comments:
Post a Comment