void textureLoad(Texture *tex)
{	bitmap *bm;
	char flname[1024];

//	tex->flags &= texture_clearmask;
//	tex->flags |= flags;

//	texturelog->log("Attempting to load texture %s",tex->name);

	if (fileExists(tex->name))										// Check to see if the path + filename is valid ...
		txtcpy(flname, sizeof(flname), tex->name);					// if so, load that
	else
		fileFindInPath(flname, sizeof(flname), tex->name, texpath);	// Find the texture with our texture path

	if (!flname[0])													// nothing found ... fail
	{	texturelog->log("*** %s *** Missing texture.  Looked in %s",tex->name,texpath);
		if (!bm_MissingTexture)
		{	bm_MissingTexture = newbitmap("Missing Texture Standin",1,1,bitmap_ARGB32);
			*(uint32 *)(bm_MissingTexture->pixel) = 0xFFFF00FF;		// Purple
		}
		textureFromBitmap(bm_MissingTexture, tex);
		estimatedtexmemused += 4;
	}	else
	{	bm = newbitmap(flname,0);
		textureFromBitmap(bm, tex);
		deleteBitmap(bm);
	}
	if (tex->oemdata)
		texturelog->log("Create %i: %s",tex->texmemused/1024,flname);
}
Exemplo n.º 2
0
static void draw_picture(control obj, rect r)
{
	image   img;
	bitmap	store = NULL;
	rgb     old = currentcolour();

	img = obj->img;
	if (has_transparent_pixels(img)) {
		store = newbitmap(r.width, r.height, 0);
		drawto(store);
		setcolour(getbackground(obj));
		fillrect(r);
	}

	if (img) {
		/* Draw the button image. */
		if (ischecked(obj))
			drawdarker(img, r, getrect(img));
		else if (isenabled(obj))
			drawimage(img, r, getrect(img));
		else
			drawimage(img, r, getrect(img)); /* never grey */
	}

	if (store != NULL) {
		drawto(obj);
		copyrect(store, pt(0,0), getrect(store));
		del(store);
	}

	setcolour(old);
}
Texture *newTextureFromFile(const char *texname,uintf flags)
{	// Search the current texture directory to locate a suitable texture file
	bitmap *bm;
	char flname[1024];
	if (!texname) return NULL;
	if (!texname[0]) return NULL;

	// Look for an already loaded texture with the same name
	fileNameInfo(texname);
	tprintf(flname,sizeof(flname),"%s.%s",fileactualname,fileextension);
	Texture *tex = usedTexture;
	while (tex)
	{	if (txticmp(flname,tex->name)==0)
		{	// Texture already loaded
			tex->refcount++;
			return tex;
		}
		tex = tex->next;
	}

	// Allocate a new texture cell
	tex = newTexture(flname, 0, 0);	// ### This forces the texture to be 2D!!!
	tex->flags &= texture_clearmask;
	tex->flags |= flags;

	if (fileExists(texname))										// Check to see if the path + filename is valid ...
		txtcpy(flname, sizeof(flname), texname);					// if so, load that
	else
		fileFindInPath(flname, sizeof(flname), tex->name, texpath);	// Find the texture with our texture path

	if (!flname[0])													// nothing found ... fail
	{	texturelog->log("*** %s *** Missing texture.  Looked in %s",tex->name,texpath);
		if (!bm_MissingTexture)
		{	bm_MissingTexture = newbitmap("Missing Texture Standin",1,1,bitmap_ARGB32);
			*(uint32 *)(bm_MissingTexture->pixel) = 0xFFFF00FF;		// Purple
		}
		textureFromBitmap(bm_MissingTexture, tex);
		estimatedtexmemused += 4;
	}	else
	{	bm = newbitmap(flname,0);
		textureFromBitmap(bm, tex);
		deleteBitmap(bm);
	}
	if (tex->oemdata)
		texturelog->log("Create %i: %s",tex->texmemused/1024,flname);
	return tex;
}
Exemplo n.º 4
0
static void draw_image_button(button obj, rect r)
{
	image   img;
	bitmap	store = NULL;
	rect    ir;
	rgb     up, down;
	rgb     old = currentcolour();

	img = obj->img;
	if (has_transparent_pixels(img)) {
		store = newbitmap(r.width, r.height, 0);
		drawto(store);
		setcolour(getbackground(obj));
		fillrect(r);
	}

	if (img) {
		ir = insetr(r,2);
		if (ishighlighted(obj)) /* button is pressed */
			ir.x += 1, ir.y += 1;

		/* Draw the button image. */
		if (ischecked(obj))
			drawdarker(img, ir, getrect(img));
		else if (isenabled(obj))
			drawimage(img, ir, getrect(img));
		else
			drawgreyscale(img, ir, getrect(img));

		if (ishighlighted(obj)) { /* fill the gap */
			ir.x -= 1, ir.y -= 1;
			setcolour(getbackground(obj));
			drawline(topleft(ir),topright(ir));
			drawline(topleft(ir),bottomleft(ir));
		}
	}

	/* Draw button border. */
	setcolour(getforeground(obj));
	setlinewidth(1);
	drawrect(r);

	/* Draw button shadow. */
	up = White, down = Grey;
	if (ishighlighted(obj))
		up = Grey, down = LightGrey;
	draw_shadow(insetr(r,1), up, down, 1);

	if (store != NULL) {
		drawto(obj);
		copyrect(store, pt(0,0), getrect(store));
		del(store);
	}

	setcolour(old);
}
void initGraphics(uintf graphicsMode,uintf width, uintf height, uintf bpp)
{	if (shutDownVideo) shutDownVideo();

	// Perform standard 3D world inits
	width = width&0xfffffffc;
	screenWidth	 = width;
	screenHeight = height;

	switch (graphicsMode & 0x0000000f)
	{	case gfxmode_GUI:	// Deliberate fallthrough to 2D mode for now

		case gfxmode_2D:
		{	init2Ddriver(width,height,bpp);
			fc_screenBitmap = getScreenBitmap();
			create2DRenderTarget(&rt2d_ScreenDisplay,fc_screenBitmap);
			select2DRenderTarget(&rt2d_ScreenDisplay);
			break;
		}

		case gfxmode_3D:
		{	// This is the currently supported mode
			fc_screenBitmap = newbitmap("2D RT Safety Net",1,1,bitmap_x8r8g8b8 | bitmap_RenderTarget);
			create2DRenderTarget(&rt2d_ScreenDisplay,fc_screenBitmap);
			select2DRenderTarget(&rt2d_ScreenDisplay);
			init3Ddriver(screenWidth,screenHeight,bpp);
			setcammatrix();
			_fclighting = initlighting();
			_fctexture = inittexture();
			fc_initShaders();
			initmaterial();
			initbillboards();
			break;
		}
		default:
		{	msg("Error","Unrecognised Graphics mode in call to initGraphics.\nDid you use the old method of requesting a render core?");
			break;
		}
	}

	getvideoinfo(&videoinfo,sizeof(videoinfo));
	fcapplaunched = 1;
}
Texture *newNormalizeCubeMap(int size, float intensity, const char *name)
{	// Create a new Normalizing Cube Map (commonly used in Normal Mapping)
	// Size = Number of pixels in width, height, and depth
	// Intensity = Intensity of lighting.  Ranges from 0 (very little lighting) to 1 (heavy specular effect)
	// Name = the name you want to call this texture (optional)
	Texture *tex = newTexture("Unnamed Cubemap", size, texture_cubemap | texture_manualmip);
	if (name) txtcpy(tex->name,maxtexnamesize,name);

	float vector[3] = {0,0,0};
	intf side, x, y, mip;
	byte *pixels;
	intensity *= 127;

	bitmap *bm = newbitmap("Normalize CubeMap", size, size,bitmap_RGB_32bit);
	pixels = (byte *)bm->pixel;

	mip = 0;
	while (size>0)
	{	float oofsize = 1.0f / (float)size;
		bm->width = size;
		bm->height = size;
		for (side = 0; side < 6; side++)
		{	for (y = 0; y < size; y++)
			{	for (x = 0; x < size; x++)
				{	float s, t, sc, tc, mag;

					s = ((float)x + 0.5f) * oofsize; // / (float)size;
					t = ((float)y + 0.5f) * oofsize; // / (float)size;
					sc = s*2.0f - 1.0f;
					tc = t*2.0f - 1.0f;

					switch (side)
					{	case 0:
							vector[0] = 1.0;
							vector[1] = -tc;
							vector[2] = -sc;
							break;
						case 1:
							vector[0] = -1.0;
							vector[1] = -tc;
							vector[2] = sc;
							break;
						case 2:
							vector[0] = sc;
							vector[1] = 1.0;
							vector[2] = tc;
							break;
						case 3:
							vector[0] = sc;
							vector[1] = -1.0;
							vector[2] = -tc;
							break;
						case 4:
							vector[0] = sc;
							vector[1] = -tc;
							vector[2] = 1.0;
							break;
						case 5:
							vector[0] = -sc;
							vector[1] = -tc;
							vector[2] = -1.0;
							break;
					} // switch size

					mag = 1.0f/(float)sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
					vector[0] *= mag;
					vector[1] *= mag;
					vector[2] *= mag;
					float alpha = intensity * vector[2] * 2;
					if (alpha<0) alpha = 0;
					pixels[4*(y*size+x) + 0] = (byte)alpha;//(128 + (byte)(intensity*vector[2]));	// A	(A taken from Z)
					pixels[4*(y*size+x) + 1] = (128 + (byte)(intensity*vector[0]));	// R
					pixels[4*(y*size+x) + 2] = (128 + (byte)(intensity*vector[1]));	// G
					pixels[4*(y*size+x) + 3] = (128 + (byte)(intensity*vector[2]));	// B
				} // for X
			}	// for Y
			downloadcubemapface(tex, side, bm, mip);
		}	// for side
		size >>= 1;
		mip++;
	}
	tex->mapping = texmapping_default | texmapping_clampUV;
	fcfree(bm);
	return tex;
}
// Internal function - Called to load up a texture map - file is known to exist
Texture *textureFromBitmap(bitmap *loadbm, Texture *tex)
{	bitmap *swizzleBm, *scaleBm, *resizeCanvasSrc;
	bool mustSwizzle = false;
	bool mustScale = false;

	// Step 1: Check for a need to swizzle (if the video card doesn't support this texture mode)
	uintf dataType = loadbm->flags & (bitmap_DataTypeMask | bitmap_DataInfoMask);
	// ### This code is not yet complete, must leave this block with 'swizzleBM' pointing to swizzled bitmap data

	// If Video card only handles 'Power-of-2' texture dimensions
	bool resizeCanvas=false;
	// if (GLESWarnings) //!(videoFeatures & videodriver_nonP2Tex))
	{	uintf newCanvasWidth = loadbm->width;
		uintf newCanvasHeight = loadbm->height;

		if (!isPow2(loadbm->width))
		{	resizeCanvas=true;
			newCanvasWidth=nextPow2(loadbm->width);
		}
		if (!isPow2(loadbm->height))
		{	resizeCanvas=true;
			newCanvasHeight=nextPow2(loadbm->height);
		}
		if (resizeCanvas)
		{	resizeCanvasSrc = loadbm;
			loadbm = newbitmap("resizeCanvasP2Tex",newCanvasWidth,newCanvasHeight,bitmap_ARGB32);
			uintf x,y;
			uint32 *src32 = (uint32 *)resizeCanvasSrc->pixel;
			uint32 *dst32 = (uint32 *)loadbm->pixel;
			for (y=0; y<resizeCanvasSrc->height; y++)
			{	uint32 *src = &src32[y*(resizeCanvasSrc->width)];
				uint32 *dst = &dst32[y*newCanvasWidth];
				for (x=0; x<resizeCanvasSrc->width; x++)
					*dst++ = *src++;
				for (;x<newCanvasWidth; x++)
					*dst++ = 0;
			}
			for (;y<newCanvasHeight; y++)
			{	uint32 *dst = &dst32[y*newCanvasWidth];
				for (x=0; x<newCanvasWidth; x++)
					*dst++=0;
			}
		}

/*		// Work out X scale
		uintf size = 1;
		while (size<=maxtexwidth)
		{	if (newx<=size) break;
			size <<=1;
		}
		if (size>maxtexwidth) size = maxtexwidth;
		newx = size;

		// Work out Y scale
		size = 1;
		while (size<=maxtexheight)
		{	if (newy<=size) break;
			size <<=1;
		}
		if (size>maxtexheight) size = maxtexheight;
		newy = size;
*/
	}

	// Step 2: Check if we need to resize - this may change swizzle mode
	uintf newx = loadbm->width;
	uintf newy = loadbm->height;
	if (newx>maxtexwidth)
		newx = maxtexwidth;
	if (newy>maxtexheight)
		newy = maxtexheight;

	if (newx!=loadbm->width || newy!=loadbm->height)
	{	dataType = bitmap_DataTypeRGB | bitmap_RGB_32bit;
		mustSwizzle = true;
		mustScale = true;
	}

	if (mustSwizzle)
	{	dataType |= loadbm->flags & bitmap_AlphaMask;
		swizzleBm = SwizzleBitmap(loadbm, dataType);
	}	else
		swizzleBm = loadbm;

	if (mustScale)
	{	// Bitmap needs to be resized before hardware will accept it
		scaleBm = scalebitmap(swizzleBm,newx,newy);
	}	else
		scaleBm = swizzleBm;

	// If we don't have a texture provided, create a new one
	if (!tex)
		tex = newTexture(NULL, 0, 0);
	downloadbitmaptex(tex, scaleBm, 0);
	estimatedtexmemused += tex->texmemused;
	if (mustScale)
		deleteBitmap(scaleBm);
	if (mustSwizzle)
		deleteBitmap(swizzleBm);
	if (resizeCanvas)
	{	deleteBitmap(loadbm);
		loadbm = resizeCanvasSrc;
		tex->flags |= texture_canvasSize;
		tex->UVscale.x = (float)loadbm->width / (float)tex->width;
		tex->UVscale.y = (float)loadbm->height/ (float)tex->height;
	}
	return tex;
}
Exemplo n.º 8
0
Arquivo: pager.c Projeto: edzer/cxxr
static pager pagercreate(void)
{
    ConsoleData p;
    int w, h, i, x, y, w0, h0;
    pager c;
    menuitem m;

    p = newconsoledata((consolefn) ? consolefn : FixedFont,
		       pagerrow, pagercol, 0, 0,
		       guiColors,
		       PAGER, 0, 0);
    if (!p) return NULL;

/*    if (ismdi()) {
      x = y = w = h = 0;
      }
      else {
      w = WIDTH ;
      h = HEIGHT;
      x = (devicewidth(NULL) - w) / 2;
      y = (deviceheight(NULL) - h) / 2 ;
      } */
    w = WIDTH ;
    h = HEIGHT;
    /* centre a single pager, randomly place each of multiple pagers */
#ifdef USE_MDI
    if(ismdi()) {
	RECT *pR = RgetMDIsize();
	w0 = pR->right;
	h0 = pR->bottom;
    } else {
#endif
	w0 = devicewidth(NULL);
	h0 = deviceheight(NULL);
#ifdef USE_MDI
    }
#endif
    x = (w0 - w) / 2; x = x > 20 ? x:20;
    y = (h0 - h) / 2; y = y > 20 ? y:20;
    if(pagerMultiple) {
#ifdef Win32
	DWORD rand = GetTickCount();
#else
	int rand = 0;
#endif
	int w0 = 0.4*x, h0 = 0.4*y;
	w0 = w0 > 20 ? w0 : 20;
	h0 = h0 > 20 ? h0 : 20;
	x += (rand % w0) - w0/2;
	y += ((rand/w0) % h0) - h0/2;
    }
    c = (pager) newwindow("PAGER", rect(x, y, w, h),
			  Document | StandardWindow | Menubar |
			  VScrollbar | HScrollbar | TrackMouse);
    if (!c) {
	freeConsoleData(p);
	return NULL;
    }
    setdata(c, p);
    if(h == 0) HEIGHT = getheight(c);
    if(w == 0) WIDTH  = getwidth(c);
    COLS = WIDTH / FW - 1;
    ROWS = HEIGHT / FH - 1;
    BORDERX = (WIDTH - COLS*FW) / 2;
    BORDERY = (HEIGHT - ROWS*FH) / 2;
    gsetcursor(c, ArrowCursor);
    gchangescrollbar(c, VWINSB, 0, 0, ROWS, 0);
    gchangescrollbar(c, HWINSB, 0, COLS-1, COLS, 1);
    setbackground(c, guiColors[pagerbg]);
#ifdef USE_MDI
    if (ismdi()) {
	int btsize = 24;
	rect r = rect(2, 2, btsize, btsize);
	control tb, bt;
	addto(c);
	MCHECK(tb = newtoolbar(btsize + 4));
	gsetcursor(tb, ArrowCursor);
	addto(tb);
	MCHECK(bt = newtoolbutton(open_image, r, menueditoropen));
	MCHECK(addtooltip(bt, G_("Open script")));
	gsetcursor(bt, ArrowCursor);
	/* wants NULL as data, not the pager */
	r.x += (btsize + 6) ;
	MCHECK(bt = newtoolbutton(copy1_image, r, pagerpaste));
	MCHECK(addtooltip(bt, G_("Paste to console")));
	gsetcursor(bt, ArrowCursor);
	setdata(bt, (void *) c);
	r.x += (btsize + 6) ;
	MCHECK(bt = newtoolbutton(copy1_image, r, pagerpastecmds));
	MCHECK(addtooltip(bt, G_("Paste commands to console")));
	gsetcursor(bt, ArrowCursor);
	setdata(bt, (void *) c);
	r.x += (btsize + 6) ;
	MCHECK(bt = newtoolbutton(print_image, r, pagerprint));
	MCHECK(addtooltip(bt, G_("Print")));
	gsetcursor(bt, ArrowCursor);
	setdata(bt, (void *) c);
	r.x += (btsize + 6) ;
	MCHECK(bt = newtoolbutton(console_image, r, pagerconsole));
	MCHECK(addtooltip(bt, G_("Return focus to Console")));
	gsetcursor(bt, ArrowCursor);
	setdata(bt, (void *) c);
    }
#endif
    addto(c);
    MCHECK(m = gpopup(pagermenuact, PagerPopup));
    setdata(m, c);
    setdata(p->mpopcopy = PagerPopup[0].m, c);
    setdata(p->mpoppaste = PagerPopup[1].m, c);
    setdata(p->mpoppastecmds = PagerPopup[2].m, c);
    setdata(PagerPopup[3].m, c);
    setdata(PagerPopup[5].m, c);
    setdata(PagerPopup[7].m, c);
    MCHECK(m = newmenubar(pagermenuact));
    setdata(m, c);
    MCHECK(newmenu(G_("File")));
    MCHECK(m = newmenuitem(G_("New script"), 'N', menueditornew));
    MCHECK(m = newmenuitem(G_("Open script..."), 'O', menueditoropen));
    MCHECK(m = newmenuitem(G_("Print..."), 'P', pagerprint));
    setdata(m, c);
    MCHECK(m = newmenuitem(G_("Save to File..."), 'S', pagersavefile));
    setdata(m, c);
    MCHECK(m = newmenuitem("-", 0, NULL));
    MCHECK(m = newmenuitem(G_("Close"), 0, pagerclose));
    setdata(m, c);
    MCHECK(newmenu(G_("Edit")));
    MCHECK(p->mcopy = newmenuitem(G_("Copy"), 'C', pagercopy));
    setdata(p->mcopy, c);
    MCHECK(p->mpaste = newmenuitem(G_("Paste to console"), 'V', pagerpaste));
    setdata(p->mpaste, c);
    MCHECK(p->mpastecmds = newmenuitem(G_("Paste commands to console"), 0, pagerpastecmds));
    setdata(p->mpastecmds, c);
    MCHECK(m = newmenuitem(G_("Select all"), 'A', pagerselectall));
    setdata(m, c);
    if (!pagerMultiple) {
	MCHECK(newmenu(G_("View")));
	for (i = 0; i < PAGERMAXKEPT; i++) {
	    snprintf(pagerTitles[i], PAGERMAXTITLE+8, "&%c.  ", 'A' + i);
	    MCHECK(pagerMenus[i] = newmenuitem(&pagerTitles[i][1], 0,
					       pagerchangeview));
	    setvalue(pagerMenus[i], i);
	}
    }
#ifdef USE_MDI
    if (ismdi()) newmdimenu();
    if (ismdi() && !(RguiMDI & RW_TOOLBAR)) toolbar_hide();
#endif
    MCHECK(BM = newbitmap(WIDTH, HEIGHT, 2));
    setdata(c, p);
    sethit(c, console_sbf);
    setresize(c, consoleresize);
    setredraw(c, drawconsole);
    setdel(c, delpager);
    setclose(c, pagerbclose);
    setkeyaction(c, console_ctrlkeyin);
    setkeydown(c, console_normalkeyin);
    setmousedrag(c, console_mousedrag);
    setmouserepeat(c, console_mouserep);
    setmousedown(c, console_mousedown);
    return(c);
}