Hello!
Following some tutorials i made a program that “puts” an image
at the background, and then a new image in the foreground. Wich you can move
it with
the arrow keys. The program works just fine when i use Windowed screen.
But if i use FULL SCREEN, the screen starts flikering as hell, and the image
looks darker… and the screen REALLY.
I thought it was about my very old monitor, so i tried the same compiled
binary in
my fathers PC, that has an almost new 19’ phillips monitor. But it did the
same.
Also, i noticed in my fathers machine (new monitor), that it shows the
background image, and the DESKTOP at the same time, like if there is a loop
that SHOWS the background image, and then shows the desktop. Very strange.
Here is how i did initialized the video mode:
(screen is a SDL_Surface *screen;)
screen =
SDL_SetVideMode(800,600,16,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
*I noticed that if i have my desktop in 24 bits, and the program is 16 bit
it works bad. So i used 16bpp desktop in the PC’s i tested the program.
and as i said, the program works perfectly when i use a windowed mode.
Can you tell me what could be the possible problem? Im sure that its not an
sdl problem, and its just the way im “showing” the images. Maybe the
background image. I can’t guess it.
Thanks in advantage!!
PD: Sorry if i didn’t explain the problem that well. Im very new to SDL.
----- Here is the code -----
#include
#include <stdlib.h>
#include "SDL/SDL.h"
using namespace std;
SDL_Surface *back;
SDL_Surface *screen;
SDL_Surface *image;
int ypos=0,xpos=0;
int InitImages() {
back = SDL_LoadBMP(“bg.bmp”);
image = SDL_LoadBMP(“image.bmp”);
return 0;
}
void DrawIMG(SDL_Surface *img, int x, int y) {
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2) {
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, screen, &dest);
}
void DrawBG() {
DrawIMG(back,0,0);
}
void DrawScene() {
DrawIMG(back,xpos-2,ypos-2,132,132,xpos-2,ypos-2);
DrawIMG(image,xpos,ypos);
SDL_Flip(screen);
}
int main(int argc, char *argv[])
{
Uint8 *keys;
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
cout <<"Error (1): al cargar Video / Sonido:
"<<SDL_GetError()<<endl;
return 1;
}
atexit(SDL_Quit);
screen =
SDL_SetVideoMode(800,600,16,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
if (screen == NULL) {
cout << "Error (2): No se puede inicializar la pantalla: " <<
SDL_GetError() <<endl;
return 1;
}
InitImages();
DrawBG();
int done=0;
while ( done == 0 ) {
SDL_Event salir;
while (SDL_PollEvent(&salir)) {
if (salir.type == SDL_QUIT) { done = 1; }
if (salir.type == SDL_KEYDOWN) {
if (salir.key.keysym.sym == SDLK_ESCAPE) { done = 1;}
}
}
keys = SDL_GetKeyState(NULL);
if (keys[SDLK_UP]) { ypos-=1; }
if (keys[SDLK_DOWN]) { ypos+=1; }
if (keys[SDLK_LEFT]) { xpos-=1; }
if (keys[SDLK_RIGHT]) { xpos+=1; }
DrawScene();
}
return 0;
}
Eduardo Garcia Rajo (h)------------------------------------------------------------------
Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios