Fullscreen with mouse pointer suppressed

Hi,

I’m new to SDL and I am loving it up until today. I am preparing to
develop an application that uses a touchscreen (hence why the mouse
pointer needs to be off for this app). I was developing on a normal PC
screen (not at the touchscreen) and all was working great. I have a toy
app that opens fullscreen and prints where I click on the screen. I
obviously enabled the mouse pointer on my normal screen so that I
could…ummm…see where I was clicking :slight_smile:

However, when I suppress the mouse pointer, a weird things happens.
Instead of the origin of the screen being in the upper left corner, it
seems to move towards the center. Any click in the upper left of the
screen registers as (0,0). If I enable the pointer in fullscreen mode,
all works. If I disable the pointer but create it in windowed mode -
all works. It’s when both are done is when the weird problem occurs. I
even tried enabling and disabling in the code to see if tha w ould fix
it. Although by doing this I can see my mouse pointer blink and thus can
test it, I still get the same problem.

Below is the code. Can anyway assist? FYI- I am developing on Windows
XP using SDL 1.2.11 and MinGW 5.0.3.

  • Damian----------------
    #include <iostream.h>
    #include <stdio.h>
    #include <SDL.h>
    #include <SDL_ttf.h>
    #include <sge.h>

char* renderText(int, int, SDL_Surface*, char*);

int main(int argc, char *argv[])
{
SDL_Surface *screen = NULL;
SDL_Event event;
int quit = 0;
char buffer[50];
Uint32 fgcolor = sge_MapAlpha(255, 255, 255, 255);
Uint32 bgcolor = sge_MapAlpha(0, 0, 0, 0);

cout << "Initializing SDL.\n";


/* Initialize defaults */
if((SDL_Init(SDL_INIT_VIDEO) < 0)) 
{ 
    cout << "Could not initialize SDL:" << SDL_GetError();
    return 1;
}

cout << "SDL initialized.\n";

/* Clean up on exit */
atexit(SDL_Quit);
atexit(TTF_Quit);

/*
 * Initialize the display to the desktop resolution (0,0 for
 * first two parms to SDL_SetVideoMode), requesting a software

surface
*/
screen = SDL_SetVideoMode(0, 0, 0,
SDL_SWSURFACE|SDL_ANYFORMAT)|SDL_FULLSCREEN);

if (screen == NULL) 
{
  cout << "Couldn't set video mode: " << SDL_GetError();
  return 1;
}


sprintf(buffer, "Screen set to resolution %d, %d\n", screen->w,

screen->h);
cout << buffer;

// hide the mouse pointer
SDL_ShowCursor(SDL_DISABLE);

    while (quit == 0)
    {

//Event Processing
while( SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
cout << SDL_GetKeyName(event.key.keysym.sym)
<< " key down is pressed\n";
break;
case SDL_KEYUP:
cout << SDL_GetKeyName(event.key.keysym.sym)
<< " key up is pressed\n";
if (strcmp(SDL_GetKeyName(event.key.keysym.sym),
“q”) == 0)
quit = 1;
break;
case SDL_QUIT:
quit = 1;
break;
case SDL_MOUSEBUTTONDOWN:
cout << "mouse click at " << event.button.x
<< ", " << event.button.y << “\n”;
sprintf(buffer, "%d, %d ", event.button.x,
event.button.y);
cout << renderText(0, 100, screen, buffer);

   			    break;
		       } // switch 
    } // while EVENT Processing loop
  } // while quit = 0
    
return 0;		

}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface*
destination )
{
//Make a temporary rectangle to hold the offsets

SDL_Rect offset; 

//Give the offsets to the rectangle 
offset.x = x; 
offset.y = y;

//Blit the surface 
SDL_BlitSurface( source, NULL, destination, &offset ); 

}

char* renderText(int x, int y, SDL_Surface* screen, char* text)
{
SDL_Surface *message = NULL;

//The font that's going to be used 
TTF_Font *font; 

//The color of the font
// SDL_Color textColor = { 255, 255, 255 };
SDL_Color textColor = { 128, 128, 255 };
SDL_Color bgColor = { 0, 0, 0 };

//Initialize SDL_ttf 
if( TTF_Init() == -1 ) 
{ 
	return "error in TTF Init\n"; 
}

//Open the font 
font = TTF_OpenFont( "font.ttf", 14 ); 

//If there was an error in loading the font 
if( font == NULL ) 
{ 
	return TTF_GetError(); 
}
    
message = TTF_RenderText_Shaded(font, text, textColor, bgColor);

//Apply to the screen 
apply_surface( x, y, message, screen ); 

SDL_FreeSurface(message);

//Update the screen 
if( SDL_Flip( screen ) == -1 ) 
  { 
  	return "Error in Flip\n"; 
  }
  
  
return "Success -> renderText\n";

}

Hi Damian,

I think this is a problem with the touchscreen driver. Switching
resolution or even acquiring fullscreen/exclusive mode didn’t work in my
touchscreen programs either. But you can create a borderless window
without titlebar, that has desktop size, and position it at (0,0).
Windows XP then usually hides the taskbar and lets the window cover the
entire screen. Retrieving information about the monitor/desktop size and
positioning of the window is not part of the SDL 1.2 API but will be in 1.3.

int resX = GetSystemMetrics(SM_CXSCREEN);
int resY = GetSystemMetrics(SM_CYSCREEN);
SDL_Surface* screen = SDL_SetVideoMode(resX, resY, …);

SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if (SDL_GetWMInfo(&wmInfo) == 1)
{
SetWindowPos(wmInfo.window,HWND_TOP,0,0,0,0,SWP_NOSIZE);
}

Ciao,
Matthias

Damian Sobieralski schrieb:> Hi,

I’m new to SDL and I am loving it up until today. I am preparing to
develop an application that uses a touchscreen (hence why the mouse
pointer needs to be off for this app). I was developing on a normal PC
screen (not at the touchscreen) and all was working great. I have a toy
app that opens fullscreen and prints where I click on the screen. I
obviously enabled the mouse pointer on my normal screen so that I
could…ummm…see where I was clicking :slight_smile:

However, when I suppress the mouse pointer, a weird things happens.
Instead of the origin of the screen being in the upper left corner, it
seems to move towards the center. Any click in the upper left of the
screen registers as (0,0). If I enable the pointer in fullscreen mode,
all works. If I disable the pointer but create it in windowed mode -
all works. It’s when both are done is when the weird problem occurs. I
even tried enabling and disabling in the code to see if tha w ould fix
it. Although by doing this I can see my mouse pointer blink and thus can
test it, I still get the same problem.

Below is the code. Can anyway assist? FYI- I am developing on Windows
XP using SDL 1.2.11 and MinGW 5.0.3.

  • Damian

#include <iostream.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_ttf.h>
#include <sge.h>

char* renderText(int, int, SDL_Surface*, char*);

int main(int argc, char *argv[])
{
SDL_Surface *screen = NULL;
SDL_Event event;
int quit = 0;
char buffer[50];
Uint32 fgcolor = sge_MapAlpha(255, 255, 255, 255);
Uint32 bgcolor = sge_MapAlpha(0, 0, 0, 0);

cout << "Initializing SDL.\n";


/* Initialize defaults */
if((SDL_Init(SDL_INIT_VIDEO) < 0)) 
{ 
    cout << "Could not initialize SDL:" << SDL_GetError();
    return 1;
}

cout << "SDL initialized.\n";

/* Clean up on exit */
atexit(SDL_Quit);
atexit(TTF_Quit);

/*
 * Initialize the display to the desktop resolution (0,0 for
 * first two parms to SDL_SetVideoMode), requesting a software

surface
*/
screen = SDL_SetVideoMode(0, 0, 0,
SDL_SWSURFACE|SDL_ANYFORMAT)|SDL_FULLSCREEN);

if (screen == NULL) 
{
  cout << "Couldn't set video mode: " << SDL_GetError();
  return 1;
}


sprintf(buffer, "Screen set to resolution %d, %d\n", screen->w,

screen->h);
cout << buffer;

// hide the mouse pointer
SDL_ShowCursor(SDL_DISABLE);

    while (quit == 0)
    {

//Event Processing
while( SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
cout << SDL_GetKeyName(event.key.keysym.sym)
<< " key down is pressed\n";
break;
case SDL_KEYUP:
cout << SDL_GetKeyName(event.key.keysym.sym)
<< " key up is pressed\n";
if (strcmp(SDL_GetKeyName(event.key.keysym.sym),
“q”) == 0)
quit = 1;
break;
case SDL_QUIT:
quit = 1;
break;
case SDL_MOUSEBUTTONDOWN:
cout << "mouse click at " << event.button.x
<< ", " << event.button.y << “\n”;
sprintf(buffer, "%d, %d ", event.button.x,
event.button.y);
cout << renderText(0, 100, screen, buffer);

   			    break;
		       } // switch 
    } // while EVENT Processing loop
  } // while quit = 0
    
return 0;		

}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface*
destination )
{
//Make a temporary rectangle to hold the offsets

SDL_Rect offset;

//Give the offsets to the rectangle
offset.x = x;
offset.y = y;

//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );
}

char* renderText(int x, int y, SDL_Surface* screen, char* text)
{
SDL_Surface *message = NULL;

//The font that's going to be used 

TTF_Font *font;

//The color of the font
// SDL_Color textColor = { 255, 255, 255 };
SDL_Color textColor = { 128, 128, 255 };
SDL_Color bgColor = { 0, 0, 0 };

//Initialize SDL_ttf 
if( TTF_Init() == -1 ) 
{ 
	return "error in TTF Init\n"; 
}

//Open the font 
font = TTF_OpenFont( "font.ttf", 14 ); 

//If there was an error in loading the font 
if( font == NULL ) 
{ 
	return TTF_GetError(); 
}
    
message = TTF_RenderText_Shaded(font, text, textColor, bgColor);

//Apply to the screen 
apply_surface( x, y, message, screen ); 

SDL_FreeSurface(message);

//Update the screen 
if( SDL_Flip( screen ) == -1 ) 
  { 
  	return "Error in Flip\n"; 
  }

return “Success -> renderText\n”;
}


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Matthias Weigand wrote:

Retrieving information about the monitor/desktop size […] is not part of the SDL 1.2 API

Not quite true, as of 1.2.10. From the release notes
http://www.libsdl.org/release/changes-1.2.html:

> - SDL_SetVideoMode() now accepts 0 for width or height and will use the > current video mode (or the desktop mode if no mode has been set.)

(For some reason, this doesn’t seem to be in the documentation
(http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode,
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fVideoInfo) yet…)

I’ve just added the width/height=0 stuff to SDL_SetVideoMode.

-bill!On Fri, Aug 18, 2006 at 10:05:46PM +0200, Christian Walther wrote:

Matthias,

I think this is a problem with the touchscreen driver.

That’s what I thought as well. But I installed SDL on a second computer
that never has had the touchscreen hooked up to it or the TS drivers and
it is doing the same thing.

But you can create a borderless window without titlebar, that has
desktop size, and position it at (0,0).

Thanks. If I cannot find a workaround I will do exactly what you
stated. Thanks much for the code segements!

I guess the larger question goes - has anyone created a full screen
app via SDL and disabled the mouse pointer (no touchscreen) and had
click coordinates accurately registered? I know w/o the touchscreen not
having the pointer on seems silly but the same thing happens when I have
it hooked up to a computer w/ no touchscreen and cycle the pointer off
and on in a loop. That way I can see the pointer briefly to see where it
is at but anything in the upper left of the screen registers as (0,0).
Maybe since it would be unusual to go fullscreen with pointer off w/o a
TS that it’s always blamed the ts drivers. Could this be a bug in the
API? Could anyone put my mind at ease by trying to do so and letting me
know if mine is an isolated incident? I’ll supply code that just uses
SDL if I have any takes (I’ll remove my SGE references for an easy
compile).

Thanks!

  • Damian

I had a very similar problem to this, probably the same thing. The
behaviour doesn’t happen in linux, only windows for me. Basically,
when you hide the cursor in fullscreen mode, the next time a
mouse motion event is generated, there are actually two
generated; one to center the mouse. Very strange and I don’t think
that it happened in earlier versions. I also saw a note on another
linux/SDL/GL game which had a hack to fix this apparently. I still
haven’t checked if that fixes it for me as well.

Anybody else encounter this?

Calvin

Hi,

I’m new to SDL and I am loving it up until today. I am preparing to
develop an application that uses a touchscreen (hence why the mouse
pointer needs to be off for this app). I was developing on a normal PC
screen (not at the touchscreen) and all was working great. I have a toy
app that opens fullscreen and prints where I click on the screen. I
obviously enabled the mouse pointer on my normal screen so that I
could…ummm…see where I was clicking :slight_smile:


http://www.venturethevoid.com

Matthias Weigand wrote:

positioning of the window is not part of the SDL 1.2 API but will be
in
1.3.

BTW- when is SDL 1.3 due out for general consumption?

Matthias Weigand wrote:

positioning of the window is not part of the SDL 1.2 API but will be
in
1.3.

BTW- when is SDL 1.3 due out for general consumption?

Probably early next year.
Right now I’m toying with the idea of programmatically generating blitters
so they’re easier to debug and we can add general scaling and rotation.

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello !

Right now I’m toying with the idea of programmatically generating blitters
so they’re easier to debug and we can add general scaling and rotation.

Programmatically ? What does that mean ?

CU

Hello !

Right now I’m toying with the idea of programmatically generating blitters
so they’re easier to debug and we can add general scaling and rotation.

Programmatically ? What does that mean ?

Scripts that generate optimized blitting code for each of the combinations
of cases.

I’m still thinking this through, so I’m not sure if I’ll add this yet.

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

I guess the larger question goes - has anyone created a full screen
app via SDL and disabled the mouse pointer (no touchscreen) and had
click coordinates accurately registered?

Yep, works fine here. Can you submit a bug with a test case to
bugzilla.libsdl.org?

Thanks!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello !

Scripts that generate optimized blitting code for each of the
combinations of cases.

I’m still thinking this through, so I’m not sure if I’ll add this yet.

What Script Language do you have in mind ?

CU

When I looked the GL renderer I thought that it would be quite usefull
to make a GLSL renderer also, because then one could use the paletted
textures easily. As currently it seams that all textures are converted
to RGB(A) textures, which can in the worst case take almost four times
as much memory as a paletted one.

GLSL renderer could also blit YUV textures even the packed YUV formats.On Tuesday 22 August 2006 01:41, Sam Lantinga wrote:

Hello !

Right now I’m toying with the idea of programmatically generating
blitters so they’re easier to debug and we can add general
scaling and rotation.

Programmatically ? What does that mean ?

Scripts that generate optimized blitting code for each of the
combinations of cases.

I’m still thinking this through, so I’m not sure if I’ll add this
yet.

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello !

Right now I’m toying with the idea of programmatically generating blitters
so they’re easier to debug and we can add general scaling and rotation.

Programmatically ? What does that mean ?

Scripts that generate optimized blitting code for each of the combinations
of cases.

I’m still thinking this through, so I’m not sure if I’ll add this yet.

I’ve used it several times. Easy to do. Kind of hard to explain. Works
great.

	Bob PendletonOn Mon, 2006-08-21 at 15:41 -0700, Sam Lantinga wrote:

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-------------------------------------+

Scripts that generate optimized blitting code for each of the combinations
of cases.

I’m still thinking this through, so I’m not sure if I’ll add this yet.

Funny, I’m currently doing this for the audio filters. :slight_smile:

Just too many damned codepaths otherwise with the new data types…

–ryan.

Hello !

Scripts that generate optimized blitting code for each of the combinations
of cases.

I’m still thinking this through, so I’m not sure if I’ll add this yet.

Funny, I’m currently doing this for the audio filters. :slight_smile:

Just too many damned codepaths otherwise with the new data types…

I am very interested. Please tell more ! What, how ?

CU

I just did. Bug 306.----
Message: 6
Date: Mon, 21 Aug 2006 15:43:36 -0700
From: slouken@libsdl.org (slouken)
Subject: Re: [SDL] Fullscreen with mouse pointer suppressed

I guess the larger question goes - has anyone created a full screen
app via SDL and disabled the mouse pointer (no touchscreen) and had
click coordinates accurately registered?

Yep, works fine here. Can you submit a bug with a test case to
bugzilla.libsdl.org?

Thanks!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

I am very interested. Please tell more ! What, how ?

This file…
http://www.libsdl.org/cgi/viewvc.cgi/trunk/SDL/src/audio/SDL_audiotypecvt.c?view=co

…is generated by this one…
http://www.libsdl.org/cgi/viewvc.cgi/trunk/SDL/src/audio/sdlgenaudiocvt.pl?view=co

This saves a lot of tapdancing in SDL_BuildAudioCVT(), and allows us to
go from any supported audio data type to any other one in one pass over
the data. Previously it would take a pass to change from signed to
unsigned, then another to go from little endian to big endian, etc,
which beats up the CPU cache more. Some of the conversions implicitly
depended on others being done first, and assumed certain truths (all
integer data, all 8 or 16 bit, etc).

BuildAudioCVT() has a hook for adding custom converters before these
autogenerated ones…that’ll let us add an SSE2 float-to-int converter,
for example…these special cases can get first shot at the data before
it falls back to the autogenerated code.

The perl script made sense once I decided to go this route…it means
maintaining 300 lines of perl instead of 2500 lines of repetitive C code
for the data converters. It doesn’t add perl as a dependency to the
build process, since this code won’t need to be regenerated often.

–ryan.

Hello !

This file…
http://www.libsdl.org/cgi/viewvc.cgi/trunk/SDL/src/audio/SDL_audiotypecvt.c?view=co

…is generated by this one…
http://www.libsdl.org/cgi/viewvc.cgi/trunk/SDL/src/audio/sdlgenaudiocvt.pl?view=co

Really cool. Another reason to learn PERL !

CU