Page 1 of 1

geEngine_SetClearColor

Posted: Mon Nov 05, 2007 12:34 pm
by QuestOfDreams
Added the possibility to set the clear color in Genesis3D

genesis.h and engine.h

add

Code: Select all

GENESISAPI geBoolean	geEngine_SetClearColor(geEngine *Engine, geFloat r, geFloat g, geFloat b);
system.h

in the geEngine struct add

Code: Select all

geFloat		ClearR;
geFloat		ClearG;
geFloat		ClearB;
engine.c

add

Code: Select all

//=====================================================================================
//	geEngine_UpdateClearColor
//=====================================================================================
static geBoolean geEngine_UpdateClearColor(geEngine *Engine)
{
	if(Engine->DriverInfo.RDriver)
	{
		return Engine->DriverInfo.RDriver->SetClearColor(Engine->ClearR,
								Engine->ClearG, 
								Engine->ClearB);
	}

	return GE_TRUE;
}

//=====================================================================================
//	geEngine_SetClearColor
//=====================================================================================
GENESISAPI geBoolean geEngine_SetClearColor(geEngine *Engine, geFloat r, geFloat g, geFloat b)
{
	Engine->ClearR = r;
	Engine->ClearG = g;
	Engine->ClearB = b;

	return geEngine_UpdateClearColor(Engine);
}

dcommon.h

add

Code: Select all

typedef geBoolean DRIVERCC DRV_SET_CLEARCOLOR(geFloat r, geFloat g, geFloat b);
in the DRV_Driver struct after DRV_SET_FOG_ENABLE *SetFogEnable; add

Code: Select all

DRV_SET_CLEARCOLOR	*SetClearColor;

DX7 driver:

D3d_main.h

in the App_Info struct add

Code: Select all

float		ClearR;
float		ClearG;
float		ClearB;
add

Code: Select all

geBoolean DRIVERCC	D3DMain_SetClearColor(float r, float g, float b);

D3d_main.cpp

in BOOL Main_ClearBackBuffer(BOOL Clear, BOOL ClearZ, BOOL ClearStencil) change

Code: Select all

if (AppInfo.FogEnable) 
	LastError = AppInfo.lpD3DDevice->Clear( 1, &Dummy, ClearFlags, ((DWORD)AppInfo.FogR<<16)|((DWORD)AppInfo.FogG<<8)|(DWORD)AppInfo.FogB, 1.0f, 0L );
else
	LastError = AppInfo.lpD3DDevice->Clear( 1, &Dummy, ClearFlags, ((DWORD)AppInfo.ClearR<<16)|((DWORD)AppInfo.ClearG<<8)|(DWORD)AppInfo.ClearB, 1.0f, 0L ); 

change

Code: Select all

geBoolean DRIVERCC D3DMain_SetFogEnable(geBoolean Enable, float r, float g, float b, float Start, float End)
{
/* 07/16/2000 Wendell Buckner
    Convert to Directx7...    
	D3DMATERIAL			Material; */
    D3DMATERIAL7		Material;

	AppInfo.FogEnable = Enable;
	AppInfo.FogR = r;
	AppInfo.FogG = g;
	AppInfo.FogB = b;
	AppInfo.FogStart = Start;
	AppInfo.FogEnd = End;

	// Fill in the material with the data
/* 07/16/2000 Wendell Buckner
    Convert to Directx7...    	
	memset(&Material, 0, sizeof(D3DMATERIAL));
	Material.dwSize       = sizeof(D3DMATERIAL); */
	memset(&Material, 0, sizeof(D3DMATERIAL7));

	if (Enable)
	{
		Material.dcvDiffuse.r = Material.dcvAmbient.r = r/255.0f;
		Material.dcvDiffuse.g = Material.dcvAmbient.g = g/255.0f;
		Material.dcvDiffuse.b = Material.dcvAmbient.b = b/255.0f;
	}
	else
	{
		Material.dcvDiffuse.r = Material.dcvAmbient.r = AppInfo.ClearR/255.0f;
		Material.dcvDiffuse.g = Material.dcvAmbient.g = AppInfo.ClearG/255.0f;
		Material.dcvDiffuse.b = Material.dcvAmbient.b = AppInfo.ClearB/255.0f;
	}

/* 07/16/2000 Wendell Buckner
    Convert to Directx7...    		
	Material.dwRampSize = 16L; // A default ramp size */

	AppInfo.BackgroundMaterial->SetMaterial(&Material); 

	return GE_TRUE;
}
add

Code: Select all

//========================================================================================================
//	D3DMain_SetClearColor
//========================================================================================================
geBoolean DRIVERCC D3DMain_SetClearColor(float r, float g, float b)
{
	D3DMATERIAL7		Material;

	AppInfo.ClearR = r;
	AppInfo.ClearG = g;
	AppInfo.ClearB = b;

	// Fill in the material with the data
	memset(&Material, 0, sizeof(D3DMATERIAL7));

	Material.dcvDiffuse.r = Material.dcvAmbient.r = r/255.0f;
	Material.dcvDiffuse.g = Material.dcvAmbient.g = g/255.0f;
	Material.dcvDiffuse.b = Material.dcvAmbient.b = b/255.0f;
	
	AppInfo.BackgroundMaterial->SetMaterial(&Material); 

	return GE_TRUE;
}

Scene.cpp

in BOOL DRIVERCC BeginScene(BOOL Clear, BOOL ClearZ, BOOL ClearStencil, RECT *WorldRect) change

Code: Select all

if (AppInfo.FogEnable)
{
	D3DFogEnable ( AppInfo.FogEnable, ((DWORD)AppInfo.FogR<<16)|((DWORD)AppInfo.FogG<<8)|(DWORD)AppInfo.FogB );		
}
else
{
	D3DFogEnable ( AppInfo.FogEnable, ((DWORD)AppInfo.ClearR<<16)|((DWORD)AppInfo.ClearG<<8)|(DWORD)AppInfo.ClearB );		
}

D3ddrv7x.cpp

in the DRV_Driver D3DDRV initialization after D3DMain_SetFogEnable, add

Code: Select all

D3DMain_SetClearColor,

changes in the old d3d driver are pretty much the same


OpenGL driver

OglDrv.c

to the globals add

Code: Select all

GLfloat ClearColor[3];

in the DRV_Driver OGLDRV initialization after SetFogEnable, add

Code: Select all

SetClearColor,
in geBoolean DRIVERCC SetFogEnable(geBoolean Enable, float r, float g, float b, float Start, float End)
change

Code: Select all

else
{
	glDisable(GL_FOG);
	FogEnabled = GE_FALSE;
	glClearColor(ClearColor[0], ClearColor[1], ClearColor[2], 1.0);
}

add

Code: Select all

geBoolean DRIVERCC SetClearColor(float r, float g, float b)
{
	ClearColor[0] = (GLfloat)r/255.0f;
	ClearColor[1] = (GLfloat)g/255.0f;
	ClearColor[2] = (GLfloat)b/255.0f;

	glClearColor(ClearColor[0], ClearColor[1], ClearColor[2], 1.0);

	return GE_TRUE;
}
in geBoolean DRIVERCC DrvInit(DRV_DriverHook *Hook) add

Code: Select all

ClearColor[0] = ClearColor[1] = ClearColor[2] = 0.f;

Posted: Mon Nov 05, 2007 4:15 pm
by federico
I will add it to the modified G3d source with

geWorld_AddEntity
geWorld_GetWorldGeometry
geActor_SetBoneGlobalAttachment

Posted: Tue Nov 13, 2007 8:16 pm
by fps
i think i understand what this is for but i may be mistaken.
will this command take a defined color value and make it transparent on any actor, bitmap, brush?
am i right about this?
ive seen this tecnique used on trees, bushes, hair, fences, ect...
also will this possibly lead to alpha maps being obsolete???

Posted: Tue Nov 13, 2007 8:23 pm
by QuestOfDreams
No, this just defines the color the rendering window gets cleared to before anything is drawn to it. This is not of much use in game but for example allows you to set the background color in the ActView tool to something different than black (like you can do it in the Viewer tool now).

Posted: Wed Nov 14, 2007 3:16 pm
by fps
oh. :oops: