示例#1
0
文件: system.cpp 项目: bagobor/bsgl
bool CALL BSGL_Impl::System_Initiate() {
    System_Log("BSGL Started...\n");
    System_Log("BSGL version: %X.%X", BSGL_VERSION>>8, BSGL_VERSION&0xFF);
    System_Log("Application: %s\n", szTitle);

    _LoadConfig("config.xml");

    if( !_GfxInit() ) {
        _PostError("Can't initialize OpenGL.");
        System_Shutdown();
        return false;
    }

    fTime = 0.0f;
#if defined(CC_TARGET_OS_IPHONE)
    fStartTime = 0.0f;
#endif

    bInit = true;
#if !defined(CC_TARGET_OS_IPHONE)
    SDL_WM_SetCaption(szTitle, NULL);
#endif

    return true;
}
示例#2
0
void CALL HGE_Impl::System_Shutdown()
{
	System_Log("\nFinishing..");

	_ClearQueue();
	_SoundDone();
	_GfxDone();
	_DonePowerStatus();
	SDL_Quit();
	System_Log("The End.");
}
示例#3
0
HSTREAM D3DCore_Impl::Stream_Load(const WCHAR *filename, DWORD size)
{
	if(m_bSilent) return 0;

	void *data;
	DWORD _size;
	CStreamList *stmItem;

	if(m_pADevice)
	{
		if(size) { data=(void *)filename; _size=size; }
		else
		{
			data=File_Load(filename, &_size);
			if(!data) return 0;
		}
		
		FilePtr pf = CreateMemoryFile(data, _size);
		SampleSourcePtr source = OpenSampleSource(pf);
		if (!source) {
			System_Log(L"[AUDIERE - ERROR] %s: Can't load sample source", filename);
			return 0;
		}

		LoopPointSourcePtr loop_source = CreateLoopPointSource(source);
		if (loop_source) {
			source = loop_source.get();
		}

		OutputStream* stream = OpenSound( m_pADevice, source, true);
		if (!stream) 
		{
			System_Log(L"[AUDIERE - ERROR] %s: Can't load stream", filename);
			if(!size) File_Free(data);
			return 0;
		}
		stream->ref();
		if(!size)
		{
			stmItem=new CStreamList;
			stmItem->hstream=(HSTREAM)stream;
			stmItem->data=data;
			stmItem->next=streams;
			streams=stmItem;
		}
		return (HSTREAM)stream;
	}
	else return 0;
}
示例#4
0
文件: system.cpp 项目: pzagrebin/omg
bool OMG_Impl::System_Initiate()
	{
	strcpy(app_name, "OMG program.");	//default application name
	strcpy(log_name, "omg.log");		//default log file name
	w_screen = 640;						//default screen width
	h_screen = 480;						//and height

	hDC = NULL;			// Private GDI Device Context
	hRC = NULL;			// Permanent Rendering Context
	hWnd = NULL;		// Holds Our Window Handle

	procFrameFunc = 0;
	procRenderFunc = 0;

	bHideMouse = true;
//	bLighting = false;
//	ambient_light = 1.0;

	//create or flush log file
	FILE * f = fopen(log_name, "w");
	fclose(f);

	System_Log("OMG_Impl::System_Initiate() - begin");
	System_Log("Application name: %s", app_name);

	active = true;
	fullscreen = false;		//window mode by default

	//timer
	timer = new omgTimer();
	t_last = 0.0;
	t_new = 0.0;
	t_step = 0.01;	//default 100 fps

//	_Input_Init();

	done = FALSE;

	if (!CreateGLWindow(app_name, w_screen, h_screen, 32, fullscreen))
		{
		System_Log("Can't create GL window, shutdown.");
		return 0;
		}
	System_Log("GL window %dx%d was created.", w_screen, h_screen);
	System_Log("OMG_Impl::System_Initiate() - done!");

	return true;
	}
示例#5
0
HEFFECT D3DCore_Impl::Effect_Load(const WCHAR *filename, DWORD size)
{
	if(m_bSilent) return 0;

	DWORD _size;
	FilePtr pf;
	SampleSource* SSource = NULL;
	void *data;

	if(m_pADevice)
	{
		if(size) { data=(void *)filename; _size=size; }
		else
		{
			data=File_Load(filename, &_size);
			if(!data) return NULL;
		}
	
		pf = CreateMemoryFile(data, _size);
		if(pf.get() != NULL) {
			SSource = OpenSampleSource( pf.get() );			
			if(!SSource) {
				System_Log(L"[AUDIERE - ERROR] %s - Can't create sound effect", filename);				
			}
			SSource->ref();
		}

		if(!size) File_Free(data);
		return (HEFFECT)SSource;
	}
	else return 0;
}
示例#6
0
bool CALL HGE_Impl::Resource_AttachPack(const char *filename, const char *password)
{
	char *szName;
	CResourceList *resItem=res;
	unzFile zip;

	szName=Resource_MakePath(filename);

	while(resItem)
	{
		if(!strcmp(szName,resItem->filename)) return false;
		resItem=resItem->next;
	}

	zip=unzOpen(szName);
	if(!zip) {
		System_Log("Unable to unzip: %s", szName);
		return false;
	}
	unzClose(zip);

	resItem=new CResourceList;
	strcpy(resItem->filename, szName);
	if(password) strcpy(resItem->password, password);
	else resItem->password[0]=0;
	resItem->next=res;
	res=resItem;

	return true;
}
示例#7
0
bool CALL HGE_Impl::System_Initiate()
{	
	// Init subsystems	
	Random_Seed();
	if(!_GfxInit()) { System_Shutdown(); return false; }	
	if(!_SoundInit()) { System_Shutdown(); return false; }
	System_Log("Init done.\n");
	return true;
}
示例#8
0
void CALL HGE_Impl::System_Shutdown()
{
	System_Log("\nFinishing..");

	timeEndPeriod(1);
	_ClearQueue();
	_SoundDone();
	_GfxDone();
	if(hwnd)
	{
		//ShowWindow(hwnd, SW_HIDE);
		//SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
		//ShowWindow(hwnd, SW_SHOW);
		DestroyWindow(hwnd);
		hwnd=0;
	}
	if(hInstance) UnregisterClass(WINDOW_CLASS_NAME, hInstance);

	System_Log("The End.");
}
示例#9
0
文件: system.cpp 项目: bagobor/bsgl
void BSGL_Impl::_PostError(const char* error, ...) {
    va_list vl;
    char _error[256];

    va_start(vl, error);
    vsprintf(_error, error, vl);
    va_end(vl);

    System_Log("Error: %s", _error);
    strcpy(szError, _error);
}
示例#10
0
bool HGE_Impl::_SoundInit()
{
	if(!bUseSound || hOpenAL) return true;

	bSilent=false;

	sidcount = 0;
	memset(sids, '\0', sizeof (sids));

    System_Log("Starting OpenAL init");

	ALCdevice *dev = alcOpenDevice(NULL);
	if (!dev)
	{
		System_Log("alcOpenDevice(NULL) failed, using no sound");
		bSilent=true;
		return true;
	}

	ALint caps[] = { ALC_FREQUENCY, nSampleRate, 0 };
	ALCcontext *ctx = alcCreateContext(dev, caps);
	if (!ctx)
	{
		alcCloseDevice(dev);
		System_Log("alcCreateContext(NULL) failed, using no sound");
		bSilent=true;
		return true;
	}

	alcMakeContextCurrent(ctx);
	alcProcessContext(ctx);

    System_Log("OpenAL initialized");
    System_Log("AL_VENDOR: %s", (char *) alGetString(AL_VENDOR));
    System_Log("AL_RENDERER: %s", (char *) alGetString(AL_RENDERER));
    System_Log("AL_VERSION: %s", (char *) alGetString(AL_VERSION));
    System_Log("AL_EXTENSIONS: %s", (char *) alGetString(AL_EXTENSIONS));

	hOpenAL = (void *) 0x1;   // something non-NULL (!!! FIXME: this should eventually be a library handle).

	_SetFXVolume(nFXVolume);
	//_SetMusVolume(nMusVolume);
	//_SetStreamVolume(nStreamVolume);

	return true;
}
示例#11
0
文件: system.cpp 项目: pzagrebin/omg
bool OMG_Impl::System_Start()
	{
	System_Log("Trying to start!");

	//timer
	timer->Start();
	t_last = timer->Get();
	t_new = timer->Get();

	//main loop
	for(;;)
		{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			}
		if(active)
			{
			if (done)
				break;
			t_new = timer->Get();
			if(t_new - t_last > t_step)
				{
				if (!DrawGLScene())
					done = TRUE;

				if(procFrameFunc)
					if (procFrameFunc())
						break;

				_Input_Update();

				SwapBuffers(hDC);
				t_last = t_new;
				}

			else
				Sleep(0);
			}
			else
				Sleep(1);
	}
	KillGLWindow();
	return true;
	}
示例#12
0
文件: system.cpp 项目: pzagrebin/omg
void OMG_Impl::System_Shutdown()
	{
	System_Log("OMG_Impl::System_Shutdown() - begin");
	System_Log("OMG_Impl::System_Shutdown() - end");
	}
示例#13
0
bool HGE_Impl::_GfxInit()
{
	HRESULT hr = S_OK;

#pragma region
	const D3D_FEATURE_LEVEL featureLevels[] = {
		D3D_FEATURE_LEVEL_11_1,
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_1 };

	UINT               numFeatureLevels = 7;
	D3D_FEATURE_LEVEL  selectedFeatureLevel = D3D_FEATURE_LEVEL_11_0;

	// create swap chain description
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
	swapChainDesc.BufferCount = 1;                                   // one back buffer
	swapChainDesc.BufferDesc.Width = nScreenWidth;                   // set the back buffer width
	swapChainDesc.BufferDesc.Height = nScreenHeight;                 // set the back buffer height
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;    // use 32-bit color
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;     // how swap chain is to be used
	swapChainDesc.OutputWindow = hwnd;                               // the window to be used
	swapChainDesc.SampleDesc.Count = 1;                              // how many multisamples
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.Windowed = bWindowed;                              // windowed/full-screen mode
	swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;    // allow full-screen switching

	//Setup debuf flag
#ifdef _DEBUG
	UINT createDeviceFlags = D3D11_CREATE_DEVICE_DEBUG;
#else
	UINT createDeviceFlags = 0;
#endif
	//create device and swapchain
	hr = D3D11CreateDeviceAndSwapChain(
		NULL,
		D3D_DRIVER_TYPE_HARDWARE,
		NULL,
		createDeviceFlags,
		featureLevels,
		numFeatureLevels,
		D3D11_SDK_VERSION,
		&swapChainDesc,
		&m_pSwapChain,
		&m_pD3DDevice,
		&selectedFeatureLevel,
		&m_pD3DDeviceContext);
	if (hr != S_OK)
	{
		_PostError("Can't initialize d3d11.");
		return false;
	}
#pragma endregion init swap chain

#pragma region 
	// Setup render target
	V_RETURN(m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&m_pBackBuffer));
	V_RETURN(m_pD3DDevice->CreateRenderTargetView(m_pBackBuffer, NULL, &pRTView));
	//m_pBackBuffer->Release();

	m_pD3DDeviceContext->OMSetRenderTargets(1, &pRTView, NULL);

	// Setup the viewport
	D3D11_VIEWPORT vp;
	vp.Width = (FLOAT)nScreenWidth;
	vp.Height = (FLOAT)nScreenHeight;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	m_pD3DDeviceContext->RSSetViewports(1, &vp);

	/*
	// Create depth stencil texture
	D3D11_TEXTURE2D_DESC descDepth;
	ZeroMemory(&descDepth, sizeof(descDepth));
	descDepth.Width = nScreenWidth;
	descDepth.Height = nScreenHeight;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	descDepth.SampleDesc.Count = 1;
	descDepth.SampleDesc.Quality = 0;
	descDepth.Usage = D3D11_USAGE_DEFAULT;
	descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	hr = m_pDevice->CreateTexture2D(&descDepth, NULL, &m_pDepthBuffer);
	if (FAILED(hr))
	return hr;

	// Create the depth stencil view
	D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
	ZeroMemory(&descDSV, sizeof(descDSV));
	descDSV.Format = descDepth.Format;
	descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;
	hr = m_pDevice->CreateDepthStencilView(m_pDepthBuffer, &descDSV, &pDSView);
	if (FAILED(hr))
	return hr;
	*/
	//m_pDeviceContext->OMSetRenderTargets(1, &pRTView, pDSView);
#pragma endregion setup render targets & viewport

#pragma region
	std::string vertexProfile, pixelProfile;
	if (m_pD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_11_0)
	{
		vertexProfile = "vs_5_0";
		pixelProfile = "ps_5_0";
	}
	else if (m_pD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_10_1)
	{
		vertexProfile = "vs_4_1";
		pixelProfile = "ps_4_1";
	}
	else if (m_pD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_10_0)
	{
		vertexProfile = "vs_4_0";
		pixelProfile = "ps_4_0";
	}
	else if (m_pD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_9_3)
	{
		vertexProfile = "vs_4_0_level_9_3";
		pixelProfile = "ps_4_0_level_9_3";
	}
	else if (m_pD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_9_2)
	{
		vertexProfile = "vs_4_0_level_9_1";
		pixelProfile = "ps_4_0_level_9_1";
	}
	else if (m_pD3DDevice->GetFeatureLevel() == D3D_FEATURE_LEVEL_9_1)
	{
		vertexProfile = "vs_4_0_level_9_1";
		pixelProfile = "ps_4_0_level_9_1";
	}

	//D3DCOMPILE_OPTIMIZATION_LEVEL3 &
	//D3DCOMPILE_ENABLE_STRICTNESS
	UINT flags = (1 << 11) | (1 << 15);


	// Build Flat Vertex Shader
	ID3DBlob* binarycode = 0, *errors = 0, *signature0 = 0, *signature1 = 0;
	V_RETURN(D3DCompile(vsSource, strlen(vsSource), "VertexShader0", 0, 0, "main", vertexProfile.c_str(), flags, 0, &binarycode, &errors));

	V_RETURN(D3DGetInputSignatureBlob(binarycode->GetBufferPointer(), binarycode->GetBufferSize(), &signature0));


	V_RETURN(m_pD3DDevice->CreateVertexShader(binarycode->GetBufferPointer(), binarycode->GetBufferSize(), 0, &m_pVS0));

	if (binarycode) binarycode->Release();
	if (errors) errors->Release();

	// Build Textured Vertex Shader
	binarycode = 0;
	errors = 0;
	V_RETURN(D3DCompile(vsTexturedSource, strlen(vsTexturedSource), "VertexShader1", 0, 0, "main", vertexProfile.c_str(), flags, 0, &binarycode, &errors));

	V_RETURN(D3DGetInputSignatureBlob(binarycode->GetBufferPointer(), binarycode->GetBufferSize(), &signature1));

	V_RETURN(m_pD3DDevice->CreateVertexShader(binarycode->GetBufferPointer(), binarycode->GetBufferSize(), 0, &m_pVS1));

	if (binarycode) binarycode->Release();
	if (errors) errors->Release();

	// Build Flat Pixel Shader
	binarycode = 0;
	errors = 0;
	V_RETURN(D3DCompile(psSource, strlen(psSource), "PixelShader0", 0, 0, "main", pixelProfile.c_str(), flags, 0, &binarycode, &errors));

	V_RETURN(m_pD3DDevice->CreatePixelShader(binarycode->GetBufferPointer(), binarycode->GetBufferSize(), 0, &m_pPS0));

	if (binarycode) binarycode->Release();
	if (errors) errors->Release();

	// Build Textured Pixel Shader
	binarycode = 0;
	errors = 0;
	V_RETURN(D3DCompile(psTexturedSource, strlen(psTexturedSource), "PixelShader1", 0, 0, "main", pixelProfile.c_str(), flags, 0, &binarycode, &errors));

	V_RETURN(m_pD3DDevice->CreatePixelShader(binarycode->GetBufferPointer(), binarycode->GetBufferSize(), 0, &m_pPS1));

	if (binarycode) binarycode->Release();
	if (errors) errors->Release();


	// Compile the shaders using the lowest possible profile for broadest feature level support
	// 	ID3DBlob* pVertexShaderBuffer = NULL;
	// 	V_RETURN(CompileShaderFromFile(TEXT("BasicHLSL11_VS.hlsl"), "VSMain", vertexProfile.c_str(), &pVertexShaderBuffer));
	// 
	// 	ID3DBlob* pPixelShaderBuffer = NULL;
	// 	V_RETURN(CompileShaderFromFile(TEXT("BasicHLSL11_PS.hlsl"), "PSMain", pixelProfile.c_str(), &pPixelShaderBuffer));
	// 
	// 	// Create the shaders
	// 	V_RETURN(m_pD3DDevice->CreateVertexShader(pVertexShaderBuffer->GetBufferPointer(),
	// 		pVertexShaderBuffer->GetBufferSize(), NULL, &pVS0));
	// 	V_RETURN(m_pD3DDevice->CreatePixelShader(pPixelShaderBuffer->GetBufferPointer(),
	// 		pPixelShaderBuffer->GetBufferSize(), NULL, &pPS0));

	// Create Input Layout
	V_RETURN(m_pD3DDevice->CreateInputLayout(vertexLayout, 3, signature0->GetBufferPointer(), signature0->GetBufferSize(), &m_pInputLayout0));
	signature0->Release();

	// Create Input Layout
	V_RETURN(m_pD3DDevice->CreateInputLayout(vertexLayout, 3, signature1->GetBufferPointer(), signature1->GetBufferSize(), &m_pInputLayout1));
	signature1->Release();

#pragma endregion create shaders and input layout

#pragma region
	// Setup constant buffers
	D3D11_BUFFER_DESC desc;
	desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	desc.MiscFlags = 0;
	desc.StructureByteStride = 0;
	desc.ByteWidth = sizeof(hgeVertex)* (VERTEX_BUFFER_SIZE);
	desc.Usage = D3D11_USAGE_DYNAMIC;
	V_RETURN(m_pD3DDevice->CreateBuffer(&desc, NULL, &m_pVertexBuf));

	// 	D3D11_BUFFER_DESC desc;
	// 	desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	// 	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	// 	desc.MiscFlags = 0;
	// 	desc.StructureByteStride = 0;
	// 	desc.ByteWidth = 6 * (VERTEX_BUFFER_SIZE/4) * sizeof(uint16_t);
	// 	desc.Usage = D3D11_USAGE_DYNAMIC;
	// 	V_RETURN(m_pD3DDevice->CreateBuffer(&desc, NULL, &m_pIndexBuf));
	// 
	// 	for (int i = 0; i < VERTEX_BUFFER_SIZE / 4; i++)
	// 	{
	// 		*pIndices++ = n;
	// 		*pIndices++ = n + 1;
	// 		*pIndices++ = n + 2;
	// 		*pIndices++ = n + 2;
	// 		*pIndices++ = n + 3;
	// 		*pIndices++ = n;
	// 		n += 4;
	// 	}
	// 
	// 	m_pD3DDeviceContext->IASetIndexBuffer(m_pIndexBuf, DXGI_FORMAT_R16_UINT, 0);
	D3D11_BUFFER_DESC Desc;
	Desc.Usage = D3D11_USAGE_DYNAMIC;
	Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	Desc.MiscFlags = 0;
	Desc.ByteWidth = sizeof(CB_VS_PER_OBJECT);
	V_RETURN(m_pD3DDevice->CreateBuffer(&Desc, NULL, &g_pcbVSPerObject));
	Desc.ByteWidth = sizeof(CB_PS_PER_OBJECT);
	V_RETURN(m_pD3DDevice->CreateBuffer(&Desc, NULL, &g_pcbPSPerObject));
	Desc.ByteWidth = sizeof(CB_PS_PER_FRAME);
	V_RETURN(m_pD3DDevice->CreateBuffer(&Desc, NULL, &g_pcbPSPerFrame));
#pragma endregion setup constant buffers

	// Create Sampler State
	D3D11_SAMPLER_DESC samplerDesc;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.BorderColor[0] = samplerDesc.BorderColor[1] = samplerDesc.BorderColor[2] = samplerDesc.BorderColor[3] = 0.0f;
	samplerDesc.ComparisonFunc = (D3D11_COMPARISON_FUNC)0;
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.MaxAnisotropy = 1.0f;
	samplerDesc.MaxLOD = 0; //D3D11_FLOAT32_MAX
	samplerDesc.MinLOD = 0;
	samplerDesc.MipLODBias = 0.0f;
	V_RETURN(m_pD3DDevice->CreateSamplerState(&samplerDesc, &m_pSamplerState));

	// Create Blend State
	D3D11_BLEND_DESC blendDesc;
	blendDesc.AlphaToCoverageEnable = false;
	blendDesc.IndependentBlendEnable = false;
	blendDesc.RenderTarget[0].BlendEnable = true;
	blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
	blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
	blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	V_RETURN(m_pD3DDevice->CreateBlendState(&blendDesc, &m_pBlendState));

	// Create Depth Stencil State
	D3D11_DEPTH_STENCIL_DESC depthDesc;
	depthDesc.DepthEnable = false;
	depthDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
	depthDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
	depthDesc.StencilEnable = false;
	depthDesc.StencilReadMask = depthDesc.StencilWriteMask = 0;
	depthDesc.BackFace.StencilDepthFailOp = depthDesc.BackFace.StencilFailOp = depthDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthDesc.FrontFace = depthDesc.BackFace;
	V_RETURN(m_pD3DDevice->CreateDepthStencilState(&depthDesc, &m_pDepthStencilState));

	// Create Rasterizer State
	D3D11_RASTERIZER_DESC rastDesc;
	rastDesc.FillMode = D3D11_FILL_SOLID;
	rastDesc.CullMode = D3D11_CULL_NONE;
	rastDesc.FrontCounterClockwise = FALSE;
	rastDesc.DepthBias = 0;
	rastDesc.DepthBiasClamp = 0;
	rastDesc.SlopeScaledDepthBias = 0;
	rastDesc.ScissorEnable = FALSE;
	rastDesc.MultisampleEnable = FALSE;
	rastDesc.AntialiasedLineEnable = FALSE;
	hr = m_pD3DDevice->CreateRasterizerState(&rastDesc, &m_pRasterizerState);

	// 	mUpdate = false;
	// 
	// 	mIsInitialise = true;

	// Setup the camera's view parameters
	// 	D3DXVECTOR3 vecEye(0.0f, 0.0f, -100.0f);
	// 	D3DXVECTOR3 vecAt(0.0f, 0.0f, -0.0f);
	// 	g_Camera.SetViewParams(&vecEye, &vecAt);
	// 	g_Camera.SetRadius(fObjectRadius * 3.0f, fObjectRadius * 0.5f, fObjectRadius * 10.0f);

	//return S_OK;

	// Get adapter info
	// 	auto adapterList = EnumerateAdapters();
	// 	for (auto it = adapterList.begin(); it != adapterList.end(); it++)
	// 	{
	// 		System_Log("D3D Driver: %s", "123123123123123");
	// 		DXGI_ADAPTER_DESC desc;
	// 		(*it)->GetDesc(&desc);
	// 		System_Log("Description: %s", desc.Description);
	// 
	// 	}

	m_prim_count = 0;
	m_cur_prim_type = HGEPRIM_QUADS;
	m_cur_blend_mode = BLEND_DEFAULT;

	//todo: test those functions
	_AdjustWindow();

	System_Log("Screen Resolution: %d x %d\n", nScreenWidth, nScreenHeight);

	_SetProjectionMatrix(nScreenWidth, nScreenHeight);

	if (!_init_lost()) return false;

	Gfx_Clear(0);

	return true;
}
示例#14
0
文件: system.cpp 项目: bagobor/bsgl
void CALL BSGL_Impl::System_Shutdown() {
    System_Log("\nFinishing...");
    _GfxDone();

    System_Log("The End.");
}
示例#15
0
文件: system.cpp 项目: doveiya/isilme
bool CALL HGE_Impl::System_Initiate()
{
	OSVERSIONINFO	os_ver;
	SYSTEMTIME		tm;
	MEMORYSTATUS	mem_st;
	WNDCLASS		winclass;
	int				width, height;

	// Log system info

	System_Log("HGE Started..\n");

	System_Log("HGE version: %X.%X", HGE_VERSION>>8, HGE_VERSION & 0xFF);
	GetLocalTime(&tm);
	System_Log("Date: %02d.%02d.%d, %02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond);

	System_Log("Application: %s",szWinTitle);
	os_ver.dwOSVersionInfoSize=sizeof(os_ver);
	GetVersionEx(&os_ver);
	System_Log("OS: Windows %ld.%ld.%ld",os_ver.dwMajorVersion,os_ver.dwMinorVersion,os_ver.dwBuildNumber);

	GlobalMemoryStatus(&mem_st);
	System_Log("Memory: %ldK total, %ldK free\n",mem_st.dwTotalPhys/1024L,mem_st.dwAvailPhys/1024L);


	// Register window class
	
	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hInstance;
	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszMenuName	= NULL; 
	winclass.lpszClassName	= WINDOW_CLASS_NAME;
	if(szIcon) winclass.hIcon = LoadIcon(hInstance, szIcon);
	else winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	
	if (!RegisterClass(&winclass)) {
		_PostError("Can't register window class");
		return false;
	}

	// Create window

	width=nScreenWidth + GetSystemMetrics(SM_CXFIXEDFRAME)*2;
	height=nScreenHeight + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);

	rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2;
	rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2;
	rectW.right=rectW.left+width;
	rectW.bottom=rectW.top+height;
	styleW=WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE; //WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;

	rectFS.left=0;
	rectFS.top=0;
	rectFS.right=nScreenWidth;
	rectFS.bottom=nScreenHeight;
	styleFS=WS_POPUP|WS_VISIBLE; //WS_POPUP

	if(hwndParent)
	{
		rectW.left=0;
		rectW.top=0;
		rectW.right=nScreenWidth;
		rectW.bottom=nScreenHeight;
		styleW=WS_CHILD|WS_VISIBLE; 
		bWindowed=true;
	}

	if(bWindowed)
		hwnd = CreateWindowEx(0, WINDOW_CLASS_NAME, szWinTitle, styleW,
				rectW.left, rectW.top, rectW.right-rectW.left, rectW.bottom-rectW.top,
				hwndParent, NULL, hInstance, NULL);
	else
		hwnd = CreateWindowEx(WS_EX_TOPMOST, WINDOW_CLASS_NAME, szWinTitle, styleFS,
				0, 0, 0, 0,
				NULL, NULL, hInstance, NULL);
	if (!hwnd)
	{
		_PostError("Can't create window");
		return false;
	}

	ShowWindow(hwnd, SW_SHOW);

	// Init subsystems

	timeBeginPeriod(1);
	Random_Seed();
	_InitPowerStatus();
	_InputInit();
	if(!_GfxInit()) { System_Shutdown(); return false; }
	if(!_SoundInit()) { System_Shutdown(); return false; }

	System_Log("Init done.\n");

	fTime=0.0f;
	t0=t0fps=timeGetTime();
	dt=cfps=0;
	nFPS=0;

	// Show splash

#ifdef DEMO

	bool			(*func)();
	bool			(*rfunc)();
	HWND			hwndTmp;

	if(pHGE->bDMO)
	{
		Sleep(200);
		func=(bool(*)())pHGE->System_GetStateFunc(HGE_FRAMEFUNC);
		rfunc=(bool(*)())pHGE->System_GetStateFunc(HGE_RENDERFUNC);
		hwndTmp=hwndParent; hwndParent=0;
		pHGE->System_SetStateFunc(HGE_FRAMEFUNC, DFrame);
		pHGE->System_SetStateFunc(HGE_RENDERFUNC, 0);
		DInit();
		pHGE->System_Start();
		DDone();
		hwndParent=hwndTmp;
		pHGE->System_SetStateFunc(HGE_FRAMEFUNC, func);
		pHGE->System_SetStateFunc(HGE_RENDERFUNC, rfunc);
	}

#endif

	// Done

	return true;
}
示例#16
0
文件: system.cpp 项目: doveiya/isilme
void HGE_Impl::_PostError(char *error)
{
	System_Log(error);
	strcpy(szError,error);
}
示例#17
0
bool HGE_Impl::_GfxInit()
{
//	static const char *szFormats[]={"UNKNOWN", "R5G6B5", "X1R5G5B5", "A1R5G5B5", "X8R8G8B8", "A8R8G8B8"};
//	D3DADAPTER_IDENTIFIER9 AdID;
//	D3DDISPLAYMODE Mode;
//	D3DFORMAT Format=D3DFMT_UNKNOWN;
//	UINT nModes, i;

// Init Open GL
    /*
    	HDC hDC;
    	HGLRC hRC;
    	long gl_error;


    	hDC = GetDC(pHGE->hwnd);
    	hRC = wglCreateContext(hDC);

    	if (hRC == NULL)
    	{
    		System_Log("Creating GL Context Failed with error code: %d", GetLastError());
    		return false;
    	}

    	System_Log("Initializing Graphix");

    	wglMakeCurrent(hDC, hRC);
    */
    long gl_error;



    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        System_Log("GLEW init Error: %s\n", glewGetErrorString(err));
    }
    else
        System_Log("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

    if (!GLEW_EXT_framebuffer_object)
    {
        System_Log("Status: Unavailable Extension GL_EXT_framebuffer_object\n");
    }
    else
        System_Log("Status: GL_EXT_framebuffer_object is supportet\n");



    glShadeModel(GL_SMOOTH);						// Enables Smooth Shading
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);      // 4-byte pixel alignment

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


    glClearStencil(0);                          // clear stencil buffer
    glClearDepth(1.0f);								// Depth Buffer Setup


    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
//	glCullFace(GL_BACK);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
//	glDisable(GL_DEPTH_TEST);


    glDepthFunc(GL_LEQUAL);							// The Type Of Depth Test To Do

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);			// Really Nice Perspective Calculations



// Get adapter info

    System_Log("OpenGL version: %s", glGetString( GL_VERSION ));
//	System_Log("OpenGL version: %s", glGetString( GL_EXTENSIONS ));




// Set up Full Screen presentation parameters



    _AdjustWindow();

    System_Log("Mode: width = %d height = %d\n",nScreenWidth,nScreenHeight);

// Create vertex batch buffer

    textures=0;

// Init all stuff that can be lost

    _SetProjectionMatrix(nScreenWidth, nScreenHeight);

    if (GL_ERROR(gl_error))
    {
        System_Log("OpenGL error: %d", gl_error);
        return false;
    }

    if(!_init_lost()) return false;

    Gfx_Clear(0);

    System_Log("Graphix initialized");

    return true;
}