示例#1
0
// -----------------------------------------------------------------------------
// drawing - may not be needed after all...
//
void pixel(void *s_in,
	   int x, int y,
	   int r, int g, int b, int a) 
{
    SDL_Renderer* s = (SDL_Renderer*)s_in;
    pixelRGBA(s, x, y, r, g, b, a);
}
void DisplayScreen::display_screen(IntMatrix& screen_matrix, int screen_width, int screen_height) {
    Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

    SDL_Surface* my_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,screen_width,screen_height,32,rmask,gmask,bmask,amask);

    int r, g, b;
    for (int y=0; y<screen_height; ++y) {
        for (int x=0; x<screen_width; ++x) {
            export_screen->get_rgb_from_palette(screen_matrix[y][x], r, g, b);
            pixelRGBA(my_surface,x,y,r,g,b,255);
        }
    }

    SDL_Surface* zoomed = zoomSurface(my_surface,screen->w/(double)screen_width,screen->h/(double)screen_height,0);
    SDL_BlitSurface(zoomed, NULL, screen, NULL);

    SDL_Flip(screen);
    SDL_FreeSurface(my_surface);
    SDL_FreeSurface(zoomed);
    poll(); // Check for quit event
}
示例#3
0
int main(int argc, char **argv)
{
    int HWH = WINDOW_HEIGHT/2;
    int HWW = WINDOW_WIDTH/2;
    int offs = 0;
    int incr = 1;
    int Trippin = 1;
    if (SDL_Init(SDL_INIT_VIDEO))
    {
        printf("you are a horrible person and I hate you\n");
        return 1;
    }
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0, 
            SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
    SDL_WM_SetCaption( WINDOW_TITLE, 0 );
    SDL_Event event;
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
    SDL_ShowCursor(0);

    while (Trippin == 1)
    {
        if (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_KEYDOWN:
                    Trippin=0;
                    break;
                default:
                    break;
            }
        }
        int x, y;
        float r=255, g=0, b=255, a=255, x_xor_y, rx, ry;

        if(offs <= 1)
            incr = 1;
        else if(offs == 2048)
            incr = -1;

        offs += incr;
        for(y = -(HWH); y < HWH; y ++)
        {
            for(x = -(HWW); x < HWW; x ++)
            {
                x_xor_y = x ^ y;
                rx = x+HWW;
                ry = y+HWH;
                r = (x_xor_y * (offs/(ry+1)) + ry) / (y+HWH+1);
                b = (x_xor_y * (offs/(rx+1)) + rx) / (x+HWW+1);
                pixelRGBA(screen, x+HWW, y+HWH, r, g, b, a);
            }
        }
        SDL_Flip(screen);
    }
    SDL_Quit();
    return 0;
}
示例#4
0
void drawpoint(int x1, int y1)
{
	pixelRGBA(screen, x1, y1, foreground_color.r, foreground_color.g, foreground_color.b , 255);
	
	/* save last draw position */
	previous_x = x1;
	previous_y = y1;
	/* SDL_Flip(screen); */
}
示例#5
0
CAMLprim value ml_pixelRGBA(value dst,value x,value y, value col,value alpha)
{
  SDL_Surface *sur= SDL_SURFACE(dst);
  SDL_Color c;
  int r;

  SDLColor_of_value(&c,col);
  r=pixelRGBA(sur,Int_val(x),Int_val(y),c.r,c.g,c.b, Int_val(alpha));

  return Val_bool(r);
}
示例#6
0
bool image_to_sdl(struct image * image)
{
  bool rv;
  SDL_Surface * tmp;

  assert(image->sdl_surface == NULL);
  rv = false;

  tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, image->width, image->height, 32, 0, 0, 0, 0);
  assert(tmp != NULL);
  if(tmp != NULL)
    {
      image->sdl_surface = SDL_ConvertSurface(tmp, gfx_game_screen()->format, 0);
      SDL_FreeSurface(tmp);
      if(image->sdl_surface != NULL)
        {
          rv = true;
          for(int y = 0; y < image->height; y++)
            for(int x = 0; x < image->width; x++)
              if(image->flags & IF_ALPHA)
                pixelRGBA(image->sdl_surface,
                          x, image->height - y - 1,
                          image->data[4 * (x + y * image->width) + 0],
                          image->data[4 * (x + y * image->width) + 1],
                          image->data[4 * (x + y * image->width) + 2],
                          image->data[4 * (x + y * image->width) + 3]);
              else
                pixelRGBA(image->sdl_surface,
                          x, image->height - y - 1,
                          image->data[3 * (x + y * image->width) + 0],
                          image->data[3 * (x + y * image->width) + 1],
                          image->data[3 * (x + y * image->width) + 2],
                          0xff);
        }
    }


  return rv;
}
示例#7
0
文件: draw.c 项目: Eckankar/MosGame
// ML type: surface -> point -> color -> unit
// Draws a pixel on the surface.
EXTERNML value draw_draw_pixel(value wScreen, value wPos, value wColor) {
    SDL_Surface *screen = (SDL_Surface *)Addr_val(wScreen);

    int x = Long_val(Field(wPos, 0)),
        y = Long_val(Field(wPos, 1)),
        colorr = Long_val(Field(wColor, 0)),
        colorg = Long_val(Field(wColor, 1)),
        colorb = Long_val(Field(wColor, 2)),
        colora = Tag_val(wColor) == RGBA ? Long_val(Field(wColor, 3)) : 255;

    pixelRGBA(screen, x, y, colorr, colorg, colorb, colora);

    return Val_unit;
}
示例#8
0
void Punto(int x, int y, unsigned char r, unsigned char g, unsigned char b, GRF_Imagen img)
{
    GRF_Imagen ptr = ((img==0) ? ventana : img);
    pixelRGBA(ptr, x, y, r, g, b, 255);
    if (img==0 && dibujo_activo) SDL_UpdateRect(ptr, x, y, 1, 1);
}
示例#9
0
void SDLDebugDraw::DrawTransform(const b2Transform &xf) {
    b2Vec2 v1 = xf.p;
    v1*= camera;
    
    pixelRGBA(App::get()->ren->renderer,v1.x, v1.y, 255,255,255,255);
}
示例#10
0
文件: gfx.cpp 项目: blaf/ditchers
/**
Sets the value of the given pixel in the given surface.
*/
void Gfx::setPixel(SDL_Surface *surface, int x, int y, int red, int green, int blue, int alpha){
    if (x == surface->w) x -= surface->w;
    if (y == surface->h) y -= surface->h;
    pixelRGBA(surface, x, y, red, green, blue, alpha);
}
示例#11
0
int copy_surface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
{
    Uint32 pixel;
    Uint8 r, g, b;
    Sint16 src_x, src_y, dst_x, dst_y;
    Sint16 srcrect_x, srcrect_y, srcrect_w, srcrect_h;
    Sint16 dstrect_x, dstrect_y;

    if (srcrect == NULL)
    {
        srcrect_x = 0;
        srcrect_y = 0;
        srcrect_w = src->w;
        srcrect_h = src->h;
    }
    else
    {
        srcrect_x = srcrect->x;
        srcrect_y = srcrect->y;
        srcrect_w = srcrect->w;
        srcrect_h = srcrect->h;
    }

    if (dstrect == NULL)
    {
        dstrect_x = 0;
        dstrect_y = 0;
    }
    else
    {
        dstrect_x = dstrect->x;
        dstrect_y = dstrect->y;
    }

    dst_y = dstrect_y;

    for (src_y = srcrect_y; src_y < srcrect_y + srcrect_h; src_y++)
    {
        dst_x = dstrect_x;

        for (src_x = srcrect_x; src_x < srcrect_x + srcrect_w; src_x++)
        {
            if (SDL_LockSurface (src) < 0)
            {
                printf ("copy_surface: can't lock source surface!\n");
                return (-1);
            }

            pixel = getpixel (src, src_x, src_y);
            SDL_UnlockSurface (src);
            SDL_GetRGB (pixel, src->format, &r, &g, &b);

            pixelRGBA (dst, dst_x, dst_y, r, g, b, 255);

            dst_x++;
        }

        dst_y++;
    }
    return (0);
}
示例#12
0
void Draw (SDL_Surface *screen, char *bmpfile)
{
	char messageText[128];
	Uint32 rmask, gmask, bmask, amask;
	SDL_Surface *picture;
	SDL_Surface *mapped_picture;
	SDL_Surface *rotozoom_picture;
	SDL_PixelFormat *pixelFormat;
	Uint8 *grayscale, *map, *curmap;
	double *unrelaxed, *relaxed, *currelax;
	int mapsize, relaxsize;
	int rowskip;
	char *pixel;
	Uint32 p;
	int x, y;
	Uint8 r, g, b, a;
	double dy;
	double t, s;
	int i;
	double c1, c2, c3, c4, ca;
	Uint8 lookupTable[256];
	double zw, zh, zf;

	/* SDL interprets each pixel as a 32-bit number, so our masks must depend
	on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	rmask = 0xff000000;
	gmask = 0x00ff0000;
	bmask = 0x0000ff00;
	amask = 0x000000ff;
#else
	rmask = 0x000000ff;
	gmask = 0x0000ff00;
	bmask = 0x00ff0000;
	amask = 0xff000000;
#endif

	/* Load the image into a surface */
	printf("Loading picture: %s\n", bmpfile);
	picture = SDL_LoadBMP(bmpfile);
	if ( picture == NULL ) {
		fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError());
		return;
	}

	/* Convert image to a brightness map */
	printf("Allocating workbuffers\n");
	mapsize = picture->w * picture->h;
	relaxsize = mapsize * sizeof(double);
	grayscale = (Uint8 *)malloc(mapsize);
	map = (Uint8 *)malloc(mapsize);
	unrelaxed = (double *)malloc(relaxsize);
	relaxed = (double *)malloc(relaxsize);
	if ((grayscale == NULL) || (map == NULL) || (unrelaxed == NULL) || (relaxed == NULL))
	{
		fprintf(stderr, "Out of memory\n");
		return;
	}
	memset(grayscale, 0, mapsize);
	memset(map, 0, mapsize);
	memset(unrelaxed, 0, relaxsize);
	memset(relaxed, 0, relaxsize);

	printf("Converting image to brightness map\n");
	pixel = picture->pixels;
	pixelFormat = picture->format;
	rowskip = (picture->pitch - picture->w * picture->format->BytesPerPixel);
	curmap = grayscale;
	for (y=0; y < picture->h; y++) {
		for (x=0; x < picture->w; x++) {
			// Get RGB
			p = getPixel(picture, x, y);
			SDL_GetRGBA(p, pixelFormat, &r, &g, &b, &a);

			// Calculate luminance (Y = 0.3R + 0.59G + 0.11B;)
			dy  = (0.30 * r) + (0.59 * g) + (0.11 * b);
			if (dy<0.0) {
				dy=0.0;
			} else if (dy>255.0) {
				dy=255.0;
			}
			*curmap = (Uint8)dy;

			// Next pixel
			pixel += picture->format->BytesPerPixel;
			curmap++;
		}

		// Next row
		pixel += rowskip;
	}

	/* --- Prepare relaxation loop --- */

	/* Binarize luminance map */
	SDL_imageFilterBinarizeUsingThreshold(grayscale, map, mapsize, threshold);

	/* Create cos^5 based lookup table */
	t = 0.0;
	for (i = 0; i < 256; i++)
	{
		s = 1.0 - 0.5 * (1.0 + cos(t));
		s = 255.0 * s * s * s * s * s;
		lookupTable[i] = (Uint8)s;
		t += ((double)contours*2.0*3.141592653589/128.0);
	}

	/* Create new surface for relaxed image */
	mapped_picture = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32,
		rmask, gmask, bmask, amask);
	if (mapped_picture == NULL) {
		fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
		return;
	}

	/* Apply relaxation algorithm */
	printf("Applying Laplacian relaxation: %i iterations\n", iterations);
	// Iterate to relax
	for (i = 0; i <= iterations; i++)
	{
		// Backup original
		memcpy(unrelaxed, relaxed, relaxsize);
		// Average into relaxed
		for (x=0; x < picture->w; x++) {		
			for (y=0; y < picture->h; y++) {
				// up
				c1 = GetPotential(map, grayscale, unrelaxed, x, y-1, picture->w, picture->h);
				// down
				c2 = GetPotential(map, grayscale, unrelaxed, x, y+1, picture->w, picture->h);
				// left
				c3 = GetPotential(map, grayscale, unrelaxed, x-1, y, picture->w, picture->h);
				// right
				c4 = GetPotential(map, grayscale, unrelaxed, x+1, y, picture->w, picture->h);
				// average and store
				ca = ((c1 + c2 + c3 + c4)/4.0);
				relaxed[x+y*picture->w] = ca;
			}
		}

		// Draw only sometimes
		if (((i % 10)==0) || (i==iterations)) {

			/* --- Create image with contour map --- */

			/* Fill output surface via colormap */
			currelax = relaxed;
			for (y=0; y<mapped_picture->h; y++) {
				for (x=0; x<mapped_picture->w; x++) {
					if (map[x+y*picture->w]!=0) {
						r = g = b = grayscale[x+y*picture->w];
					} else {
						r = g = b = lookupTable[(Uint8)*currelax];
					}
					pixelRGBA(mapped_picture, x, y, r, g, b, 255);
					currelax++;
				}
			}

			/* --- Scale and draw to screen --- */

			/* Scale to screen size */
			zw = (double)screen->w/(double)mapped_picture->w; 
			zh = (double)screen->h/(double)mapped_picture->h; 
			zf = (zw < zh) ? zw : zh;
			if ((rotozoom_picture=zoomSurface(mapped_picture, zf, zf, 1))==NULL) {
				fprintf(stderr, "Rotozoom failed: %s\n", SDL_GetError());
				return;
			}	

			/* Draw surface to screen */
			if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, NULL) < 0 ) {
				fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
				return;
			}
			SDL_FreeSurface(rotozoom_picture);

			/* Info */
			if (i != iterations) {
				sprintf(messageText,"%i", i);
				stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255);
			}

			/* Display by flipping screens */
			SDL_Flip(screen);
		}

		/* Maybe quit */
		HandleEvent();
	}

	/* Save final picture */
	if (SDL_SaveBMP(mapped_picture, "result.bmp") <0) {
		fprintf(stderr, "Save BMP failed: %s\n", SDL_GetError());
		return;
	}
	free(map);
	free(grayscale);
	free(unrelaxed);
	free(relaxed);
	SDL_FreeSurface(picture);
	SDL_FreeSurface(mapped_picture);

	return;
}
示例#13
0
int BEE::draw_point(int x, int y, bool is_hud) {
	if (!is_hud) {
		convert_view_coords(x, y);
	}
	return pixelRGBA(renderer, x, y, color->r, color->g, color->b, color->a);
}
示例#14
0
void C_BaseParticles::Render()
{
	if(m_life > 0)
		pixelRGBA(screen, m_X - Camera.Get_XYWH()->x, m_Y - Camera.Get_XYWH()->y, m_red, m_green, m_blue, m_alpha);
}
示例#15
0
 void DrawingArea::DrawPixel(const int x, const int y, const SSDL::Color Color) {
     pixelRGBA(this->surface, x, y, Color.GetRed(), Color.GetGreen(), Color.GetBlue(), Color.GetAlpha());
 }
示例#16
0
/* Calls to commands created via [sdl.surface] are implemented by this
 * C command. */
static int JimSdlHandlerCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    JimSdlSurface *jss = Jim_CmdPrivData(interp);
    int option;
    static const char * const options[] = {
        "free", "flip", "pixel", "rectangle", "box", "line", "aaline",
        "circle", "aacircle", "fcircle", NULL
    };
    enum
    { OPT_FREE, OPT_FLIP, OPT_PIXEL, OPT_RECTANGLE, OPT_BOX, OPT_LINE,
        OPT_AALINE, OPT_CIRCLE, OPT_AACIRCLE, OPT_FCIRCLE
    };

    if (argc < 2) {
        Jim_WrongNumArgs(interp, 1, argv, "method ?args ...?");
        return JIM_ERR;
    }
    if (Jim_GetEnum(interp, argv[1], options, &option, "SDL surface method", JIM_ERRMSG) != JIM_OK)
        return JIM_ERR;
    if (option == OPT_PIXEL) {
        /* PIXEL */
        long x, y, red, green, blue, alpha = 255;

        if (argc != 7 && argc != 8) {
            Jim_WrongNumArgs(interp, 2, argv, "x y red green blue ?alpha?");
            return JIM_ERR;
        }
        if (Jim_GetLong(interp, argv[2], &x) != JIM_OK ||
            Jim_GetLong(interp, argv[3], &y) != JIM_OK ||
            Jim_GetLong(interp, argv[4], &red) != JIM_OK ||
            Jim_GetLong(interp, argv[5], &green) != JIM_OK ||
            Jim_GetLong(interp, argv[6], &blue) != JIM_OK) {
            return JIM_ERR;
        }
        if (argc == 8 && Jim_GetLong(interp, argv[7], &alpha) != JIM_OK)
            return JIM_ERR;
        pixelRGBA(jss->screen, x, y, red, green, blue, alpha);
        return JIM_OK;
    }
    else if (option == OPT_RECTANGLE || option == OPT_BOX ||
        option == OPT_LINE || option == OPT_AALINE) {
        /* RECTANGLE, BOX, LINE, AALINE */
        long x1, y1, x2, y2, red, green, blue, alpha = 255;

        if (argc != 9 && argc != 10) {
            Jim_WrongNumArgs(interp, 2, argv, "x y red green blue ?alpha?");
            return JIM_ERR;
        }
        if (Jim_GetLong(interp, argv[2], &x1) != JIM_OK ||
            Jim_GetLong(interp, argv[3], &y1) != JIM_OK ||
            Jim_GetLong(interp, argv[4], &x2) != JIM_OK ||
            Jim_GetLong(interp, argv[5], &y2) != JIM_OK ||
            Jim_GetLong(interp, argv[6], &red) != JIM_OK ||
            Jim_GetLong(interp, argv[7], &green) != JIM_OK ||
            Jim_GetLong(interp, argv[8], &blue) != JIM_OK) {
            return JIM_ERR;
        }
        if (argc == 10 && Jim_GetLong(interp, argv[9], &alpha) != JIM_OK)
            return JIM_ERR;
        switch (option) {
            case OPT_RECTANGLE:
                rectangleRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
            case OPT_BOX:
                boxRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
            case OPT_LINE:
                lineRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
            case OPT_AALINE:
                aalineRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
        }
        return JIM_OK;
    }
    else if (option == OPT_CIRCLE || option == OPT_AACIRCLE || option == OPT_FCIRCLE) {
        /* CIRCLE, AACIRCLE, FCIRCLE */
        long x, y, radius, red, green, blue, alpha = 255;

        if (argc != 8 && argc != 9) {
            Jim_WrongNumArgs(interp, 2, argv, "x y radius red green blue ?alpha?");
            return JIM_ERR;
        }
        if (Jim_GetLong(interp, argv[2], &x) != JIM_OK ||
            Jim_GetLong(interp, argv[3], &y) != JIM_OK ||
            Jim_GetLong(interp, argv[4], &radius) != JIM_OK ||
            Jim_GetLong(interp, argv[5], &red) != JIM_OK ||
            Jim_GetLong(interp, argv[6], &green) != JIM_OK ||
            Jim_GetLong(interp, argv[7], &blue) != JIM_OK) {
            return JIM_ERR;
        }
        if (argc == 9 && Jim_GetLong(interp, argv[8], &alpha) != JIM_OK)
            return JIM_ERR;
        switch (option) {
            case OPT_CIRCLE:
                circleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
                break;
            case OPT_AACIRCLE:
                aacircleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
                break;
            case OPT_FCIRCLE:
                filledCircleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
                break;
        }
        return JIM_OK;
    }
    else if (option == OPT_FREE) {
        /* FREE */
        if (argc != 2) {
            Jim_WrongNumArgs(interp, 2, argv, "");
            return JIM_ERR;
        }
        Jim_DeleteCommand(interp, Jim_String(argv[0]));
        return JIM_OK;
    }
    else if (option == OPT_FLIP) {
        /* FLIP */
        if (argc != 2) {
            Jim_WrongNumArgs(interp, 2, argv, "");
            return JIM_ERR;
        }
        SDL_Flip(jss->screen);
        return JIM_OK;
    }
    return JIM_OK;
}
示例#17
0
OutVideo& operator<<(OutVideo& screen, const MyVector oth){
	if(pixelRGBA(screen,oth.x,oth.y,oth.mColor.c_red,oth.mColor.c_green,oth.mColor.c_blue,255)!=0){
		//TODO: fare errore!
	}
	return screen;
}