Esempio n. 1
0
BOOL GUIAPI SetColorfulPalette (HDC hdc)
{
    PDC pdc;
    GAL_Color pal[256];

    pdc = dc_HDC2PDC (hdc);

    if (pdc->surface->format->BitsPerPixel == 8) {
        GAL_DitherColors (pal, 8);
        GAL_SetColors (pdc->surface, pal, 0, 256);
    }

    return FALSE;
}
Esempio n. 2
0
int minigl_MakeCurrent(GAL_Surface *surface, minigl_Context *ctx, unsigned short client_width, unsigned short client_height)
{
	int	mode;
	int	xsize;
	int	ysize;
	int	n_colors = 0;
	ZBuffer *zb;

	if( ctx->gl_context == NULL )
	{
		// create the TinyGL context

		xsize = client_width;
		ysize = client_height;

		// we ensure that xsize and ysize are multiples of 2 for the zbuffer.
		xsize &= ~3;
		ysize &= ~3;

		switch( surface->format->BitsPerPixel )
		{
		case  8:
			{
				ctx->indexes = (unsigned char *)malloc(ZB_NB_COLORS);
				if (ctx->indexes == NULL)
					return 0;
				for(mode=0;mode<ZB_NB_COLORS;mode++)
					ctx->indexes[mode]=mode;

				ctx->palette = (unsigned int *)calloc (ZB_NB_COLORS, sizeof(int));
				if (ctx->palette == NULL)
				{
					free(ctx->indexes);
					ctx->indexes = NULL;
					return 0;
				}

				ctx->pitch = surface->pitch * 2;
				n_colors = ZB_NB_COLORS;
				mode = ZB_MODE_INDEX;

				ctx->pDitherBuf = (unsigned char *)malloc(xsize * ysize);
			}
			break;

		case 16:
			{
				ctx->pitch = surface->pitch;
				mode = ZB_MODE_5R6G5B;
			}
			break;

		case 24:
			{
				ctx->pitch = ( surface->pitch * 2 ) / 3;
				mode = ZB_MODE_RGB24;
			}
			break;

		case 32:
			{
				ctx->pitch = surface->pitch / 2;
				mode = ZB_MODE_RGBA;
			}
			break;

		default:
			return 0;
		}

		zb = ZB_open( xsize, ysize, mode, n_colors, (unsigned char*)ctx->indexes, (int *)ctx->palette, NULL);

		if( zb == NULL ){
//			fprintf( stderr, "Error while initializing Z buffer\n" );
			if (ctx->indexes != NULL )
			{
				free(ctx->indexes);
				ctx->indexes = NULL;
			}
			if (ctx->palette != NULL )
			{
				free(ctx->palette);
				ctx->palette = NULL;
			}
			return 0;
		}

		if (ctx->palette != NULL)
		{
			GAL_Color *pal=(GAL_Color *)calloc(ZB_NB_COLORS,sizeof(GAL_Color));
			if (pal!=NULL)
			{
				for (mode=0; mode<ZB_NB_COLORS; mode++)
				{
					pal[mode].r = (ctx->palette[mode]>>16) & 0xFF;
					pal[mode].g = (ctx->palette[mode]>>8) & 0xFF;
					pal[mode].b = (ctx->palette[mode]) & 0xFF;
				}

				GAL_SetColors(surface, pal, 0, ZB_NB_COLORS);
				free(pal);
			}
		}