예제 #1
0
파일: sdl.c 프로젝트: sbp/cadr
void
sdl_setup_display(void)
{
#if 0
	SDL_Surface *logo;
#endif
	unsigned char *p = screen->pixels;
	int i, j;

	for (i = 0; i < video_width; i++) {
		for (j = 0; j < video_height; j++)
			*p++ = COLOR_WHITE;
	}

#if 0
	logo = IMG_ReadXPMFromArray(logo_xpm);
	SDL_BlitSurface(logo, NULL, screen, NULL);
#else
	{
		char *p;
		unsigned char *ps = screen->pixels;
		for (j = 0; j < 116; j++) {
			p = logo_xpm[3+j];
			for (i = 0; i < 432; i++) {
				if (p[i] != '.')
					ps[i] = COLOR_BLACK;
			}
			ps += video_width;
		}
	}
#endif

	SDL_UpdateRect(screen, 0, 0, video_width, video_height);
}
예제 #2
0
파일: Video.cpp 프로젝트: Zeg9/platformutes
Image::Image(const char **xpm)
{
	SDL_Surface *surf = IMG_ReadXPMFromArray(const_cast<char**>(xpm));
	w = surf->w; h = surf->h;
	if (!surf)
		throw std::runtime_error("Couldn't load xpm");
	tex = SDL_CreateTextureFromSurface(getDevice().renderer, surf);
	SDL_FreeSurface(surf);
}
예제 #3
0
파일: fontmap.c 프로젝트: odrevet/GE
void fontmap_init_from_xpm(fontmap *p_fontmap, char **font_xpm)
{
  p_fontmap->p_surface_font = IMG_ReadXPMFromArray(font_xpm);
  SDL_SetColorKey(p_fontmap->p_surface_font,
		  SDL_SRCCOLORKEY,
		  SDL_MapRGB(p_fontmap->p_surface_font->format,255,0,255));
  if(!p_fontmap->p_surface_font) {
    printf("IMG_ReadXPMFromArray: %s\n", IMG_GetError());
  }
}
예제 #4
0
	bool Image::ReadXPMFromArray(char **xpm)
	{
		SDL_Surface *temp = IMG_ReadXPMFromArray(xpm);

		if(temp == NULL)
			return false;
		else
			m_Surface = temp;

		return true;
	}
예제 #5
0
파일: sdlFunc.c 프로젝트: pepi55/math-in-c
SDL_Texture *loadHeader(char **loc, SDL_Renderer *ren) {
	SDL_Texture *tex = NULL;
	SDL_Surface *loadedSource = IMG_ReadXPMFromArray(loc);

	if (loadedSource != NULL) {
		tex = SDL_CreateTextureFromSurface(ren, loadedSource);
		SDL_FreeSurface(loadedSource);

		if (tex == NULL) logSDLError("CreateTextureFromSource");
	} else {
		logSDLError("LoadSRC");
	}

	return tex;
}
예제 #6
0
파일: fontmap.c 프로젝트: odrevet/GE2
void fontmap_init_from_xpm(fontmap *p_fontmap,
                           char **font_xpm,
                           SDL_Renderer *renderer)
{
    SDL_Surface *p_surface_font = IMG_ReadXPMFromArray(font_xpm);
    if(!p_surface_font) {
        printf("IMG_ReadXPMFromArray: %s\n", IMG_GetError());
    }

    //Transparency
    SDL_SetColorKey(p_surface_font,
                    SDL_TRUE,
                    SDL_MapRGB( p_surface_font->format, 0xFF, 0x00, 0xFF ) );


    p_fontmap->p_texture_font = SDL_CreateTextureFromSurface(renderer,
                                p_surface_font);
    SDL_FreeSurface(p_surface_font);
}
예제 #7
0
// --------------------------------------------------------------------------------------------------------
int kDisplayXPMIcon ( const char ** xpmData, const KPosition & pos )
{
    glPushAttrib(GL_PIXEL_MODE_BIT);
    
    float color[4];
    glGetFloatv(GL_CURRENT_COLOR, color);
    
    glPixelTransferf(GL_RED_SCALE, color[0]);
    glPixelTransferf(GL_GREEN_SCALE, color[1]);
    glPixelTransferf(GL_BLUE_SCALE, color[2]);
    
    SDL_Surface * xpmSurface = IMG_ReadXPMFromArray (const_cast<char **>(xpmData));
    if (xpmSurface == NULL) 
    {
        KConsole::printError("kDisplayXPMIcon: IMG_ReadXPMFromArray failed");
        glPopAttrib();
        return 0;
    }
    SDL_Surface * surface = SDL_ConvertSurface(xpmSurface, &KDL_PIXEL_FORMAT, SDL_SWSURFACE);
    if (surface == NULL) 
    {
        KConsole::printError("kDisplayXPMIcon: SDL_ConvertSurface failed");
        glPopAttrib();
        SDL_FreeSurface(xpmSurface);
        return 0;
    }
    SDL_FreeSurface(xpmSurface);
    
    int width = surface->w;
    glRasterPos2f(pos.x-0.5, pos.y+0.5);
#ifndef _WIN32
    glDrawPixels(surface->w, surface->h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, surface->pixels);
#else
	glDrawPixels(surface->w, surface->h, GL_RGBA, GL_4_BYTES, surface->pixels);
#endif

    SDL_FreeSurface(surface);
    
    glPopAttrib();
    return width;
}
예제 #8
0
int load_ovr(char *filename) {
 int x=0, y=0;
 Uint8 r=0,g=0,b=0, *pix=0;
 int color=0;
 int i=0;
 SDL_Surface *tmp_surface=0;


 if( filename != NULL)
  tmp_surface = IMG_Load(filename);
 else
  tmp_surface = IMG_ReadXPMFromArray((char **)default_overlay_xpm);

 if(!tmp_surface) return -1;

 pix = tmp_surface->pixels;
 i = 0;
 
 for(y=0;y<240;y++) {
  for(x=0;x<320;x++) {
   if(x < tmp_surface->w &&
      y < tmp_surface->h) {
     color = *(int *)pix;
     SDL_GetRGB(color,tmp_surface->format, &r, &g, &b);
    } else {
     /* generate some pretty hash */
     r = x^y;
     g = x^y;
     b = ((x^y)&0xf)*0xf;
   }
   vdp_screen[i].ovr_color.r = r;
   vdp_screen[i].ovr_color.g = g;
   vdp_screen[i++].ovr_color.b = b;
   pix+=tmp_surface->format->BytesPerPixel;
  }
  pix-= (tmp_surface->format->BytesPerPixel * 320);
  pix+= tmp_surface->pitch;
 }
 SDL_FreeSurface(tmp_surface);
 return 1;
}
예제 #9
0
CAMLprim value sdlimagestub_read_xpm_from_array(value xpm)
{
	CAMLparam1(xpm);
	size_t i;
	size_t length = Wosize_val(xpm);
	char **data = malloc((length + 1) * sizeof(char *));
	if(data == NULL){
		caml_raise_out_of_memory();
	}
	for(i = 0; i < length; ++i){
		data[i] = String_val(Field(xpm, i));
	}
	data[length] = NULL;
	SDL_Surface *new_surface = IMG_ReadXPMFromArray(data);
	free(data);
	if(new_surface == NULL){
		raise_failure();
	}
	value result = Val_SDL_Surface(new_surface);
	CAMLreturn(result);
}
SDL_Texture* clsScreen::loadERROR(void) {
    SDL_Surface* temp = IMG_ReadXPMFromArray(image_error_xpm);

	if (temp == nullptr) {
        printf("Failed to load embedded image.\n");
        error();
        return nullptr;
	} else {
	    if (Global::blnDebugMode) {printf("Error surface created.\n");}
    }

	SDL_Texture *tex = SDL_CreateTextureFromSurface(ren,temp);
	SDL_FreeSurface(temp);
	if (tex == nullptr) {
        printf("Failed to create texture.\n");
        error();
	} else {
	    if (Global::blnDebugMode) {printf("Surface to texture successful\n");}
    }

	return tex;
}
예제 #11
0
int main(int argc, char *argv[])
{
	Uint32 flags;
	SDL_Surface *screen, *image;
	int i, depth, done;
	SDL_Event event;
#if 0
	SDL_RWops* rw_ops;
#endif

	/* Check command line usage */
	if ( ! argv[1] ) {
		fprintf(stderr, "Usage: %s <image_file>\n", argv[0]);
		return(1);
	}

	/* Initialize the SDL library */
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(255);
	}

	flags = SDL_SWSURFACE;
	for ( i=1; argv[i]; ++i ) {
		if ( strcmp(argv[i], "-fullscreen") == 0 ) {
			SDL_ShowCursor(0);
			flags |= SDL_FULLSCREEN;
			continue;
		}
#if 0
		rw_ops = SDL_RWFromFile(argv[1], "r");
		
		fprintf(stderr, "BMP:\t%d\n", IMG_isBMP(rw_ops));
		fprintf(stderr, "GIF:\t%d\n", IMG_isGIF(rw_ops));
		fprintf(stderr, "JPG:\t%d\n", IMG_isJPG(rw_ops));
		fprintf(stderr, "PNG:\t%d\n", IMG_isPNG(rw_ops));
		fprintf(stderr, "TIF:\t%d\n", IMG_isTIF(rw_ops));
		/* fprintf(stderr, "TGA:\t%d\n", IMG_isTGA(rw_ops)); */
		fprintf(stderr, "PCX:\t%d\n", IMG_isPCX(rw_ops));
#endif

		/* Open the image file */
#ifdef XPM_INCLUDED
		image = IMG_ReadXPMFromArray(picture_xpm);
#else
		image = IMG_Load(argv[i]);
#endif
		if ( image == NULL ) {
			fprintf(stderr, "Couldn't load %s: %s\n",
			        argv[i], SDL_GetError());
			continue;
		}
		SDL_WM_SetCaption(argv[i], "showimage");

		/* Create a display for the image */
		depth = SDL_VideoModeOK(image->w, image->h, 32, flags);
		/* Use the deepest native mode, except that we emulate 32bpp
		   for viewing non-indexed images on 8bpp screens */
		if ( depth == 0 ) {
			if ( image->format->BytesPerPixel > 1 ) {
				depth = 32;
			} else {
				depth = 8;
			}
		} else
		if ( (image->format->BytesPerPixel > 1) && (depth == 8) ) {
	    		depth = 32;
		}
		if(depth == 8)
			flags |= SDL_HWPALETTE;
		screen = SDL_SetVideoMode(image->w, image->h, depth, flags);
		if ( screen == NULL ) {
			fprintf(stderr,"Couldn't set %dx%dx%d video mode: %s\n",
				image->w, image->h, depth, SDL_GetError());
			continue;
		}

		/* Set the palette, if one exists */
		if ( image->format->palette ) {
			SDL_SetColors(screen, image->format->palette->colors,
			              0, image->format->palette->ncolors);
		}

		/* Draw a background pattern if the surface has transparency */
		if(image->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY))
	    		draw_background(screen);

		/* Display the image */
		SDL_BlitSurface(image, NULL, screen, NULL);
		SDL_UpdateRect(screen, 0, 0, 0, 0);

		done = 0;
		while ( ! done ) {
			if ( SDL_PollEvent(&event) ) {
				switch (event.type) {
				    case SDL_KEYUP:
					switch (event.key.keysym.sym) {
					    case SDLK_LEFT:
						if ( i > 1 ) {
							i -= 2;
							done = 1;
						}
						break;
					    case SDLK_RIGHT:
						if ( argv[i+1] ) {
							done = 1;
						}
						break;
					    case SDLK_ESCAPE:
					    case SDLK_q:
						argv[i+1] = NULL;
						/* Drop through to done */
					    case SDLK_SPACE:
					    case SDLK_TAB:
						done = 1;
						break;
					    default:
						break;
					}
					break;
				    case SDL_MOUSEBUTTONDOWN:
					done = 1;
					break;
                                    case SDL_QUIT:
					argv[i+1] = NULL;
					done = 1;
					break;
				    default:
					break;
				}
			} else {
				SDL_Delay(10);
			}
		}
		SDL_FreeSurface(image);
	}

	/* We're done! */
	SDL_Quit();
	return(0);
}
예제 #12
0
파일: pilot.c 프로젝트: jgraef/aNXT
int main(int argc,char *argv[]) {
  SDL_Event event;
  SDL_Surface *screen;
  SDL_Surface *bg,*left,*enter,*right,*exit,*display_surface;
  SDL_Rect rect_left = {
    .x = 51,
    .y = 172,
    .w = 27,
    .h = 31,
  };
  SDL_Rect rect_enter = {
    .x = 91,
    .y = 173,
    .w = 32,
    .h = 31,
  };
  SDL_Rect rect_right = {
    .x = 136,
    .y = 172,
    .w = 27,
    .h = 31,
  };
  SDL_Rect rect_exit = {
    .x = 91,
    .y = 216,
    .w = 31,
    .h = 20,
  };
  SDL_Rect rect_display = {
    .x = 57,
    .y = 62,
    .w = 100,
    .h = 64,
  };
  int c;
  char *name = NULL;
  int force = 0;

  while ((c = getopt(argc,argv,":hn:f"))!=-1) {
    switch (c) {
      case 'h':
        usage(argv[0],0);
        break;
      case 'f':
        force = 1;
        break;
      case 'n':
        name = optarg;
        break;
      case ':':
        fprintf(stderr,"Option -%c requires an operand\n",optopt);
        usage(argv[0],1);
        break;
      case '?':
        fprintf(stderr,"Unrecognized option: -%c\n", optopt);
        usage(argv[0],1);
        break;
    }
  }

  // init NXT
  nxt_t *nxt = nxt_open(name);
  if (nxt==NULL) {
    fprintf(stderr,"Could not find NXT\n");
    return 1;
  }
  if (nxt_get_connection_type(nxt)==NXT_CON_BT && !force) {
    fprintf(stderr,"Warning! Using NXT Pilot over Bluetooth can make trouble. Are you sure to continue (y/n)[n]: ");
    if (fgetc(stdin)!='y') {
      nxt_close(nxt);
      return 0;
    }
  }
  nxt_display_t *display = nxt_display_open(nxt);
  if (display==NULL) {
    fprintf(stderr,"Could not open display\n");
    nxt_close(nxt);
    return 1;
  }

  // init window
  if (SDL_Init(SDL_INIT_VIDEO)==-1) {
    fprintf(stderr,"Can't init SDL:  %s\n",SDL_GetError());
    return 1;
  }
  atexit(SDL_Quit);
  screen = SDL_SetVideoMode(215,322,32,SDL_HWSURFACE);
  if (screen==NULL) {
    fprintf(stderr,"Can't open window: %s\n",SDL_GetError());
    return 1;
  }
  SDL_WM_SetCaption("NXT Pilot","NXT Pilot");

  // load images
  bg = IMG_ReadXPMFromArray(pilot_bg_xpm);
  left = IMG_ReadXPMFromArray(pilot_left_xpm);
  enter = IMG_ReadXPMFromArray(pilot_enter_xpm);
  right = IMG_ReadXPMFromArray(pilot_right_xpm);
  exit = IMG_ReadXPMFromArray(pilot_exit_xpm);

  // display NXT
  SDL_BlitSurface(bg,NULL,screen,NULL);
  SDL_BlitSurface(left,NULL,screen,&rect_left);
  SDL_BlitSurface(enter,NULL,screen,&rect_enter);
  SDL_BlitSurface(right,NULL,screen,&rect_right);
  SDL_BlitSurface(exit,NULL,screen,&rect_exit);

  int done = 0;
  unsigned int pause = nxt_get_connection_type(nxt)==NXT_CON_BT?500:100;
  while (!done) {
    while (SDL_PollEvent(&event)) {
      switch(event.type) {
        case SDL_QUIT:
          done = 1;
          break;
        case SDL_KEYUP:
          if (event.key.keysym.sym==SDLK_ESCAPE) done = 1;
          else if (event.key.keysym.sym==SDLK_RETURN) nxt_set_button(nxt,NXT_UI_BUTTON_ENTER);
          else if (event.key.keysym.sym==SDLK_BACKSPACE) nxt_set_button(nxt,NXT_UI_BUTTON_EXIT);
          else if (event.key.keysym.sym==SDLK_LEFT) nxt_set_button(nxt,NXT_UI_BUTTON_LEFT);
          else if (event.key.keysym.sym==SDLK_RIGHT) nxt_set_button(nxt,NXT_UI_BUTTON_RIGHT);
          break;
        case SDL_MOUSEBUTTONUP:
          if (in_rect(rect_left,event.button)) nxt_set_button(nxt,NXT_UI_BUTTON_LEFT);
          else if (in_rect(rect_enter,event.button)) nxt_set_button(nxt,NXT_UI_BUTTON_ENTER);
          else if (in_rect(rect_right,event.button)) nxt_set_button(nxt,NXT_UI_BUTTON_RIGHT);
          else if (in_rect(rect_exit,event.button)) nxt_set_button(nxt,NXT_UI_BUTTON_EXIT);
          break;
      }
    }

    display_surface = load_display(display);
    if (display!=NULL) {
      SDL_BlitSurface(display_surface,NULL,screen,&rect_display);
      SDL_UpdateRect(screen,0,0,0,0);
      SDL_FreeSurface(display_surface);
    }

    SDL_Delay(pause);
  }

  // free images
  SDL_FreeSurface(bg);
  SDL_FreeSurface(left);
  SDL_FreeSurface(enter);
  SDL_FreeSurface(right);
  SDL_FreeSurface(exit);

  // close nxt
  int ret = nxt_error(nxt);
  nxt_display_flush(display,1);
  nxt_display_close(display);
  nxt_close(nxt);

  return ret;
}