Esempio n. 1
0
void InitLightExam()
{
	ZFXCOLOR color(0, 0, 1, 1);
	g_pDevice->SetShadeMode(RS_SHADE_SOLID, 1.0f, &color);
	ZFXVector vU(0, 1, 0);
	ZFXVIEWPORT vp = { 0, 0, 800, 600 };
	g_pDevice->InitStage(60, &vp, 0);
	g_pDevice->SetClippingPlanes(0.1f, 1000.0f);
	g_pDevice->SetMode(EMD_PERSPECTIVE, 0);

	IShaderManager* sm = g_pDevice->GetShaderManager();
	if (g_vshader)
		sm->BindShader(g_vshader);
	if (g_fshader)
		sm->BindShader(g_fshader);
	if (g_vshader || g_fshader)
		sm->EnableShader(true);


	light.Type = LGT_SPOT;
	light.cAmbient.rgba(0.2, 0.2, 0.2, 1);
	light.cDiffuse.rgba(0, 0, 1, 1);
	light.cSpecular.rgba(1, 0, 0, 1);
	light.fAttenuation0 = 1.0f;
	light.fAttenuation1 = 0.0f;
	light.fTheta = 30;
	light.fPhi = 60;
	light.fRange = 50;
	light.vcDirection = ZFXVector(0, 0, 0);
}
Esempio n. 2
0
void InitTriangleExam()
{
	ZFXCOLOR color(0, 0, 1, 1);
	g_pDevice->SetShadeMode(RS_SHADE_SOLID, 1.0f, &color);
	ZFXVector vU(0, 1, 0);
	ZFXVIEWPORT vp = { 0, 0, 800, 600 };
	g_pDevice->InitStage(60, &vp, 0);
	g_pDevice->SetClippingPlanes(0.1f, 1000.0f);
	g_pDevice->SetMode(EMD_ORTHOGONAL, 0);

	IShaderManager* sm = g_pDevice->GetShaderManager();
	if (g_vshader)
		sm->BindShader(g_vshader);
	if (g_fshader)
		sm->BindShader(g_fshader);
	if (g_vshader || g_fshader)
		sm->EnableShader(true);

	sm->EnableShader(false);
}
Esempio n. 3
0
/**
 * Create a render device and stuff.
 */
HRESULT ProgramStartup(const char *chAPI) 
{
	HWND hWnd3D[4];
	RECT rcWnd;
	int  x = 0, y = 0;

	// no opengl render device yet...
	//if (strcmp(chAPI, "OpenGL") == 0) return S_OK;

	// create a render objekt
	g_pRenderer = new ZFXRenderer(g_hInst);

	// create a device for the chosen api
	if (FAILED(g_pRenderer->CreateDevice(chAPI))) return E_FAIL;

	// get a pointer on that device
	g_pDevice = g_pRenderer->GetDevice();
	if (g_pDevice == NULL) return E_FAIL;

	// build for child windows
	GetClientRect(g_hWnd, &rcWnd);
	g_MAXWND = 0;
	for (int i = 0; i < g_MAXWND; i++) 
	{
		if ((i == 0) || (i == 2)) x = 10;
		else x = rcWnd.right / 2 + 10;

		if ((i == 0) || (i == 1)) y = 10;
		else y = rcWnd.bottom / 2 + 10;

		hWnd3D[i] = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("static"),
			NULL, WS_CHILD | SS_BLACKRECT | WS_VISIBLE,
			x, y, rcWnd.right / 2 - 20, rcWnd.bottom / 2 - 20,
			g_hWnd, NULL, g_hInst, NULL);
	}

	// init render device
	if (FAILED(g_pDevice->Init(g_hWnd, hWnd3D, g_MAXWND, 16, 0, false)))
	{
		GetLogger().Print(LOG_DEBUG,log_file,"Error RenderDevice Init");
		return ZFX_FAIL;
	}

	g_pDevice->UseWindow(0);

	POINT ptRes;
	g_pDevice->GetResolution(&ptRes);
	long lx = 0, ldx = 0, ldy = 0, fs = 0;

	ldx = ptRes.x / 2.666666f;
	ldy = ldx / 1.333333f;
	lx = ptRes.x - ldx - 10;

	fs = ptRes.x / 20;

	ZFXVIEWPORT rc = { lx, 0, ldx, ldy };
	g_pDevice->InitStage(60, NULL, 0);
	g_pDevice->InitStage(60, &rc, 1);

	if (strcmp(chAPI, "Direct3D") == 0)
	{
		if (FAILED(g_pDevice->CreateFont("Arial", 0, false, false,
			false, fs, &g_nFontID)))
		{
			GetLogger().Print(LOG_DEBUG,log_file,"error: ZFXRenderDevice::CreateFont failed\n");
			return ZFX_FAIL;
		}
	}

	IShaderManager* sm = g_pDevice->GetShaderManager();
	std::string str("shader//shader.vert");
	g_vshader = sm->CreateShader((void*)str.c_str(), SHT_VERTEX, true);
	str.assign("shader//shader.frag");
	g_fshader = sm->CreateShader((void*)str.c_str(), SHT_PIXEL, true);


	return ZFX_OK;
} // ProgramStartup