I have been trying to create an sdl screem amd a ) printf co ordinates of mousebutton event
to console, b ) if that doesnt work and it doesnt .. try fprintf(stderr
message the co ordinates but no luck on that .. not sure I have set it
correctly or c ) create a test file print the co ordinates to the file.
at present no luck .. can anyone hlep me here ..
thanks in advance al.
Code://-lmingw32 -lSDLmain -lSDL
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
struct sdl_screen{
int x;
int y;
} sdlscreen;
SDL_Event event;
SDL_Surface *screen;
int begin_sdl_screen(){
struct sdl_screen *p;
p = &sdlscreen;
// initialize SDL's subsystems - in this case, only video.
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
SDL_WM_SetCaption ("MANDELBROT SET", NULL);
// attempt to create a 200X200 window with 32bit pixels.
screen = SDL_SetVideoMode(p->x, p->y, 32, SDL_SWSURFACE );
// if we fail, return error.
if ( screen == NULL )
{
fprintf(stderr, "Unable to set 200X200 video: %s\n", SDL_GetError());
exit(1);
}
}
int set_screen(){
struct sdl_screen *p;
p = &sdlscreen;
p->x = 400;
p->y = 200;
printf("x %i y %i\n",p->x,p->y );
}
int main(int argc, char *argv[])
{
FILE *f;
char ch;
set_screen();
begin_sdl_screen();
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:{
//fprintf(stderr, "Mouse button %d pressed at (%d,%d)\n"
// ,event.button.button, event.button.x, event.button.y);
f = fopen("test.txt","w");
fprintf(f,"Mouse button %d pressed at (%d,%d)\n",event.button.button, event.button.x, event.button.y);
fclose( f );
}
}
} // SDL_Quit();
ch = getchar();
return 0;
}
