Problem with Fill Rect
Hi, im new here. I am having some problems with the fill rect function in SDL. If I run the program in fullscreen the screen flashes a lot but if i run it windowed it works just fine. I dont know if the problem is the fill rect function or something else, i would appreciate if you could help me. Thanks.
Try using a double buffer in fullscreen mode, and see if that corrects the problem.
To do this or in the SDL_DOUBLEBUF flag when you make the call to SDL_SetVideoMode. You'll need to call SDL_Flip instead of updating the screen surface though.
To do this or in the SDL_DOUBLEBUF flag when you make the call to SDL_SetVideoMode. You'll need to call SDL_Flip instead of updating the screen surface though.
Hmmm
Weird if it's bug only in full screen mode but.... make sure SDL_Flip is really called at the very end of the calculation and when you are ready to swap the buffers.
Weird if it's bug only in full screen mode but.... make sure SDL_Flip is really called at the very end of the calculation and when you are ready to swap the buffers.
//This is the function we call from the gameloop every cicle:
void CTetris::Draw()
{
bool bEsPieza;
SDL_Rect rectFondo;
rectFondo.x = (ANCHO_VENTANA / 3) + 18;
rectFondo.y = 85;
rectFondo.w = 191;
rectFondo.h = 388;
SDL_Rect rectLineas;
rectLineas.x = 500;
rectLineas.y = 103;
rectLineas.w = 50;
rectLineas.h = 20;
SDL_FillRect(sfcScreen, &rectFondo, SDL_MapRGB(sfcScreen->format, 0, 0, 0));
for (int i = 0; i < ALTO_TABLERO; i++)
{
for (int j = 0; j < ANCHO_TABLERO; j++)
{
bEsPieza = false;
int k = 0;
while (k < 4 && !bEsPieza)
{
if (p.cuadrado[k].x == j && p.cuadrado[k].y == i)
bEsPieza = true;
k++;
}
if (bEsPieza)
DrawSprite(sfcPiezas, sfcScreen, TAM_PIEZA * (p.tipo - 1), 0, j * TAM_PIEZA+ (ANCHO_VENTANA /3), i * TAM_PIEZA + 93, TAM_PIEZA, TAM_PIEZA);
else
{
if (tablero[j] != LIBRE)
DrawSprite(sfcPiezas, sfcScreen, TAM_PIEZA * (tablero[j] - 1), 0, j * TAM_PIEZA+(ANCHO_VENTANA/3), i * TAM_PIEZA + 93, TAM_PIEZA, TAM_PIEZA);
}
}
}
SDL_FillRect(sfcScreen, &rectLineas, SDL_MapRGB(sfcScreen->format, 0, 0, 0));
DrawText( sfcScreen, IntToString(iLineasTotales), 505, 100, 255, 255, 255 );
SDL_Flip( sfcScreen );
}
void CTetris::Draw()
{
bool bEsPieza;
SDL_Rect rectFondo;
rectFondo.x = (ANCHO_VENTANA / 3) + 18;
rectFondo.y = 85;
rectFondo.w = 191;
rectFondo.h = 388;
SDL_Rect rectLineas;
rectLineas.x = 500;
rectLineas.y = 103;
rectLineas.w = 50;
rectLineas.h = 20;
SDL_FillRect(sfcScreen, &rectFondo, SDL_MapRGB(sfcScreen->format, 0, 0, 0));
for (int i = 0; i < ALTO_TABLERO; i++)
{
for (int j = 0; j < ANCHO_TABLERO; j++)
{
bEsPieza = false;
int k = 0;
while (k < 4 && !bEsPieza)
{
if (p.cuadrado[k].x == j && p.cuadrado[k].y == i)
bEsPieza = true;
k++;
}
if (bEsPieza)
DrawSprite(sfcPiezas, sfcScreen, TAM_PIEZA * (p.tipo - 1), 0, j * TAM_PIEZA+ (ANCHO_VENTANA /3), i * TAM_PIEZA + 93, TAM_PIEZA, TAM_PIEZA);
else
{
if (tablero[j] != LIBRE)
DrawSprite(sfcPiezas, sfcScreen, TAM_PIEZA * (tablero[j] - 1), 0, j * TAM_PIEZA+(ANCHO_VENTANA/3), i * TAM_PIEZA + 93, TAM_PIEZA, TAM_PIEZA);
}
}
}
SDL_FillRect(sfcScreen, &rectLineas, SDL_MapRGB(sfcScreen->format, 0, 0, 0));
DrawText( sfcScreen, IntToString(iLineasTotales), 505, 100, 255, 255, 255 );
SDL_Flip( sfcScreen );
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement