Пример #1
0
static int BestShrinkFactor (CBitmap *bmP, int nShrinkFactor)
{
	int	nBaseSize, nTargetSize, nBaseFactor;

if ((bmP->Width () != Pow2ize (bmP->Width ())) || (bmP->Height () != Pow2ize (bmP->Height ())))
	return 1;
#if 0
if (bmP->Width () >= 2 * bmP->Width ()) {
#endif
	nBaseSize = bmP->Width ();
	nTargetSize = 512 / nShrinkFactor;
	nBaseFactor = (3 * nBaseSize / 2) / nTargetSize;
#if 0
	}
else {
	nBaseSize = bmP->Width () * bmP->Width ();
	nTargetSize = (512 * 512) / (nShrinkFactor * nShrinkFactor);
	nBaseFactor = (int) sqrt ((double) (3 * nBaseSize / 2) / nTargetSize);
	}
#endif
if (!nBaseFactor)
	return 1;
if (nBaseFactor > nShrinkFactor)
	return nShrinkFactor;
for (nShrinkFactor = 1; nShrinkFactor <= nBaseFactor; nShrinkFactor *= 2)
	;
return nShrinkFactor / 2;
}
Пример #2
0
void CTexture::Setup (int w, int h, int lw, int bpp, int bMask, int bMipMap, int bSmoothe, CBitmap *bmP)
{
m_info.w = w;
m_info.h = h;
m_info.lw = lw;
m_info.tw = Pow2ize (w);
m_info.th = Pow2ize (h);
if (bMask) {
	m_info.format = GL_RED;
	m_info.internalFormat = 1;
	}
else if (bpp == 3) {
	m_info.format = GL_RGB;
#if TEXTURE_COMPRESSION
	if ((w > 64) && (w == h))
		m_info.internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
	else
#endif
	m_info.internalFormat = 3;
	}
else {
	m_info.format = GL_RGBA;
#if TEXTURE_COMPRESSION
	if ((w > 64) && (w == h))
		m_info.internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
	else
#endif
	m_info.internalFormat = 4;
	}
m_info.bMipMaps = (bMipMap > 0) && !bMask;
m_info.bSmoothe = (bMipMap < 0) ? -1 : bSmoothe || m_info.bMipMaps;
}
Пример #3
0
int CCamera::Create (short nId, short srcSeg, short srcSide, short tgtSeg, short tgtSide, 
							CObject *objP, int bShadowMap, int bTeleport)
{
	CAngleVector	a;
#if 0
	short*		corners;
	CFixVector	*pv;
#endif

Init ();
m_info.nId = nId;
m_info.bShadowMap = bShadowMap;
m_info.buffer.SetWidth (Pow2ize (screen.Width () / (2 - gameOpts->render.cameras.bHires)));
m_info.buffer.SetHeight (Pow2ize (screen.Height () / (2 - gameOpts->render.cameras.bHires)));
m_info.buffer.SetBPP (4);
//m_info.buffer.SetRowSize (max (CCanvas::Current ()->Width (), m_info.buffer.Width ()));
#if RENDER2TEXTURE
if (!CreateBuffer ()) 
#endif
{
#if CAMERA_READPIXELS
	if (!(m_info.buffer.Create (m_info.buffer.Width () * m_info.buffer.Height () * 4)))
		return 0;
	if (gameOpts->render.cameras.bFitToWall || m_info.bTeleport)
		m_info.screenBuf = m_info.buffer.Buffer ();
	else {
		m_info.screenBuf = new ubyte [CCanvas::Current ()->Width () * CCanvas::Current ()->Height () * 4];
		if (!m_info.screenBuf) {
			gameOpts->render.cameras.bFitToWall = 1;
			m_info.screenBuf = m_info.buffer.Buffer ();
			}
		}
	memset (m_info.buffer.Buffer (), 0, m_info.buffer.Width () * m_info.buffer.Height () * 4);
#else
	return 0;
#endif
	}
if (objP) {
	m_info.objP = objP;
	m_info.orient = objP->info.position.mOrient;
	m_info.curAngle =
	m_info.curDelta = 0;
	m_info.t0 = 0;
	cameraManager.SetObjectCamera (objP->Index (), nId);
	}
else {
	m_info.objP = &m_info.obj;
	if (bTeleport) {
		CFixVector n = *SEGMENTS [srcSeg].m_sides [srcSide].m_normals;
		/*
		n[X] = -n[X];
		n[Y] = -n[Y];
		*/
		n.Neg ();
		a = n.ToAnglesVec ();
		}
	else
		a = SEGMENTS [srcSeg].m_sides [srcSide].m_normals [0].ToAnglesVec ();
	m_info.obj.info.position.mOrient = CFixMatrix::Create(a);
#if 1
	if (bTeleport)
		m_info.obj.info.position.vPos = SEGMENTS [srcSeg].Center ();
	else
		m_info.obj.info.position.vPos = SEGMENTS [srcSeg].SideCenter (srcSide);
#else
	corners = SEGMENTS [srcSeg].Corners (srcSide);
	for (i = 0; i < 4; i++) {
		pv = gameData.segs.vertices + corners [i];
		m_info.obj.info.position.p.vPos.x += pv->x;
		m_info.obj.info.position.p.vPos.y += pv->y;
		m_info.obj.info.position.p.vPos.z += pv->z;
		}
	m_info.obj.info.position.p.vPos.x /= 4;
	m_info.obj.info.position.p.vPos.y /= 4;
	m_info.obj.info.position.p.vPos.z /= 4;
#endif
	m_info.obj.info.nSegment = srcSeg;
	m_info.bMirror = (tgtSeg == srcSeg) && (tgtSide == srcSide);
	}
//m_info.obj.nSide = srcSide;
m_info.nSegment = tgtSeg;
m_info.nSide = tgtSide;
m_info.bTeleport = (char) bTeleport;
return 1;
}