Example #1
2
int main(int argc, char **argv) {
  SDL_Init(SDL_INIT_VIDEO);
  SDL_Surface *screen = SDL_SetVideoMode(40, 40, 32, SDL_SWSURFACE);

  SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 0xff, 0, 0, 0xff));
  SDL_LockSurface(screen);
  *((int*)screen->pixels + 95) = 0;
  SDL_UnlockSurface(screen);

  SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 0, 0xff, 0, 0xff)); // wipe out previous pixel and fill
  SDL_LockSurface(screen);
  *((int*)screen->pixels + 205) = 0;
  SDL_UnlockSurface(screen);

  SDL_Flip(screen);

  return 0;
}
Example #2
0
void Color::mapColor(SDL_PixelFormat *format)
{
    if(!mapped)
    {
        //map = SDL_MapRGB(format, red, green, blue);
        map = SDL_MapRGBA(format, red, green, blue, alpha);
        mapped = true;
    }
}
Example #3
0
static void
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
{
    if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
    {
      	return;
    }

    Sint16 *vx, *vy;
    Sint16 x, y;
    int i;

    vx = alloca(count * sizeof(Sint16));
    vy = alloca(count * sizeof(Sint16));

    for(i = 0; i < count; i++)
    {
        x = (Sint16)p[i].x;
        y = (Sint16)p[i].y;
        vx[i] = x;
        vy[i] = y;

        dbg(lvl_debug, "draw_polygon: %p %i %d,%d\n", gc, i, p[i].x, p[i].y);
    }

    if(gr->aa)
    {
        raster_aapolygon(gr->screen, count, vx, vy,
                SDL_MapRGBA(gr->screen->format,
                    gc->fore_r,
                    gc->fore_g,
                    gc->fore_b,
                    gc->fore_a));
    }
    else
    {
        raster_polygon(gr->screen, count, vx, vy,
                SDL_MapRGBA(gr->screen->format,
                    gc->fore_r,
                    gc->fore_g,
                    gc->fore_b,
                    gc->fore_a));
    }
}
Example #4
0
// We don't use colors
void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
{
  int x, y;
  Uint8 a;
  Uint32 amask;

  if (calligraphy_r == r &&
      calligraphy_g == g &&
      calligraphy_b == b)
    return;

  calligraphy_r = r;
  calligraphy_g = g;
  calligraphy_b = b;

  if (calligraphy_colored_brush != NULL)
    SDL_FreeSurface(calligraphy_colored_brush);

  amask = ~(calligraphy_brush->format->Rmask |
            calligraphy_brush->format->Gmask |
            calligraphy_brush->format->Bmask);

  calligraphy_colored_brush =
    SDL_CreateRGBSurface(SDL_SWSURFACE,
                         calligraphy_brush->w,
                         calligraphy_brush->h,
                         calligraphy_brush->format->BitsPerPixel,
                         calligraphy_brush->format->Rmask,
                         calligraphy_brush->format->Gmask,
                         calligraphy_brush->format->Bmask, amask);

  if (calligraphy_colored_brush == NULL)
    return; // FIXME: Error!

  SDL_LockSurface(calligraphy_brush);
  SDL_LockSurface(calligraphy_colored_brush);


  for (y = 0; y < calligraphy_brush->h; y++)
  {
    for (x = 0; x < calligraphy_brush->w; x++)
    {
      SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y),
                  calligraphy_brush->format, &r, &g, &b, &a);

      api->putpixel(calligraphy_colored_brush, x, y,
                     SDL_MapRGBA(calligraphy_colored_brush->format,
                                 calligraphy_r,
                                 calligraphy_g,
                                 calligraphy_b, a));
    }
  }

  SDL_UnlockSurface(calligraphy_colored_brush);
  SDL_UnlockSurface(calligraphy_brush);
}
Example #5
0
/* Updates the console, draws the background and the history lines. Does not draw the Commandline */
void CON_UpdateConsole(ConsoleInformation * console)
{
    int loop;
    int loop2;
    int Screenlines;
    SDL_Rect DestRect;
    /*BitFont *CurrentFont = DT_FontPointer(console->FontNumber);*/

    if (!console)
        return;

    /* Due to the Blits, the update is not very fast: So only update if it's worth it */
    if (!CON_isVisible(console))
        return;

    Screenlines = console->ConsoleSurface->h / console->FontHeight;


    SDL_FillRect(console->ConsoleSurface, NULL,
                 SDL_MapRGBA(console->ConsoleSurface->format, 0, 20, 0,
                             SDL_ALPHA_OPAQUE));

    /* draw the background image if there is one */
    if (console->BackgroundImage) {
        DestRect.x = console->BackX;
        DestRect.y = console->BackY;
        DestRect.w = console->BackgroundImage->w;
        DestRect.h = console->BackgroundImage->h;
        SDL_BlitSurface(console->BackgroundImage, NULL,
                        console->ConsoleSurface, &DestRect);
    }

    /*      now draw text from last but second line to top
       loop: for every line in the history
       loop2: draws the scroll indicators to the line above the Commandline
     */
    for (loop = 0;
            loop < Screenlines - 1
            && loop < console->LineBuffer - console->ConsoleScrollBack;
            loop++) {
        if (console->ConsoleScrollBack != 0 && loop == 0)
            for (loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++)
                DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface,
                            console->FontNumber,
                            CON_CHAR_BORDER +
                            (loop2 * 5 * console->FontWidth),
                            (Screenlines - loop -
                             2) * console->FontHeight);
        else
            DT_DrawText(console->
                        ConsoleLines[console->ConsoleScrollBack + loop],
                        console->ConsoleSurface, console->FontNumber,
                        CON_CHAR_BORDER,
                        (Screenlines - loop - 2) * console->FontHeight);
    }
}
Example #6
0
static void fold_shadow(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * temp,
		       int x, int y)
{
  magic_api * api = (magic_api *) ptr;
  Uint8 r,g,b,a;
	  SDL_GetRGBA(api->getpixel(temp, x, y),
		      temp->format, &r, &g, &b, &a);
	  api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format,
						  max(r-160+fold_shadow_value*4,0), max(g-160+fold_shadow_value*4,0), max(b-160+fold_shadow_value*4,0), a));
}
Example #7
0
/* set color key */
void Surface::SetDefaultColorKey(void)
{
    if(isValid())
    {
	const u32 clkey = amask() ? SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, 0) : 
				    SDL_MapRGB(surface->format, 0xFF, 0, 0xFF);
	Fill(clkey);
	SetColorKey(clkey);
    }
}
Example #8
0
/**
Crops surface to the rectangle and returns it a new surface.
*/
SDL_Surface* Gfx::crop(SDL_Surface *tobecropped, SDL_Rect *r){

    SDL_SetAlpha(tobecropped, 0, SDL_ALPHA_OPAQUE);
    SDL_Surface *croppedx = SDL_CreateRGBSurface(SDL_HWSURFACE, r->w, r->h, 32, 0, 0, 0, 0);
    SDL_Surface *cropped = SDL_DisplayFormatAlpha(croppedx);
    SDL_FillRect(cropped, NULL, SDL_MapRGBA(cropped->format, 0, 0, 0, 0));

    SDL_BlitSurface(tobecropped,r,cropped,NULL);
    return cropped;
}
Example #9
0
/* Updates the console, draws the background and the history lines. Does not draw the Commandline */
void CON_UpdateConsole(ConsoleInformation *console) {
	int loop;
	int loop2;
	int Screenlines;
	SDL_Rect DestRect;
	BitFont *CurrentFont = DT_FontPointer(console->FontNumber);

	if(!console)
		return;

	/* Due to the Blits, the update is not very fast: So only update if it's worth it */
	if(!CON_isVisible(console))
		return;

	Screenlines = console->ConsoleSurface->h / console->FontHeight;


	SDL_FillRect(console->ConsoleSurface, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, console->ConsoleAlpha));

	if(console->OutputScreen->flags & SDL_OPENGLBLIT)
		SDL_SetAlpha(console->ConsoleSurface, 0, SDL_ALPHA_OPAQUE);

	/* draw the background image if there is one */
	if(console->BackgroundImage) {
		DestRect.x = console->BackX;
		DestRect.y = console->BackY;
		DestRect.w = console->BackgroundImage->w;
		DestRect.h = console->BackgroundImage->h;
		SDL_BlitSurface(console->BackgroundImage, NULL, console->ConsoleSurface, &DestRect);
	}

	/* Draw the text from the back buffers, calculate in the scrollback from the user
	 * this is a normal SDL software-mode blit, so we need to temporarily set the ColorKey
	 * for the font, and then clear it when we're done.
	 */
	if((console->OutputScreen->flags & SDL_OPENGLBLIT) && (console->OutputScreen->format->BytesPerPixel > 2)) {
		Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels);
		SDL_SetColorKey(CurrentFont->FontSurface, SDL_SRCCOLORKEY, *pix);
	}

	/*	now draw text from last but second line to top
		loop: for every line in the history
		loop2: draws the scroll indicators to the line above the Commandline
	*/
	for(loop = 0; loop < Screenlines-1 && loop < console->LineBuffer - console->ConsoleScrollBack; loop++) {
		if(console->ConsoleScrollBack != 0 && loop == 0)
			for(loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++)
				DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER + (loop2*5*console->FontWidth), (Screenlines - loop - 2) * console->FontHeight);
		else
			DT_DrawText(console->ConsoleLines[console->ConsoleScrollBack + loop], console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER, (Screenlines - loop - 2) * console->FontHeight);
	}

	if(console->OutputScreen->flags & SDL_OPENGLBLIT)
		SDL_SetColorKey(CurrentFont->FontSurface, 0, 0);
}
Example #10
0
void CSprite::generateSprite( const int points )
{
	Uint32 color = 0;
	Uint8 r,g,b,a;
	std::string pointStr = itoa(points);

	setSize( pointStr.size()*8, 8);

	createSurface( g_pVideoDriver->mp_VideoEngine->getBlitSurface()->flags, g_pGfxEngine->Palette.m_Palette  );
	optimizeSurface();

	SDL_FillRect(mpSurface.get(), NULL, 0xFFFFFFFF);

	CFont &smallFont = g_pGfxEngine->getFont(2);

	// Create Text Borders TODO: Make this code to draw better looking fonts
	smallFont.drawFont( mpSurface.get(), pointStr, -1,  0 );
	smallFont.drawFont( mpSurface.get(), pointStr,  0, -1 );
	smallFont.drawFont( mpSurface.get(), pointStr,  1, 0 );
	smallFont.drawFont( mpSurface.get(), pointStr,  0, 1 );

	// Now draw the alternate font. It just has another color.
	smallFont.drawFont( mpSurface.get(), pointStr, 0,  0, true );

	if(SDL_MUSTLOCK(mpSurface.get())) SDL_LockSurface(mpSurface.get());

	// This makes the white pixel transparent TODO: This and other must get more elegant
	Uint8 *pixel = (Uint8*)mpSurface->pixels;

	for( Uint8 y=0 ; y<mpSurface->h ; y++ )
	{
		for( Uint8 x=0 ; x<mpSurface->w ; x++ )
		{
			memcpy( &color, pixel, mpSurface->format->BytesPerPixel );

			SDL_GetRGBA( color, mpSurface->format, &r, &g, &b, &a );

			if( color == 0xFFFFFFFF ) // White
				a = 0;

			color = SDL_MapRGBA( mpSurface->format, r, g, b, a );

			memcpy( pixel, &color, mpSurface->format->BytesPerPixel );

			pixel += mpSurface->format->BytesPerPixel;
		}
	}
	if(SDL_MUSTLOCK(mpSurface.get())) SDL_LockSurface(mpSurface.get());


	m_bboxX1=0;
	m_bboxY1=0;
	m_bboxX2=getWidth();
	m_bboxY2=getHeight();
}
Example #11
0
/*  Convert a color to SDL's integer format  */
int BrogueDisplay_colorToSDL(SDL_Surface *surface, BROGUE_DRAW_COLOR *color)
{
    int ret;

    ret = SDL_MapRGBA(surface->format, 
			   colorFloat2Byte(color->red),
			   colorFloat2Byte(color->green),
			   colorFloat2Byte(color->blue),
			   255);
    return ret;
}
/**
 * \brief Loads a texture from an image file and fits into a GL-compatible size.
 * \param fileName The name of the image file.
 * \param filtering True for linear filtering, false for nearest-neighbor.
 * \param realW Returns the real width of the texture.
 * \param realH Returns the real height of the texture.
 * \return The OpenGL texture ID.
 */
long SDLGL_LoadTextureFromFileBestFit( std::string fileName, bool filtering, unsigned long &realW, unsigned long &realH ) {
  GLuint theTexture;
  SDL_Surface *loadSurface, *theSurface, *convertedSurface;
  Uint32 rmask, gmask, bmask, amask;

  loadSurface = IMG_Load( fileName.c_str() );

  if ( loadSurface ) {
    #if SDL_BYTEORDER == SDL_BIG_ENDIAN
      rmask = 0xff000000;
      gmask = 0x00ff0000;
      bmask = 0x0000ff00;
      amask = 0x000000ff;
    #else
      rmask = 0x000000ff;
      gmask = 0x0000ff00;
      bmask = 0x00ff0000;
      amask = 0xff000000;
    #endif
    theSurface = SDL_CreateRGBSurface( SDL_SWSURFACE | SDL_SRCALPHA, NextPowerOfTwo(loadSurface->w), NextPowerOfTwo(loadSurface->h), 32, rmask, gmask, bmask, amask );
    SDL_FillRect( theSurface, NULL, SDL_MapRGBA( theSurface->format, 0,0,0,255 ) );
    convertedSurface = SDL_ConvertSurface( loadSurface, theSurface->format, SDL_SWSURFACE | SDL_SRCALPHA );

    MoveTexture( convertedSurface, theSurface );
  }
  else
    theSurface = NULL;

  if ( theSurface ) {
    glGenTextures( 1, &theTexture);

    glBindTexture( GL_TEXTURE_2D, theTexture );

    if ( filtering ) {
      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    } else {
      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    }

    realW = loadSurface->w;
    realH = loadSurface->h;
    glTexImage2D( GL_TEXTURE_2D, 0, 4, theSurface->w, theSurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, theSurface->pixels );

    SDL_FreeSurface( theSurface );
    SDL_FreeSurface( loadSurface );
    SDL_FreeSurface( convertedSurface );

    return theTexture;
  }
  else
    return 0; // GLspeak for "no texture"
}
static Uint32 value_2_color(VALUE color, SDL_PixelFormat *fmt, Uint8 *alpha)
{
  VALUE *array = RARRAY_PTR(color);
  if(alpha != NULL){ *alpha = (Uint8)(NUM2INT(*(array+3))); }
  return SDL_MapRGBA(fmt,
                     (Uint8)(NUM2INT(*(array+0))),
                     (Uint8)(NUM2INT(*(array+1))),
                     (Uint8)(NUM2INT(*(array+2))),
                     (Uint8)(NUM2INT(*(array+3)))
                    );
}
Example #14
0
	void Surface::makeTransparent(void)
	{
        if(sdlSurface != nullptr)
		{
			Uint32 colorkey = SDL_MapRGBA(sdlSurface->format, 0, 0, 0, 0);
			SDL_Rect *src = getRect();
			SDL_FillRect(sdlSurface, src, colorkey);
			SDL_SetColorKey(sdlSurface, SDL_TRUE, colorkey);
			delete src;
		}
	}
Example #15
0
Uint32 Imagen::atransparentar(){
	//try{
		if(superficie == NULL) return 0;
		Uint32 color = SDL_MapRGBA(superficie->format,255,0,255,255);
		SdlSurfaceManager::dibujarCuadrado(superficie,0,0,superficie->w,superficie->h,color);
		return color;
	//}catch(...){
	//	if(this!=NULL)this->fallar();
	//	return 0;
	//}
}
Example #16
0
//nueva superficie de las dimensiones pasadas
Imagen::Imagen(int ancho,int alto){
	//try{
		if(ancho == 0) ancho = 10;
		if(alto == 0) alto = 10;
		superficie = SdlSurfaceManager::crearSup(ancho,alto);
		Uint32 negro = SDL_MapRGBA(superficie->format,0,0,0,255);
		SdlSurfaceManager::pintarSup(superficie,negro);
	//}catch(...){
	//	if(this!=NULL)this->fallar();
	//}
}
Example #17
0
void Picture::fill( const NColor& color, const Rect& rect )
{
  SDL_Surface* source = _d->surface;

  SDL_LockSurface( source );
  SDL_Rect sdlRect = { (short)rect.getLeft(), (short)rect.getTop(), (Uint16)rect.getWidth(), (Uint16)rect.getHeight() };

  SDL_FillRect(source, rect.getWidth() > 0 ? &sdlRect : NULL, SDL_MapRGBA( source->format, color.getRed(), color.getGreen(), 
                                                                                           color.getBlue(), color.getAlpha() )); 
  SDL_UnlockSurface(source);
}
Example #18
0
/**
 *  Colors the background to the stored drawing color.
 *  Coloring is done differently for each rendering mode.
 */
void n8::RenderService::ColorBackground(int p_red, int p_green, int p_blue, int p_alpha){
    SetDrawingColor(p_red, p_green, p_blue, p_alpha);
    
    if (m_renderMode == ESprite) {
        SDL_Surface* surface = SDL_GetWindowSurface(const_cast<SDL_Window*>(&m_gameWindow->GetWindow()));
        SDL_FillRect(const_cast<SDL_Surface*>(&m_gameWindow->GetSurface()), NULL, SDL_MapRGBA(surface->format, m_red,m_green,m_blue,m_alpha));
    }
    else{
        SDL_RenderClear(const_cast<SDL_Renderer*>(&m_gameWindow->GetRenderer()));
    }
}
Example #19
0
SDL_Surface *CGeneral::RenderCard(const CCard &c, int w, int h)
{
   SDL_Surface *s;
   int pw = m_imgCards->w / 4, ph = m_imgCards->h / 13;

   s = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE,
      w, h, gpScreen->format->BitsPerPixel,
      gpScreen->format->Rmask, gpScreen->format->Gmask,
      gpScreen->format->Bmask, gpScreen->format->Amask);

   w--;
   h--;

   SDL_SetColorKey(s, SDL_SRCCOLORKEY, SDL_MapRGBA(s->format, 0, 0, 0, 0));
   UTIL_FillRect(s, w, 1, 1, h - 1, 1, 1, 1);
   UTIL_FillRect(s, 1, h, w, 1, 1, 1, 1);

   SDL_Rect dstrect, dstrect2;
   if (c.GetValue() >= 48) {
      dstrect.x = pw * 2;
      dstrect.y = ph * 12;
   } else {
      dstrect.x = (c.GetValue() & 3) * pw;
      dstrect.y = (c.GetMonth() - 1) * ph;
   }
   dstrect.w = pw;
   dstrect.h = ph;
   dstrect2.x = dstrect2.y = 0;
   dstrect2.w = w;
   dstrect2.h = h;

   UTIL_ScaleBlit(m_imgCards, &dstrect, s, &dstrect2);

   if (c.m_iRenderEffect & EF_DARK) {
      int i, j;
      unsigned char r, g, b;
      for (i = 0; i < s->w; i++) {
         for (j = 0; j < s->h; j++) {
            UTIL_GetPixel(s, i, j, &r, &g, &b);
            r = r * 2 / 3;
            g = g * 2 / 3;
            b = b * 2 / 3;
            UTIL_PutPixel(s, i, j, r, g, b);
         }
      }
   }

   if (c.m_iRenderEffect & EF_BOX) {
      UTIL_RectShade(s, 0, 0, w, h, 255, 255, 0, 0, 255, 255, 255, 0, 255);
      UTIL_RectShade(s, 1, 1, w - 2, h - 2, 255, 255, 0, 0, 255, 255, 255, 0, 255);
   }

   return s;
}
Example #20
0
/****************************************************************************
  Draw a filled-in colored rectangle onto canvas.
****************************************************************************/
void canvas_put_rectangle(struct canvas *pcanvas, struct color *pcolor,
		          int canvas_x, int canvas_y, int width, int height)
{
  SDL_Rect dst = {canvas_x, canvas_y, width, height};
  
  SDL_FillRect(pcanvas->surf, &dst, SDL_MapRGBA(pcanvas->surf->format,
                                                pcolor->color->r,
                                                pcolor->color->g,
		                                 pcolor->color->b,
                                                pcolor->color->unused));
}
Example #21
0
SDL_Surface* filtre_bright_p(t_display display, int coef)
{
	int x, y, n;
 
    Uint8 r_s, g_s, b_s, a_s;
 
    Uint32 pixel_s;
 
    SDL_LockSurface(display.screen);

	n = (coef - 50) * 2.55;
	for (y = 0 ; y < display.screen->h; y ++)
        {
                for ( x = 0 ; x < display.screen->w; x ++)
                {
					
					pixel_s = *((Uint32*)(display.screen->pixels) + x + y * WINX);
 
                    SDL_GetRGBA(pixel_s, display.screen->format, &r_s, &g_s, &b_s, &a_s);


					if (r_s > 255 - n)
						r_s = 255;
					else
						r_s = r_s + n;

					if (g_s > 255 - n)
						g_s = 255;
					else
						g_s = g_s + n;

					if (b_s > 255 - n)
						b_s = 255;
					else
						b_s = b_s + n;

                   
                    pixel_s = SDL_MapRGBA(display.screen->format, r_s, g_s, b_s, a_s);
					setPixel(&display, x, y, pixel_s);

				}

		}


  	SDL_UnlockSurface(display.screen);

		SDL_BlitSurface(display.screen, NULL, display.screen, NULL);

		SDL_Flip(display.screen);

		return display.screen;
}
Example #22
0
SDL_Surface* filtre_lum_moins(t_display display)
{
	int x, y;
 
    Uint8 r_s, g_s, b_s, a_s;
 
    Uint32 pixel_s;
 
    SDL_LockSurface(display.screen);

	
	for (y = 0 ; y < display.screen->h; y ++)
        {
                for ( x = 0 ; x < display.screen->w; x ++)
                {
					
					pixel_s = *((Uint32*)(display.screen->pixels) + x + y * WINX);
 
                    SDL_GetRGBA(pixel_s, display.screen->format, &r_s, &g_s, &b_s, &a_s);


					if (r_s < 50)
						r_s = 0;
					else
						r_s = r_s - 50;

					if (g_s < 50)
						g_s = 0;
					else
						g_s = g_s - 50;

					if (b_s < 50)
						b_s = 0;
					else
						b_s = b_s - 50;

                   
                    pixel_s = SDL_MapRGBA(display.screen->format, r_s, g_s, b_s, a_s);
					setPixel(&display, x, y, pixel_s);

				}

		}


  	SDL_UnlockSurface(display.screen);

		SDL_BlitSurface(display.screen, NULL, display.screen, NULL);

		SDL_Flip(display.screen);

		return display.screen;
}
Example #23
0
		int inline LOBJECT_METHOD(mapRGBA, SDL_PixelFormat * format){
			state.push_integer(
				SDL_MapRGBA(
					format,
					(Uint8)state.to_integer(1),
					(Uint8)state.to_integer(2),
					(Uint8)state.to_integer(3),
					(Uint8)state.to_integer(4)
					));

			return 1;
		}
Example #24
0
Uint32 to_pixel(SDL_PixelFormat *fmt, double value) {
	double v = (value + (double) 1) / (double) 2;
	int a = 255;
	double r, g, b;
	if(v <= 0.5) { // water
		double p = v / 0.5;
		r = 0;
		g = 0;
		b = __i(p, 0.5, 1);
	}
	else if(v <= 0.53) { // beach
		double p = (v - 0.5) / 0.03;
		p = sqrt(p);
		r = __i(p, 0, 1);
		g = __i(p, 0, 1);
		b = __i(p, 1, 0.5);
	}
	else if(v <= 0.56) { // to-grass
		double p = (v - 0.53) / 0.03;
		p = __c(p);
		r = __i(p, 1, 0.5);
		g = 1;
		b = 0.5;
	}
	else if(v <= 0.7) { // grass
		r = 0.5;
		g = 1;
		b = 0.5;
	}
	else if(v <= 0.71) { // to-mountain
		double p = (v - 0.7) / 0.01;
		r = 0.5;
		g = __i(p, 1, 0.5);
		b = 0.5;
	}
	else if(v <= 0.80) { // mountain
		double p = (v - 0.71) / 0.09;
		r = __i(p, 0.5, 1);
		g = __i(p, 0.5, 1);
		b = __i(p, 0.5, 1);
	}
	else { // snow
		r = 1;
		g = 1;
		b = 1;
	}
	return SDL_MapRGBA(fmt,
		(int)(r * (double) 255),
		(int)(g * (double) 255),
		(int)(b * (double) 255),
		a
	);
}
Example #25
0
static void init_colors(Screen *screen) {
  SDL_PixelFormat *f = screen->screen->format; /* shortcut */
  screen->colors.red = SDL_MapRGBA(f, 255, 0, 0, 255);
  screen->colors.green = SDL_MapRGBA(f, 0, 255, 0, 255);
  screen->colors.blue = SDL_MapRGBA(f, 0, 0, 255, 255);
  screen->colors.white = SDL_MapRGBA(f, 255, 255, 255, 255);
  screen->colors.black = SDL_MapRGBA(f, 0, 0, 0, 255);
  screen->colors.grey = SDL_MapRGBA(f, 150, 150, 150, 255);
  screen->colors.dark_grey = SDL_MapRGBA(f, 80, 80, 80, 255);
}
/**
 * Helper that clears the test surface
 */
void _clearTestSurface()
{
    int ret;
    Uint32 color;

    /* Clear surface. */
    color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
    SDLTest_AssertPass("Call to SDL_MapRGBA()");
    ret = SDL_FillRect( testSurface, NULL, color);
    SDLTest_AssertPass("Call to SDL_FillRect()");
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
}
void mouse_action::set_terrain_mouse_overlay(editor_display& disp, t_translation::t_terrain fg,
		t_translation::t_terrain bg)
{
	surface image_fg(image::get_image("terrain/"
		+ disp.get_map().get_terrain_info(fg).editor_image() + ".png"));
	surface image_bg(image::get_image("terrain/"
		+ disp.get_map().get_terrain_info(bg).editor_image() + ".png"));

	if (image_fg == NULL || image_bg == NULL) {
		ERR_ED << "Missing terrain icon\n";
		disp.set_mouseover_hex_overlay(NULL);
		return;
	}

	// Create a transparent surface of the right size.
	surface image = create_compatible_surface(image_fg, image_fg->w, image_fg->h);
	SDL_FillRect(image,NULL,SDL_MapRGBA(image->format,0,0,0, 0));

	// For efficiency the size of the tile is cached.
	// We assume all tiles are of the same size.
	// The zoom factor can change, so it's not cached.
	// NOTE: when zooming and not moving the mouse, there are glitches.
	// Since the optimal alpha factor is unknown, it has to be calculated
	// on the fly, and caching the surfaces makes no sense yet.
	static const Uint8 alpha = 196;
	static const int size = image_fg->w;
	static const int half_size = size / 2;
	static const int quarter_size = size / 4;
	static const int offset = 2;
	static const int new_size = half_size - 2;
	const int zoom = static_cast<int>(size * disp.get_zoom_factor());

	// Blit left side
	image_fg = scale_surface(image_fg, new_size, new_size);
	SDL_Rect rcDestLeft = { offset, quarter_size, 0, 0 };
	SDL_BlitSurface ( image_fg, NULL, image, &rcDestLeft );

	// Blit left side
	image_bg = scale_surface(image_bg, new_size, new_size);
	SDL_Rect rcDestRight = { half_size, quarter_size, 0, 0 };
	SDL_BlitSurface ( image_bg, NULL, image, &rcDestRight );

	//apply mask so the overlay is contained within the mouseover hex
	surface mask(image::get_image("terrain/alphamask.png"));
	image = mask_surface(image, mask);

	// Add the alpha factor and scale the image
	image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);

	// Set as mouseover
	disp.set_mouseover_hex_overlay(image);
}
Example #28
0
void HUD_Lua_Class::start_draw(void)
{
	alephone::Screen *scr = alephone::Screen::instance();
    m_wr = scr->window_rect();
	m_opengl = (get_screen_mode()->acceleration != _no_acceleration);
	m_masking_mode = _mask_disabled;
	
#ifdef HAVE_OPENGL
	if (m_opengl)
	{
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glEnable(GL_TEXTURE_2D);
		glDisable(GL_CULL_FACE);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_ALPHA_TEST);
		glDisable(GL_STENCIL_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDisable(GL_FOG);
        
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
        glTranslatef(m_wr.x, m_wr.y, 0.0);
		
		m_surface = NULL;
	}
	else
#endif
	{
		if (m_surface &&
				(m_surface->w != SDL_GetVideoSurface()->w ||
				 m_surface->h != SDL_GetVideoSurface()->h))
		{
			SDL_FreeSurface(m_surface);
			m_surface = NULL;
		}
		if (!m_surface)
		{
			m_surface = SDL_DisplayFormatAlpha(SDL_GetVideoSurface());
			SDL_SetAlpha(m_surface, SDL_SRCALPHA, 0);
		}
		SDL_SetClipRect(m_surface, NULL);
		SDL_FillRect(m_surface, NULL, SDL_MapRGBA(m_surface->format, 0, 0, 0, 0));
		
		SDL_SetAlpha(SDL_GetVideoSurface(), SDL_SRCALPHA, 0xff);
	}
	
	
	m_drawing = true;
	clear_mask();
}
Example #29
0
SDL_Surface *textlib_get_finalscreen(unsigned int players, const char **names, int *points, 
				     char **primary_weapons, int *primary_weapon_lvls, 
				     char **secondary_weapons, int *secondary_weapon_lvls, 
				     int w, int h){
  SDL_Surface *quickhack = textlib_get_text("foobar", 0, 0, 0);
  SDL_Surface *finalscreen = SDL_CreateRGBSurface(SDL_SWSURFACE,
					 w, h,
					 quickhack->format->BitsPerPixel,
					 quickhack->format->Rmask, quickhack->format->Gmask,
					 quickhack->format->Bmask, quickhack->format->Amask);
  SDL_FillRect(finalscreen, NULL, SDL_MapRGBA(finalscreen->format, 0, 0, 255, 255)); // color surface
  return finalscreen;
}
Uint32 SDLHardwareRenderDevice::MapRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
	Uint32 u_format = SDL_GetWindowPixelFormat(window);
	SDL_PixelFormat* format = SDL_AllocFormat(u_format);

	if (format) {
		Uint32 ret = SDL_MapRGBA(format, r, g, b, a);
		SDL_FreeFormat(format);
		return ret;
	}
	else {
		return 0;
	}
}