geEngine_SetClearColor

Programming Reality Factory and Genesis3D.
Post Reply
User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

geEngine_SetClearColor

Post 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;
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

I will add it to the modified G3d source with

geWorld_AddEntity
geWorld_GetWorldGeometry
geActor_SetBoneGlobalAttachment
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post 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???
1 wrote:
for the internet is a cruel and dark place at times, and there's sex and blood everywhere.

2 wrote:
You say that like it's a bad thing.

1 wrote:
You are a bad thing.
User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Post 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).
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps »

oh. :oops:
1 wrote:
for the internet is a cruel and dark place at times, and there's sex and blood everywhere.

2 wrote:
You say that like it's a bad thing.

1 wrote:
You are a bad thing.
Post Reply