예제 #1
0
bool Application::InitOpenGL()
{
#ifdef WIN32
	wglSwapIntervalEXT_Func wglSwapIntervalEXT = (wglSwapIntervalEXT_Func)wglGetProcAddress("wglSwapIntervalEXT");
	if(wglSwapIntervalEXT) wglSwapIntervalEXT(Globals.VP.Vsync);//1 - чтобы включить
	else FASSERT (wglSwapIntervalEXT);
#else
#error Linux is not supported yet
#endif
	LF.Logf("InitOpenGL","Vsync status : %d",Globals.VP.Vsync);
	//===[ Инициализация всякой фигни ]===================================================||
		Cam.Init();
	//===[ Наинициализировались ]=========================================================||
	glClearColor(0.0f, 0.0f, 0.25f, 0.0f);
							// Очистка экрана в черный цвет
	glClearDepth(1.0);		// Разрешить очистку буфера глубины
	glDepthFunc(GL_LESS);	// Тип теста глубины (рисуется всё что ближе)
	glEnable(GL_DEPTH_TEST);// разрешить тест глубины
	glShadeModel(GL_SMOOTH);// разрешить плавное цветовое сглаживание
	ReshapeWindow(Globals.VP.Width,Globals.VP.Height);
	glEnable(GL_TEXTURE_2D);	// Разрешение наложения текстур
	glClearDepth(1.0f);           // Установка буфера глубины
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Улучшенные вычисления перспективы
	glDisable(GL_POLYGON_SMOOTH);
	glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
	glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
	glEnable(GL_DITHER);
	//glEnable(GL_CULL_FACE);
	//==== Свет ==========================================================================//
	glEnable(GL_LIGHT1); // Разрешение источника света номер один
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);		// Установка Фонового Света
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);		// Установка Диффузного Света
	glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);	// Позиция света
	glEnable(GL_LIGHTING);
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,0.0);
	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
	//=== /Свет ==========================================================================//

	return	NO_ERROR;
}
예제 #2
0
bool Application::GetSysInfo()
{
// ===[ Видео акселератор ]===================================================================================
	glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,&SysInfo.video.MaxAnisotropy);
	SysInfo.video.RendererName	= (char *)glGetString(GL_RENDERER);					// Выводим имя карты
	LF.Logf("GetSysInfo","Render            %s",SysInfo.video.RendererName);
	SysInfo.video.VendorName	= (char *)glGetString(GL_VENDOR);					// Выводим имя поставщика
	LF.Logf("GetSysInfo","Vendor            %s",SysInfo.video.VendorName);
	SysInfo.video.OpenGL_Version= (char *)glGetString(GL_VERSION);					// Выводим версию
	LF.Logf("GetSysInfo","OpenGL version is %s",SysInfo.video.OpenGL_Version);
	SysInfo.video.SupportedGlExtentions = (char *)glGetString(GL_EXTENSIONS);
	//LF.Msg("Найденые расширения видеокарты"); LF.Msg(SysInfo.video.SupportedGlExtentions);
// ===[ Процессор::реестр ]=======================================================================================
#ifdef WIN32
	HKEY CPinfo;
	FASSERT(!RegOpenKeyEx(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",NULL,KEY_QUERY_VALUE,&CPinfo));
	DWORD bufsize = sizeof(SysInfo.cpu.speed);
	RegQueryValueEx(CPinfo,"~MHz",NULL,NULL,(LPBYTE)&SysInfo.cpu.speed,&bufsize);
	LF.Logf("GetSysInfo","CPU speed is %d (by M$ Windows)",SysInfo.cpu.speed);
	bufsize = sizeof(SysInfo.cpu.id);
	RegQueryValueEx(CPinfo,"Identifier",NULL,NULL,(LPBYTE)&SysInfo.cpu.id,&bufsize);
	LF.Logf("GetSysInfo","CPU identifier \"%s\"",SysInfo.cpu.id);
	bufsize = sizeof(SysInfo.cpu.name);
	RegQueryValueEx(CPinfo,"ProcessorNameString",NULL,NULL,(LPBYTE)&SysInfo.cpu.name,&bufsize);
	LF.Logf("GetSysInfo","CPU name  \"%s\" ",SysInfo.cpu.name);
	bufsize = sizeof(SysInfo.cpu.vendor_id);
	RegQueryValueEx(CPinfo,"VendorIdentifier",NULL,NULL,(LPBYTE)&SysInfo.cpu.vendor_id,&bufsize);
	LF.Logf("GetSysInfo","Vendor ID \"%s\"",SysInfo.cpu.vendor_id);
	RegCloseKey(CPinfo);
		// Расширения процессора
	char fichi[128];
	sprintf(fichi,"Supported extentions: ");
	SysInfo.cpu.MMX			= (char)IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)	;
	if (SysInfo.cpu.MMX) strcat(fichi," MMX");
	SysInfo.cpu.AMD_3DNow	= (char)IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE)	;
	if (SysInfo.cpu.AMD_3DNow) strcat(fichi," AMD_3DNow");
	SysInfo.cpu.RDTSC		= (char)IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE)	;
	if (SysInfo.cpu.RDTSC) strcat(fichi," RDTSC");
	SysInfo.cpu.SSE			= (char)IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE)	;
	if (SysInfo.cpu.SSE) strcat(fichi," SSE");
	SysInfo.cpu.SSE2		= (char)IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE);
	if (SysInfo.cpu.SSE2) strcat(fichi," SSE2");
	LF.Logf("GetSysInfo","%s",fichi);
#else
// ===[ Процессор::ассемблер ]====================================================================================
	unsigned __int64 ticks;
	ticks = GetCycleCount();
	Sleep (TIME_TO_CALCULATE_CPU_SPEED);
	ticks = GetCycleCount() - ticks;
	SysInfo.cpu.speed = int ((float)ticks /(TIME_TO_CALCULATE_CPU_SPEED * 1000.0f));
	LF.Logf("GetSysInfo","CPU speed is %d (by ASM)",SysInfo.cpu.speed);
	union CPUID_string_union_type{
		char name [16];
		struct{
			DWORD a,b,c,zero;
		};
	}			CPU_name;
	DWORD a,b,c;								// Временные переменные для доставания имени процессора
	memset (&CPU_name,0,sizeof(CPU_name));
	DWORD	CPU_features,						// Возможности процессора 32 бита
			CPU_data_1,							// Данные о прецессоре первые 32 бита
			CPU_data_2;							// Данные о прецессоре вторые 32 бита
	__asm {
		mov EAX, 00000000h						// Имя вендора процессора
		CPUID
		mov a,EBX
		mov b,EDX
		mov c,ECX

		mov EAX, 00000001h
		CPUID
		mov CPU_features,	EDX
		mov CPU_data_1,		EBX
		mov CPU_data_2,		ECX
	};	CPU_name.a = a;	CPU_name.b = b;	CPU_name.c = c;
	LF.Logf("GetSysInfo","CPU_name            %s",CPU_name.name);

#define SOPROCESSOR_ENABLED		0x1			//	00000000000000000000000000000001
#define RDTSC_ENABLED			0x8			//	00000000000000000000000000001000
#define MMX_ENABLED				0x400000	//	00000000010000000000000000000000
#define SSE_ENABLED				0x800000	//	00000000100000000000000000000000
#define SSE2_ENABLED			0x1000000	//	00000001000000000000000000000000
#define AMD_3D_NOW_ENABLED		0x40000000	//	01000000000000000000000000000000
#define AMD_3D_NOW_Ex_ENABLED	0x80000000	//	10000000000000000000000000000000
#pragma warning (disable:4127)
	if (CPU_features & RDTSC_ENABLED)			SysInfo.cpu.RDTSC		= true;
	if (CPU_features & MMX_ENABLED)				SysInfo.cpu.MMX			= true;
	if (CPU_features & SSE_ENABLED)				SysInfo.cpu.SSE			= true;
	if (CPU_features & SSE2_ENABLED)			SysInfo.cpu.SSE2		= true;
	if (CPU_features & AMD_3D_NOW_ENABLED)		SysInfo.cpu.AMD_3DNow	= true;
	if (CPU_features & AMD_3D_NOW_Ex_ENABLED)	SysInfo.cpu.AMD_3DNow_Ex= true;
#pragma warning (default:4127)
	char fichi[128];
	sprintf(fichi,"Supported extentions: ");
	if (SysInfo.cpu.SSE)				strcat(fichi," SSE");
	if (SysInfo.cpu.SSE2)				strcat(fichi," SSE2");
	if (SysInfo.cpu.MMX)				strcat(fichi," MMX");
	if (SysInfo.cpu.AMD_3DNow)			strcat(fichi," AMD_3DNow");
	if (SysInfo.cpu.AMD_3DNow_Ex)		strcat(fichi," AMD_3DNow_Ex");
	if (SysInfo.cpu.RDTSC)				strcat(fichi," RDTSC");
	LF.Logf("GetSysInfo","%s",fichi);
#endif
	//if (!SysInfo.cpu.RDTSC) {MessageBox(NULL,"Your CPU not supported RDTSC instruction\nYou are crazy???","You need new CPU",MB_OK|MB_ICONERROR); ExitProcess(1);}
	return NO_ERROR;
}
예제 #3
0
bool Application::Birth()
{
	CoInitializeEx(NULL,NULL);
	Globals.Exiting	=	false;
	srand(GetTickCount());
	Input::I = new Input::Input_t;
	//===[ КОНФИГУРАЦИЯ ]===========================================================================
		ReadConfig();
	//===[ КОНФИГУРАЦИЯ ]===========================================================================	
	CCons.INIT();
#ifdef WIN32
	WNDCLASSEX wc;
	DWORD dwExStyle;
	DWORD dwStyle;
	RECT WindowRect;

	WindowRect.left = 0L;
	WindowRect.top	= 0L;
	WindowRect.right = Globals.VP.Width;
	WindowRect.bottom = Globals.VP.Height;

	Application::Vars.App.HInstance = GetModuleHandle(NULL);
	memset(&wc,0,sizeof(WNDCLASSEX));
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
	wc.lpfnWndProc = (WNDPROC) WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = Application::Vars.App.HInstance;
	wc.hIcon = LoadIcon(Application::Vars.App.HInstance,MAKEINTRESOURCE(IDI_ICON1));
	wc.hIconSm = LoadIcon(Application::Vars.App.HInstance,MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor = LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);//NULL;
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = MY_WINDOW_CLASS_NAME;

	FASSERT(RegisterClassEx(&wc));
	if(IsFullScreen)
	{
		EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&Application::Vars.win.PrevDS);
		memset(&Application::Vars.win.CurrDS, 0, sizeof(Application::Vars.win.CurrDS));
		Application::Vars.win.CurrDS.dmSize = sizeof(Application::Vars.win.CurrDS);
		Application::Vars.win.CurrDS.dmPelsWidth = Globals.VP.Width;
		Application::Vars.win.CurrDS.dmPelsHeight = Globals.VP.Height;
		Application::Vars.win.CurrDS.dmBitsPerPel = Globals.VP.Bits;
		Application::Vars.win.CurrDS.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY;
		Application::Vars.win.CurrDS.dmDisplayFrequency=Globals.VP.Hzs;

		if(ChangeDisplaySettings(&Application::Vars.win.CurrDS,CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			if(MessageBox(0, "Cannot run in fullscreen mode!\nRun in window?",
				"Hardware trouble!", MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
			{
				IsFullScreen = false;
			}
			else 
			{
				MessageBox(0, "OK!!! I'm quit...", "!!!", MB_OK | MB_ICONQUESTION);
				PostQuitMessage(1);
				return NO_ERROR;
			};
		};
	};

	if(IsFullScreen)
	{
			dwExStyle	= WS_EX_APPWINDOW/* | WS_EX_TOPMOST*/; // WS_EX_TOPMOST - Поверх всех окон
			dwStyle		= WS_POPUP;
	}
	else
	{
// ВНИМАНИЕ Здесь обнаружены глюки при использовании nView от nVidia!
			dwExStyle	= WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
			dwStyle		= WS_OVERLAPPEDWINDOW;
	};
	ShowCursor(false);
	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
	if (WindowRect.left < 0)
		WindowRect.right -= WindowRect.left,WindowRect.left = 0;
	if (WindowRect.top < 0)
		WindowRect.bottom -= WindowRect.top,WindowRect.top = 0;
	Application::Vars.win.MHWnd =
			CreateWindowEx(		dwExStyle, 
								MY_WINDOW_CLASS_NAME,
								MY_WINDOW_NAME,
								dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
								WindowRect.left,
								WindowRect.top,
								WindowRect.right - WindowRect.left,
								WindowRect.bottom - WindowRect.top,
								NULL,
								NULL,
								GetModuleHandle(0),
								NULL
								);
	FASSERT(Application::Vars.win.MHWnd);
	ShowWindow(Application::Vars.win.MHWnd, SW_SHOW);
	SetForegroundWindow(Application::Vars.win.MHWnd);
	SetFocus(Application::Vars.win.MHWnd);

	// Получаем контекст устройства
	Application::Vars.win.DC = GetDC(Application::Vars.win.MHWnd);
		FASSERT(Application::Vars.win.DC);
	// Установка формата пикселей
		PIXELFORMATDESCRIPTOR mainPFD;
		memset(&mainPFD,0,sizeof(PIXELFORMATDESCRIPTOR));
		mainPFD.nSize			= sizeof(PIXELFORMATDESCRIPTOR);
		mainPFD.nVersion		= 1;
		mainPFD.iPixelType		= PFD_TYPE_RGBA;
		mainPFD.dwFlags			= PFD_DRAW_TO_WINDOW |PFD_DOUBLEBUFFER |PFD_SUPPORT_OPENGL;
		mainPFD.iLayerType		= PFD_MAIN_PLANE;
		mainPFD.cDepthBits		=	16;
		int PF;
		PF = ChoosePixelFormat(Application::Vars.win.DC,&mainPFD);
		FASSERT(PF);	// Выбрали!
		FASSERT(SetPixelFormat(Application::Vars.win.DC,PF,&mainPFD));			// Поставили!
	// Создание контекста рендера
		Application::Vars.win.RC = wglCreateContext (Application::Vars.win.DC);
		FASSERT(Application::Vars.win.RC);
	// Установка полученого контекста главным
		FASSERT(wglMakeCurrent (Application::Vars.win.DC, Application::Vars.win.RC));
#else
		dpy = XOpenDisplay(0);						// Открываем дисплей по-умолчанию (может быть сетевой)
		vi = glXChooseVisual(	dpy,				// Получаем подходящий визуал
								DefaultScreen(dpy),
								attributeList);
		cx = glXCreateContext(dpy, vi, 0, GL_TRUE);	// Создание контекста
		// create	a color	map
		cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
				 vi->visual, AllocNone);
		// Создаём окно
		swa.colormap = cmap;
		swa.border_pixel = 0;
		swa.event_mask = StructureNotifyMask;
		win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 100, 100,
			  0, vi->depth,	InputOutput, vi->visual,
			  CWBorderPixel|CWColormap|CWEventMask,	&swa);
		XMapWindow(dpy, win);
		XIfEvent(dpy, &event, WaitForNotify, (char*)win);

		
		glXMakeCurrent(dpy, win, cx);				// Привязка контекста к окну
#endif
		GetSysInfo();
#ifndef	_DEBUG
		if (AVIp.Open("data/VIDEO/logo.avi") == FJC_NO_ERROR)
		{
			AVIp.Caching();
			GT.Start();
			ShowMovie(true);
			AVIp.CloseAVI();
		}
		else
		{
			LF.Logf("Birth","Невозможно загрузить и проиграть заставку");
		}
#endif
	// Инициализация библиотек и глобальных объектов
		InitOpenGL();						// Графика - OpenGL
		LF.Log("BIRTH","Init OpenGL complete");
		InitOpenIL();						// Поддержка изображений - OpenIL(DevIL)
		LF.Log("BIRTH","Init OpenIL complete");
// инициализация менеджера ресурсов		
		rm.INIT("Consolas.LFont","default.png","cube.lwo");
		CCons.SetFont(rm.SELECT_Font("Console"));

		SimpleLogo.init(&SwapBuffersEXT,IL_PNG,"data/textures/Logos/NewLOGO.PNG");
		SimpleLogo.render_logo(FJC_STARTUP_LOGO_MODE_BEGIN);
		rm.SELECT_Font("Courier")->SetColor(1,0,0);
		SimpleLogo.render_logo(	FJC_STARTUP_LOGO_MODE_PROCEED_WITH_TEXT,1,
								TextBlock(rm.SELECT_Font("Consolas"),"Now loading, please wait",250.0f,300.0f));
		Sound.Init();
		TestBuf.Init();
		TestBuf.LoadWav("data/sounds/KDE_Startup_new2.wav");
		TestSource.Init();
		TestSource.LinkWithBufer(&TestBuf);
		LF.Log("BIRTH","Init OpenAL complete");
		InitMATH();							// Математическая библиотека
		LF.Log("BIRTH","InitMATH");
		LF.Msg("Init complete");
		LoadResources();
		PS.INIT();
	return NO_ERROR;
};