예제 #1
0
/**
 * @return whether setting the video mode was successful
 * 
 * Sets SDL video mode options/settings
 */
bool SpringApp::SetSDLVideoMode ()
{
	int sdlflags = SDL_OPENGL | SDL_RESIZABLE;

	conditionally_set_flag(sdlflags, SDL_FULLSCREEN, fullscreen);

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
#ifdef __APPLE__
	const int defaultDepthSize = 32;
#else
	const int defaultDepthSize = 16;
#endif
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, configHandler.GetInt("DepthBufferBits", defaultDepthSize));
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	FSAA = MultisampleTest();

	SDL_Surface *screen = SDL_SetVideoMode(screenWidth,screenHeight,0,sdlflags);
	if (!screen) {
		handleerror(NULL,"Could not set video mode","ERROR",MBF_OK|MBF_EXCL);
		return false;
	}
	if (FSAA)
		FSAA = MultisampleVerify();

	SetVSync ();

	return true;
}
예제 #2
0
Game::Game(unsigned int windowWidth, unsigned int windowHeight, bool fullscreen, const char *title) : Application(windowWidth, windowHeight, fullscreen, title)
{
	m_nFramesPassed = 0;
	m_fTimePassed = 0.0f;
	m_fFPS = 0.0f;

	SetVSync(false);
	srand((unsigned int)time(nullptr));

	// Load in the textures that we want to use
	m_backgroundTexture = new Texture("./Images/background.png");
	m_mouseTexture = new Texture("./Images/Player.png");
	
	// Create the font for use with draw string
	m_font = new Font("./Fonts/calibri_24px.fnt");

	// Defaults for mouse X and Y
	m_v2MousePos.x = 0.0f;
	m_v2MousePos.y = 0.0f;
	m_fMouseRadius = 100.0f;

	Vector2 v2LevelTopLeft;
	v2LevelTopLeft.x = 0.0f;
	v2LevelTopLeft.y = 0.0f;
	Vector2 v2LevelBottomRight;
	v2LevelBottomRight.x = (float)windowWidth;
	v2LevelBottomRight.y = (float)windowHeight;

	// Spawn a grid of slightly randomly placed enemies.
	// First calculate how many enemies we can fit on the screen.
	m_MaxEnemiesPerRow = (windowWidth - SCREEN_PADDING_X) / ENEMY_SPACING;
	m_MaxEnemiesPerColumn = (windowHeight - SCREEN_PADDING_Y) / ENEMY_SPACING;
	m_EnemyCount = m_MaxEnemiesPerRow * m_MaxEnemiesPerColumn;

	//Instantiate the quadtree.
	gameTree = new Quadtree(0,0, v2LevelBottomRight.x, v2LevelBottomRight.y);

	// Create the enemies
	m_apEnemyList = new Enemy*[m_MaxEnemiesPerRow * m_MaxEnemiesPerColumn];
	for(int x = 0; x < m_MaxEnemiesPerRow; ++x)
	{
		for(int y = 0; y < m_MaxEnemiesPerColumn; ++y)
		{
			int index = (y * m_MaxEnemiesPerRow) + x;
			float posX = (float)SCREEN_PADDING_X + (x * ENEMY_SPACING);
			float posY = (float)SCREEN_PADDING_Y + (y * ENEMY_SPACING);

			posX += -ENEMY_SPACING + rand() % (ENEMY_SPACING * 2);
			posY += -(ENEMY_SPACING / 2) + rand() % (ENEMY_SPACING);

			m_apEnemyList[index] = new Enemy(posX, posY);

			//Add enemy to quadtree.
			gameTree->addEnemy(m_apEnemyList[index]);
		}
	}

}
예제 #3
0
void CRenderSystemGL::PresentRender(bool rendered, bool videoLayer)
{
  SetVSync(true);

  if (!m_bRenderCreated)
    return;

  PresentRenderImpl(rendered);

  if (!rendered)
    Sleep(40);
}
예제 #4
0
void CRenderSystemGLES::PresentRender(bool rendered, bool videoLayer)
{
  SetVSync(true);

  if (!m_bRenderCreated)
    return;

  PresentRenderImpl(rendered);

  // if video is rendered to a separate layer, we should not block this thread
  if (!rendered && !videoLayer)
    Sleep(40);
}
예제 #5
0
void CRenderSystemGL::PresentRender(bool rendered)
{
  SetVSync(true);

  if (!m_bRenderCreated)
    return;

  PresentRenderImpl(rendered);
  m_latencyCounter++;

  if (!rendered)
    Sleep(40);
}
Application::Application(unsigned int windowWidth, unsigned int windowHeight, bool fullscreen, const char *title)
{
	// Initialise member variables 
	//----------------------------------------------------------------------------
		m_windowWidth	= windowWidth;
		m_windowHeight	= windowHeight;
		m_gameOver		= false;

		m_currentTime	= (float)glfwGetTime();
		m_lastTime		= m_currentTime;
		m_deltaTime		= 0.0f;

		m_fps			= 0;
		m_fpsCount		= 0;
		m_fpsIntervial	= 0.0f;

		m_currentRenderTarget = nullptr;
	//----------------------------------------------------------------------------
	
	// Setup GLFW
	//----------------------------------------------------------------------------
	glfwInit();

	m_pWindow = glfwCreateWindow(windowWidth, windowHeight, title, (fullscreen ? glfwGetPrimaryMonitor() : NULL) , NULL);

	glfwMakeContextCurrent(m_pWindow);

	// Initialise openGL 
	//----------------------------------------------------------------------------
	
		// STEP 2: Initialise glew (gl extension wrangler)
		glewInit();

		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glEnable(GL_DEPTH);



	//----------------------------------------------------------------------------

	Input::CreateSingleton();

	SetVSync(true);

}
예제 #7
0
OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen) : 
	Super(hMonitor, width, height, bits, refreshHz, fullscreen) 
{
	GLRenderer = new FGLRenderer(this);
	memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256);
	UpdatePalette ();
	ScreenshotBuffer = NULL;
	LastCamera = NULL;

	InitializeState();
	gl_SetupMenu();
	gl_GenerateGlobalBrightmapFromColormap();
	DoSetGamma();
	needsetgamma = true;
	swapped = false;
	Accel2D = true;
	SetVSync(vid_vsync);
}
예제 #8
0
void WindowsHeadlessHost::InitGL()
{
	glOkay = false;
	hWnd = CreateHiddenWindow();

	if (WINDOW_VISIBLE)
	{
		ShowWindow(hWnd, TRUE);
		SetFocus(hWnd);
	}

	int pixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {0};
	pfd.nSize = sizeof(pfd);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 16;
	pfd.iLayerType = PFD_MAIN_PLANE;

#define ENFORCE(x, msg) { if (!(x)) { fprintf(stderr, msg); return; } }

	ENFORCE(hDC = GetDC(hWnd), "Unable to create DC.");
	ENFORCE(pixelFormat = ChoosePixelFormat(hDC, &pfd), "Unable to match pixel format.");
	ENFORCE(SetPixelFormat(hDC, pixelFormat, &pfd), "Unable to set pixel format.");
	ENFORCE(hRC = wglCreateContext(hDC), "Unable to create GL context.");
	ENFORCE(wglMakeCurrent(hDC, hRC), "Unable to activate GL context.");

	SetVSync(0);

	glewInit();
	glstate.Initialize();

	LoadNativeAssets();

	if (ResizeGL())
		glOkay = true;
}
예제 #9
0
void VCWindow::Initalize()
{
    std::cout << "Creating a VCWindow..." << std::endl;
    
	// =====   GLFW   ======================================================
	glfwSetErrorCallback(glewErrorCallback);

	if (!glfwInit())
	{
		std::cout << "Failed to initialize GLFW." << std::endl;
		std::cin.ignore();
	}
	 
	//glfwWindowHint(GLFW_DECORATED, false);
	//glfwWindowHint(GLFW_SAMPLES, 4);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#if DEBUG
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
#endif

	GLFWWindowHandle = glfwCreateWindow(1280, 600, "Thilenius - A 0.0.1", NULL, NULL);
	if (!GLFWWindowHandle)
	{
		glfwTerminate();
		std::cout << "Failed to create a window." << std::endl;
		std::cin.ignore();
	}

	glfwMakeContextCurrent(GLFWWindowHandle);

	// =====   GLEW   ======================================================
	glewExperimental = true;
	GLenum glewError = glewInit();
	if( glewError != GLEW_OK )
	{
		printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
		std::cin.ignore();
	}

	// =====   Debug   ======================================================
#if DEBUG
	glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
	glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
	glDebugMessageCallbackARB(&glDebugCallback, NULL);
#endif


	GLint major, minor;
	glGetIntegerv(GL_MAJOR_VERSION, &major); 
	glGetIntegerv(GL_MINOR_VERSION, &minor);
    std::cout << "OpenGL version: " << major << "." << minor << std::endl;
    std::cout << "Hardware: " << glGetString(GL_RENDERER) << std::endl << std::endl;
    
	glfwGetWindowSize(GLFWWindowHandle, &Width, &Height);
	FullViewport = VCRectangle(0, 0, Width, Height);
	
	SetVSync(false);
	std::cout << "VCWindow Initialized." << std::endl;
    glErrorCheck();

	VCInteropWindowSetPos(200, 200);
}
예제 #10
0
    bool App::Load()
    {
		// force size and vsync
		SetSize(SCREEN_WIDTH, SCREEN_HEIGHT);
		SetVSync(true);

		// set up basic OpenGL parameters
		GL_DEBUG(glClearColor(0.3f, 0.3f, 0.3f, 1.0f));
		GL_DEBUG(glEnable(GL_DEPTH_TEST));
		
		// load textures
		cubeTexture = g_Texture.LoadTexture("crate.png");
		baseTexture = g_Texture.LoadTexture("concrete2.jpg", true);

		// load shaders
		phongShader = g_Shader.CreateProgram("texPhong.vert", "texPhong.frag", 3,
											FF_ATTRIBUTE_VERTEX, "vVertex",
											FF_ATTRIBUTE_NORMAL, "vNormal",
											FF_ATTRIBUTE_TEXTURE0, "vTexture0");

		blurShader = g_Shader.CreateProgram("blur.vert", "blur.frag", 2,
											FF_ATTRIBUTE_VERTEX, "vVertex",
											FF_ATTRIBUTE_TEXTURE0, "vTexture0");

		// get locations for shader uniforms
		locTexture = GL_DEBUG(glGetUniformLocation(phongShader, "texSampler"));
		locLightPos = GL_DEBUG(glGetUniformLocation(phongShader, "lightPos"));
		locMV = GL_DEBUG(glGetUniformLocation(phongShader, "mvMatrix"));
		locMVP = GL_DEBUG(glGetUniformLocation(phongShader, "mvpMatrix"));
		locNM = GL_DEBUG(glGetUniformLocation(phongShader, "normalMatrix"));
		locAmbient = GL_DEBUG(glGetUniformLocation(phongShader, "ambient"));
		locDiffuse = GL_DEBUG(glGetUniformLocation(phongShader, "diffuse"));
		locSpecular = GL_DEBUG(glGetUniformLocation(phongShader, "specular"));
		locBlurMVP = GL_DEBUG(glGetUniformLocation(blurShader, "mvpMatrix"));

		// create geometry
		gltMakeCube(cube, 1);
		screen.Begin(GL_TRIANGLE_STRIP, 4, 1);
			screen.MultiTexCoord2f(0, 0, 0);
			screen.Vertex3f(0, 0, 0);
			screen.MultiTexCoord2f(0, 1, 0);
			screen.Vertex3f((float)GetWidth(), 0, 0);
			screen.MultiTexCoord2f(0, 0, 1);
			screen.Vertex3f(0, (float)GetHeight(), 0);
			screen.MultiTexCoord2f(0, 1, 1);
			screen.Vertex3f((float)GetWidth(), (float)GetHeight(), 0);
		screen.End();
		const float baseSize = 40.0f;
		const float baseHeight = -3.f;
		base.Begin(GL_TRIANGLE_STRIP, 8, 1);
			base.MultiTexCoord2f(0, 0, 0);
			base.Vertex3f(-baseSize, baseHeight, baseSize);
			base.MultiTexCoord2f(0, baseSize, 0);
			base.Vertex3f(baseSize, baseHeight, baseSize);
			base.MultiTexCoord2f(0, 0, baseSize);
			base.Vertex3f(-baseSize, baseHeight, -baseSize);
			base.MultiTexCoord2f(0, baseSize, baseSize);
			base.Vertex3f(baseSize, baseHeight, -baseSize);
			base.MultiTexCoord2f(0, 0, 0);
			base.Vertex3f(-baseSize, baseHeight, -baseSize);
			base.MultiTexCoord2f(0, baseSize, 0);
			base.Vertex3f(baseSize, baseHeight, -baseSize);
			base.MultiTexCoord2f(0, 0, baseSize);
			base.Vertex3f(-baseSize, baseHeight + baseSize, -baseSize);
			base.MultiTexCoord2f(0, baseSize, baseSize);
			base.Vertex3f(baseSize, baseHeight + baseSize, -baseSize);
		base.End();

		// create pixel buffer
		glGenBuffers(1, &pbo);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
		glBufferData(GL_PIXEL_PACK_BUFFER, PIXEL_DATA_SIZE, NULL, GL_DYNAMIC_DRAW);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

		// create blur textures
		glGenTextures(BLUR_TEXTURE_COUNT, blurTextures);
		for (int i = 0; i < BLUR_TEXTURE_COUNT; ++i)
		{
			glActiveTexture(GL_TEXTURE1 + i);
			glBindTexture(GL_TEXTURE_2D, blurTextures[i]);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
		}

		// set initial variables
		curBlurFrame = 0;
		blurTimer = 0;
		blurEnabled = true;
		moveBlur = false;
		cameraFrame.MoveForward(-10);
		return true;
	}
예제 #11
0
/**
 * @return whether setting the video mode was successful
 * 
 * Sets SDL video mode options/settings
 */
bool SpringApp::SetSDLVideoMode ()
{
	int sdlflags = SDL_OPENGL | SDL_RESIZABLE;

	//conditionally_set_flag(sdlflags, SDL_FULLSCREEN, fullscreen);
	sdlflags |= fullscreen ? SDL_FULLSCREEN : 0;

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

#ifdef __APPLE__
	const int defaultDepthSize = 32;
#else
	const int defaultDepthSize = 16;
#endif
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, configHandler.GetInt("DepthBufferBits", defaultDepthSize));
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, configHandler.GetInt("StencilBufferBits", 1));

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	FSAA = MultisampleTest();

	SDL_Surface *screen = SDL_SetVideoMode(screenWidth, screenHeight, 0, sdlflags);
	if (!screen) {
		char buf[1024];
		SNPRINTF(buf, sizeof(buf), "Could not set video mode:\n%s", SDL_GetError());
		handleerror(NULL, buf, "ERROR", MBF_OK|MBF_EXCL);
		return false;
	}

	// Something in SDL_SetVideoMode (OpenGL drivers?) messes with the FPU control word.
	// Set single precision floating point math.
	streflop_init<streflop::Simple>();

	if (FSAA) {
 		FSAA = MultisampleVerify();
	}

	// setup GL smoothing
	const int defaultSmooth = 0; // FSAA ? 0 : 3;  // until a few things get fixed
	const int lineSmoothing = configHandler.GetInt("SmoothLines", defaultSmooth);
	if (lineSmoothing > 0) {
		GLenum hint = GL_FASTEST;
		if (lineSmoothing >= 3) {
			hint = GL_NICEST;
		} else if (lineSmoothing >= 2) {
			hint = GL_DONT_CARE;
		}
		glEnable(GL_LINE_SMOOTH);
		glHint(GL_LINE_SMOOTH_HINT, hint);
	}
	const int pointSmoothing = configHandler.GetInt("SmoothPoints", defaultSmooth);
	if (pointSmoothing > 0) {
		GLenum hint = GL_FASTEST;
		if (pointSmoothing >= 3) {
			hint = GL_NICEST;
		} else if (pointSmoothing >= 2) {
			hint = GL_DONT_CARE;
		}
		glEnable(GL_POINT_SMOOTH);
		glHint(GL_POINT_SMOOTH_HINT, hint);
	}

	SetVSync();

	// there must be a way to see if this is necessary, compare old/new context pointers?
	if (!!configHandler.GetInt("FixAltTab", 0)) {
		// free GL resources
		GLContext::Free();

		// initialize any GL resources that were lost
		GLContext::Init();
	}

	// initialize the stencil
	glClearStencil(0);
	glClear(GL_STENCIL_BUFFER_BIT); SDL_GL_SwapBuffers();
	glClear(GL_STENCIL_BUFFER_BIT); SDL_GL_SwapBuffers();

	return true;
}
예제 #12
0
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name

	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}
	
	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen=FALSE;		// Windowed Mode Selected.  Fullscreen = FALSE
			}
			else
			{
				// Pop Up A Message Box Letting User Know The Program Is Closing.
				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return FALSE;									// Return FALSE
			}
		}
	}

	if (fullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		//ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		bits,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};
	
	if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(hRC=wglCreateContext(hDC)))				// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!wglMakeCurrent(hDC,hRC))					// Try To Activate The Rendering Context
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	ReSizeGLScene(width, height);					// Set Up Our Perspective GL Screen

	if (!InitGL())									// Initialize Our Newly Created GL Window
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	SetVSync(false);

	return TRUE;									// Success
}
예제 #13
0
파일: draw.c 프로젝트: bsv798/pcsxr
void SetExtGLFuncs(void)
{
 //----------------------------------------------------//

 SetFixes();                                           // update fix infos

 //----------------------------------------------------//

#ifdef _WINDOWS
 if((iForceVSync>=0) &&                                // force vsync?
    strstr((char *)glGetString(GL_EXTENSIONS),         // and extension available?
    "WGL_EXT_swap_control"))
  {
   PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT= 
    (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");

   if(wglSwapIntervalEXT) wglSwapIntervalEXT(iForceVSync);
  }
#endif
#ifdef _MACGL
    SetVSync(iForceVSync);
#endif
 if(iUseExts && !(dwActFixes&1024) &&                  // extensions wanted? and not turned off by game fix?
    strstr((char *)glGetString(GL_EXTENSIONS),         // and blend_subtract available?
    "GL_EXT_blend_subtract"))
     {                                                 // -> get ogl blend function pointer
#ifdef _WINDOWS
      glBlendEquationEXTEx=(PFNGLBLENDEQU)wglGetProcAddress("glBlendEquationEXT");
#elif defined(_MACGL)
    // no prob, OSX > 10.4.3 has this
#else
      glBlendEquationEXTEx=(PFNGLBLENDEQU)glXGetProcAddress("glBlendEquationEXT");
#endif
     }
 else                                                  // no subtract blending?
  {
   if(glBlendEquationEXTEx)                            // -> change to additive blending (if subract was active)
    glBlendEquationEXTEx(FUNC_ADD_EXT);
#if !defined(_MACGL) // BTW, why set to null? strange...
   glBlendEquationEXTEx=(PFNGLBLENDEQU)NULL;           // -> no more blend function pointer
#endif
  }

 //----------------------------------------------------//

 if(iUseExts && bAdvancedBlend &&                      // advanced blending wanted ?
    strstr((char *)glGetString(GL_EXTENSIONS),         // and extension avail?
           "GL_EXT_texture_env_combine"))
  {
   bUseMultiPass=FALSE;bGLBlend=TRUE;                  // -> no need for 2 passes, perfect

   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);    
   glTexEnvf(GL_TEXTURE_ENV, COMBINE_RGB_EXT, GL_MODULATE);     
   glTexEnvf(GL_TEXTURE_ENV, COMBINE_ALPHA_EXT, GL_MODULATE);     
   glTexEnvf(GL_TEXTURE_ENV, RGB_SCALE_EXT, 2.0f);    
  }
 else                                                  // no advanced blending wanted/available:
  {
   if(bAdvancedBlend) bUseMultiPass=TRUE;              // -> pseudo-advanced with 2 passes
   else               bUseMultiPass=FALSE;             // -> or simple 'bright color' mode
   bGLBlend=FALSE;                                     // -> no ext blending!

   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);    
  }

 //----------------------------------------------------//
 // init standard tex quality 0-2, and big alpha mode 3

 if(!(dwActFixes&0x4000) && iFilterType && iTexQuality>=3) 
      bSmallAlpha=TRUE;                  
 else bSmallAlpha=FALSE;

 if(bOpaquePass)                                        // opaque mode?
  {
   if(dwActFixes&32) 
    {
     TCF[0]=CP8RGBA_0;
     PalTexturedColourFn=CP8RGBA;                      // -> init col func
    }
   else
    {
     TCF[0]=XP8RGBA_0;
     PalTexturedColourFn=XP8RGBA;                      // -> init col func
    }

   TCF[1]=XP8RGBA_1;
   glAlphaFunc(GL_GREATER,0.49f);
  }
 else                                                  // no opaque mode?
  {
   TCF[0]=TCF[1]=P8RGBA;
   PalTexturedColourFn=P8RGBA;                         // -> init col func
   glAlphaFunc(GL_NOTEQUAL,0);                         // --> set alpha func
  }

 //----------------------------------------------------//

 LoadSubTexFn=LoadSubTexturePageSort;                  // init load tex ptr

 giWantedFMT=GL_RGBA;                                  // init ogl tex format

 switch(iTexQuality)                                   // -> quality:
  {
   //--------------------------------------------------// 
   case 0:                                             // -> don't care
    giWantedRGBA=4;
    giWantedTYPE=GL_UNSIGNED_BYTE;
    break;
   //--------------------------------------------------// 
   case 1:                                             // -> R4G4B4A4
    if(bGLExt)
     {
      giWantedRGBA=GL_RGBA4;
      giWantedTYPE=GL_UNSIGNED_SHORT_4_4_4_4_EXT;
      LoadSubTexFn=LoadPackedSubTexturePageSort;
      if(bOpaquePass) 
       {
        if(dwActFixes&32) PTCF[0]=CP4RGBA_0;
        else              PTCF[0]=XP4RGBA_0;
        PTCF[1]=XP4RGBA_1;
       }
      else      
       {
        PTCF[0]=PTCF[1]=P4RGBA;
       }
     }
    else
     {
      giWantedRGBA=GL_RGBA4;
      giWantedTYPE=GL_UNSIGNED_BYTE;
     }
    break;
   //--------------------------------------------------// 
   case 2:                                             // -> R5B5G5A1
    if(bGLExt)
     {
      giWantedRGBA=GL_RGB5_A1;
      giWantedTYPE=GL_UNSIGNED_SHORT_5_5_5_1_EXT;
      LoadSubTexFn=LoadPackedSubTexturePageSort;
      if(bOpaquePass) 
       {
        if(dwActFixes&32) PTCF[0]=CP5RGBA_0;
        else              PTCF[0]=XP5RGBA_0;
        PTCF[1]=XP5RGBA_1;
       }
      else   
       {
        PTCF[0]=PTCF[1]=P5RGBA;
       }
     }
    else
     {
      giWantedRGBA=GL_RGB5_A1;giWantedTYPE=GL_UNSIGNED_BYTE;
     }
    break;
   //--------------------------------------------------// 
   case 3:                                             // -> R8G8B8A8
    giWantedRGBA=GL_RGBA8;
    giWantedTYPE=GL_UNSIGNED_BYTE;

    if(bSmallAlpha)
     {
      if(bOpaquePass)                                  // opaque mode?
       {
        if(dwActFixes&32) {TCF[0]=CP8RGBAEx_0;PalTexturedColourFn=CP8RGBAEx;}
        else              {TCF[0]=XP8RGBAEx_0;PalTexturedColourFn=XP8RGBAEx;}
        TCF[1]=XP8RGBAEx_1;
       }
     }

    break;
   //--------------------------------------------------// 
   case 4:                                             // -> R8G8B8A8
    giWantedRGBA = GL_RGBA8;
    giWantedTYPE = GL_UNSIGNED_BYTE;

    if(strstr((char *)glGetString(GL_EXTENSIONS),      // and extension avail?
              "GL_EXT_bgra"))
     {
      giWantedFMT  = GL_BGRA_EXT;

      if(bOpaquePass)                                  // opaque mode?
       {
        if(bSmallAlpha)
         {
          if(dwActFixes&32) {TCF[0]=CP8BGRAEx_0;PalTexturedColourFn=CP8RGBAEx;}
          else              {TCF[0]=XP8BGRAEx_0;PalTexturedColourFn=XP8RGBAEx;}
          TCF[1]=XP8BGRAEx_1;
         }
        else
         {
          if(dwActFixes&32) {TCF[0]=CP8BGRA_0;PalTexturedColourFn=CP8RGBA;}
          else              {TCF[0]=XP8BGRA_0;PalTexturedColourFn=XP8RGBA;}
          TCF[1]=XP8BGRA_1;
         }
       }
      else                                             // no opaque mode?
       {
        TCF[0]=TCF[1]=P8BGRA;                          // -> init col func
       }
     }
    else
     {
      iTexQuality=3;
      if(bSmallAlpha)
       {
        if(bOpaquePass)                                 // opaque mode?
         {
          if(dwActFixes&32) {TCF[0]=CP8RGBAEx_0;PalTexturedColourFn=CP8RGBAEx;}
          else              {TCF[0]=XP8RGBAEx_0;PalTexturedColourFn=XP8RGBAEx;}
          TCF[1]=XP8RGBAEx_1;
         }
       }
     }

    break;
   //--------------------------------------------------// 
  }

 bBlendEnable=FALSE;                                   // init blending: off
 glDisable(GL_BLEND);

 SetScanTrans();                                       // init scan lines (if wanted)
}
void Application::ToggleVSync()
{
	SetVSync(!m_vSyncEnabled);
}
예제 #15
0
LRESULT CALLBACK WinProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
	unsigned char key;
	switch ( msg )
	{
		case WM_CREATE:
			if ( (hdc = GetDC(hwnd)) == NULL )				// get device context
			{
				MessageBox( hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK );
				SysShutdown();
				break;
			}

			SetGLFormat();					// select pixel format, needed before wglCreateContext call
			
			if ( (hglrc = wglCreateContext( hdc )) == NULL )	// create the rendering context
			{
				MessageBox( hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK );
				SysShutdown();
				break;
			}
			
			if ( wglMakeCurrent( hdc, hglrc ) == FALSE)		// make hglrc current rc
			{
				MessageBox( hwnd, "Failed to Make OpenGL Rendering Context Current", "OpenGL Rendering Context Error", MB_OK );
				SysShutdown();					
			}

			Resize( SCRWIDTH, SCRHEIGHT );

			SetVSync( 0 );  // turn off vsync.

			InitOpenGL();					// initialize OpenGL before showing the window

			ShowWindow( hwnd, SW_SHOW );	// everything went OK, show the window
			UpdateWindow( hwnd );
			break;			

		case WM_DESTROY:
			PostQuitMessage( 0 );
			break;
	
		case WM_SIZE:
			// resize the viewport after the window had been resized
			Resize( LOWORD( lparam ), HIWORD( lparam ) );
			
			screenw = LOWORD( lparam );
			screenh = HIWORD( lparam );			
			break;			

		case WM_KEYDOWN:
		case WM_SYSKEYDOWN:
			key = VirtualKeyToSysKey( wparam );
			keysDown[key] = 1;
			keysPressed[key] = 1; 
			break;			

		case WM_KEYUP:
		case WM_SYSKEYUP:
			key = VirtualKeyToSysKey( wparam );
			keysDown[key] = 0;
			break;
	}

	return DefWindowProc( hwnd, msg, wparam, lparam );
}