Do I need to do something special to draw in fullscreen mode?

I’ve compiled and ran the sdl tutorials by Marius at http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/index.
They work just fine in windowed mode when compiled in VC++ 6.0, but I just get a blank screen in fullscreen mode. The code itself is pretty simple. At first I thought it was just the images where missing from the directory with the .exe, but I copied them in and it’s still the same thing. Besides if that was the problem why would it work in windowed mode? Here’s the code :

// “Graphics with SDL” turorial series Lesson 2
// by Marius Andra (http;//cone3d.gamedev.net/)
//
// NOTE: don’t be alarmed if running this from
// Dev-C++ turns up a black screen. Compile it and then
// run it from the sources folder.

#include <stdio.h>
#include <stdlib.h>

#include “SDL.h”

SDL_Surface *back;
SDL_Surface *image;
SDL_Surface *screen;

int xpos=0,ypos=0;

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}

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()
{
Slock(screen);
DrawIMG(back, 0, 0);

Sulock(screen);
}

void DrawScene()
{
Slock(screen);
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);

DrawIMG(image, xpos, ypos);

SDL_Flip(screen);
Sulock(screen);
}

int main(int argc, char argv[])
{
Uint8
keys;

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

screen=SDL_SetVideoMode(640,480,32,SDL_FULLSCREEN|SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( screen == NULL )
{
printf(“Unable to set 640x480 video: %s\n”, SDL_GetError());
exit(1);
}

InitImages();
DrawBG();

int done=0;

while(done == 0)
{
SDL_Event event;

while ( SDL_PollEvent(&event) )
{
  if ( event.type == SDL_QUIT )  {  done = 1;  }

  if ( event.type == SDL_KEYDOWN )
  {
    if ( event.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;
}

what’s missing? or maybe it’s my configuration? I’ve got the same problem in a simple tile engine I wrote too.

BTW, should I be able to blt 100 64x48 tiles to a 640x480 screen each frame and generate smooth scrolling on a p/// 800? Just wondering :). Thanks again everyone.

Jeremy Gregorio
@Jeremy_Gregorio

“Jeremy Gregorio” writes:

void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}

You’ve got uninitialized, and therefore random, dest.w and dest.h
values. If they happen to be zero, nothing will be blit’ed.

Derrell

Derrell.Lipman at UnwiredUniverse.com wrote:

You’ve got uninitialized, and therefore random, dest.w and dest.h
values. If they happen to be zero, nothing will be blit’ed.

wrong. destination width/height is ignored — read the manual

“Jeremy Gregorio” wrote in message
news:mailman.1006924446.20674.sdl at libsdl.org

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}

That’s just silly. The ‘Slock’ and ‘Sulock’ functions here do the same
thing as the ‘SDL_LockSurface’ and ‘SDL_UnlockSurface’ functions they wrap,
only slower.

void DrawBG()
{
Slock(screen);
DrawIMG(back, 0, 0);

Sulock(screen);
}

void DrawScene()
{
Slock(screen);
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);

DrawIMG(image, xpos, ypos);

SDL_Flip(screen);
Sulock(screen);
}

Don’t ever blit from or to a locked surface.–
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

void DrawScene()
{
Slock(screen);
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);

DrawIMG(image, xpos, ypos);

SDL_Flip(screen);
Sulock(screen);
}

Don’t ever blit from or to a locked surface.

You also shouldn’t flip a locked surface.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment