コード例 #1
0
ファイル: main.cpp プロジェクト: slipslob/3d-zfxengine
/**
 * Create a render device and stuff. 
 */
HRESULT ProgramStartup(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);

   for (int i=0; i<4; 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
   return g_pDevice->Init(g_hWnd, hWnd3D, 4, 16, 0, false);
   } // ProgramStartup
コード例 #2
0
ファイル: main.cpp プロジェクト: Gemini2015/ZFXEngine
/**
 * 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