示例#1
0
/**
 * MsgProc to deal with incoming windows messages.
 */
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{
	switch (msg)
	{
		// our app has the focus
	case WM_ACTIVATE:
		g_bIsActive = (BOOL)wParam;
		break;
		// key was pressed
	case WM_KEYDOWN:
		switch (wParam)
		{
		case VK_ESCAPE:
			g_bDone = true;
			PostMessage(hWnd, WM_CLOSE, 0, 0);
			return 0;
			break;
		case VK_LEFT:
			if (g_nWndCtl <= 0)
			{
				break;
			}
			g_nWndCtl--;
			if (g_pDevice)
			{
				g_pDevice->UseWindow(g_nWndCtl);
			}
			break;
		case VK_RIGHT:

			if (g_nWndCtl >= g_MAXWND - 1)
			{
				break;
			}
			g_nWndCtl++;
			if (g_pDevice)
			{
				g_pDevice->UseWindow(g_nWndCtl);
			}
			break;
		}
		break;
		// we are ordered to suicide
	case WM_DESTROY:
		g_bDone = true;
		PostQuitMessage(0);
		return 1;
		break;

	default: break;
	}

	if (msg == WM_KEYDOWN)
	{
		KeyProc(wParam);
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}
示例#2
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
示例#3
0
void DrawLightExam()
{
	// compute camera 
	g_pos.y = distance * sin(yAngle);
	g_pos.x = distance * cos(yAngle) * sin(-xAngle);
	g_pos.z = distance * cos(yAngle) * cos(-xAngle);

	g_lightPos.y = LightDistantce * sin(yLightAngle);
	g_lightPos.x = LightDistantce * cos(yLightAngle) * sin(-xLightAngle);
	g_lightPos.z = LightDistantce * cos(yLightAngle) * cos(-xLightAngle);



	light.vcPosition = g_lightPos;
	light.vcDirection = -g_lightPos;
	light.vcDirection.w = 0;
	light.fPhi = g_cutoff;
	light.fExponent = g_exponent;

	g_pDevice->UseWindow(0);

	ZFXVector vU(0, 1, 0);
	g_pDevice->SetViewLookAt(g_pos, ZFXVector(0, 0, 0), vU);
	IShaderManager *sm = g_pDevice->GetShaderManager();
	sm->SetNamedConstant("camera_position", DAT_FVEC4, 1, g_pos.v);
	GLfloat f[16] = { 0.0 };
	glGetFloatv(GL_MODELVIEW_MATRIX, f);
	glGetFloatv(GL_PROJECTION_MATRIX, f);

	ZFXMatrix mWorld;
	mWorld.Identity();
	g_pDevice->SetWorldTransform(&mWorld);

	//sm->EnableShader(false);

	g_pDevice->SetAmbientLight(0.1, 0.1, 0.1);
	g_pDevice->SetLight(&light, 0);

	float v[4];
	glGetMaterialfv(GL_FRONT, GL_AMBIENT, v);
	glGetMaterialfv(GL_FRONT, GL_DIFFUSE, v);
	glGetMaterialfv(GL_FRONT, GL_SPECULAR, v);
	glGetMaterialfv(GL_FRONT, GL_EMISSION, v);

	DrawOBJModel();
	GLenum error = glGetError();
	if (error != GL_NO_ERROR)
	{
		int i = 0;
	}

	glGetMaterialfv(GL_FRONT, GL_AMBIENT, v);
	glGetMaterialfv(GL_FRONT, GL_DIFFUSE, v);
	glGetMaterialfv(GL_FRONT, GL_SPECULAR, v);
	glGetMaterialfv(GL_FRONT, GL_EMISSION, v);

	glGetLightfv(GL_LIGHT0, GL_AMBIENT, v);
	glGetLightfv(GL_LIGHT0, GL_DIFFUSE, v);
	glGetLightfv(GL_LIGHT0, GL_SPECULAR, v);


	error = glGetError();
	if (error != GL_NO_ERROR)
	{
		int i = 0;
	}
}