Hi,
I am using SDL for the first time. Windows is the current target platform i am developing for. anyway, I have made the following little program to get started with learning to use SDL. Everything works as expected, except that when I run it, I cannot drag the video window around nor will the minimize or close buttons work. If I drag any other window over the top of my SDL video window the image is refreshed by the while(1) loop under main() but the window border and title bar do not refresh. It is as if SDL is working correctly, but the window manager is not doing its job to maintain/move/minimize the window itself. 99% of my code is just copy/pasted from the getting started tutorials. Am I missing something?
Code:
#define WIN32
/* – Include the precompiled libraries – */
#ifdef WIN32
#pragma comment(lib, “SDL.lib”)
#pragma comment(lib, “SDLmain.lib”)
#endif
#include “SDL.h”
//#include <windows.h>
//SDL_WINDOWID
/*
-
Set the pixel at (x, y) to the given value
-
NOTE: The surface must be locked before calling this!
*/
void putpixel(SDL_Surface surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
/ Here p is the address to the pixel we want to set */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;switch(bpp) {
case 1:
*p = pixel;
break;case 2:
*(Uint16 *)p = pixel;
break;case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;case 4:
*(Uint32 *)p = pixel;
break;
}
}
//----------------------------------------------------------------------------
int main(int argc, char **argv)
{
//setenv(SDL_DEBUG);SDL_Surface *screen;//screen is the vieo output (ie monitor screen)
printf("\nHello SDL User!\n");
//initialize SDL
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
fprintf( stderr, “Video initialization failed: %s\n”,
SDL_GetError( ) );
SDL_Quit( );//clean up b4 exit
return -1;
}/*
- Initialize the display in a 640x480 8-bit palettized mode,
- requesting a software surface
*/
screen = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
SDL_Quit( );//clean up b4 exit
return(1);
}
/* Code to set a yellow pixel at the center of the screen */
int x, y;
Uint32 yellow;/* Map the color yellow to this display (R=0xff, G=0xFF, B=0x00)
Note: If the display is palettized, you must set the palette first.
*/
yellow = SDL_MapRGB(screen->format, 0xff, 0xff, 0x00);while(1){
//Lock the screen for direct access to the pixels
if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface(screen) < 0 ) {
fprintf(stderr, “Can’t lock screen: %s\n”, SDL_GetError());
return -1;
}
}//set all pixels to yellow
for(y=0; y<240; y++){
for(x=0; x<320; x++){
putpixel(screen, x, y, yellow);
}
}//unlock screen
if ( SDL_MUSTLOCK(screen) ) {
SDL_UnlockSurface(screen);
}/* Update just the part of the display that we’ve changed */
SDL_UpdateRect(screen, 0, 0, 0, 0);//see if any errors
printf(“JDD: %s\n”, SDL_GetError());//wait 0.5 sec
SDL_Delay(500);
}//system(“pause”);
//shutdown SDL
SDL_Quit( );
return 0;
}