예제 #1
0
	void RenderSystem::v_Render()
	{
		static const GLfloat black[] ={0.2f, 0.3f, 0.4f, 1.0f };
		static const GLfloat one[] ={ 1.0f };
		glClearBufferfv(GL_COLOR, 0, black);
		glClearBufferfv(GL_DEPTH, 0, one);

		m_Font.Render("Graphics card: " + GetGLRenderer(), 10, windowInfo.Height - 20);
		m_Font.Render("GL Version: " + GetGLVersion(), 10, windowInfo.Height - 40);
		m_Font.Render("GLSL Version: " + GetGLSLVersion(), 10, windowInfo.Height - 60);
		m_Font.Render("FPS: " + std::to_string(m_Fps) , 10, 20);
	}
예제 #2
0
bool zglCoreContextWin::CreateCoreContext()
{
    if ( !m_tempContext )
        return false;

    bool makeCurResult = wglMakeCurrent( m_hDC, m_tempContext );

    bool bCore = GL_LoadCreateWinCoreContext();

    if (!bCore)
        return false;

    GetGLVersion(&m_major, &m_minor);

    if( !makeCurResult || m_major < MAJOR || ( m_major == MAJOR && m_minor < MINOR ) )
    {
        wglMakeCurrent(NULL,NULL);
        wglDeleteContext(m_tempContext);
        return false;
    }

    int attribs[] =
    {
        WGL_CONTEXT_MAJOR_VERSION_ARB, m_major,
        WGL_CONTEXT_MINOR_VERSION_ARB, m_minor,
        WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
        0
    };

    m_Context = wglCreateContextAttribsARB(m_hDC,0, attribs);

    if ( !m_Context )
        return false;

    LoadGL();

    wglMakeCurrent(NULL,NULL);
    wglDeleteContext(m_tempContext);

    return true;
}
예제 #3
0
float HumanClientApp::GLVersion() const
{ return GetGLVersion(); }
예제 #4
0
	int LoadFunctions()
	{
		int eCurrLoadStatus = LS_LOAD_FUNCTIONS_ALL;

		iMajorVersion = 0;
		iMinorVersion = 0;

		//Clear the extensions, in case we loaded already.
		gleIntClear();

		//Get the base functions that we need just to process OpenGL.
		gleIntLoadBaseFuncs();

		//Get the version numbers.
		GetGLVersion(&iMajorVersion, &iMinorVersion);

		if(iMajorVersion < 3)
		{
			//Load the 2.1 core.
			if(!gleIntLoad_Version_2_1()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
		}
		else if(iMajorVersion == 3 && iMinorVersion < 2)
		{
			switch(iMinorVersion)
			{
			case 0:
				if(!gleIntLoad_Version_3_0()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				break;
			case 1:
				//Check the ARB_compatibility extension.
				if(CheckCompatibilityExt())
				{
					if(!gleIntLoad_Version_3_1_Comp()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				}
				else
				{
					if(!gleIntLoad_Version_3_1()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				}
				break;
			}
		}
		else
		{
			int iProfileMask = 0;
			glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &iProfileMask);
			if(iProfileMask)
			{
				if(iProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
				{
					if(!gleIntLoad_Version_3_2_Comp()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				}
				else
				{
					if(!gleIntLoad_Version_3_2()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				}
			}
			else
			{
				//Hack to fix NVIDIA stupidity.
				if(CheckCompatibilityExt())
				{
					if(!gleIntLoad_Version_3_2_Comp()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				}
				else
				{
					if(!gleIntLoad_Version_3_2()) eCurrLoadStatus = LS_LOAD_FUNCTIONS_SOME;
				}
			}
		}

		//Now, process the extensions.
		//Use different methods if glGetStringi is available.
		if(iMajorVersion < 3)
		{
			ProcExtFromExtString((const char *)glGetString(GL_EXTENSIONS), gleIntExtensionMap, gleIntExtensionMapSize);
		}
		else
		{
			ProcExtFromList();
		}

		return eCurrLoadStatus;
	}
예제 #5
0
bool CGLDevice::Create30Context( const tInitStruct& initData )
{
	// store some variables
	m_hWnd = initData.hwnd;
	m_hDC = GetDC(m_hWnd);

	// choose PixelFormat
	PIXELFORMATDESCRIPTOR pfd; // Create a new PIXELFORMATDESCRIPTOR (PFD)
	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); // Clear our  PFD
	pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); // Set the size of the PFD to the size of the class
	pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; // Enable double buffering, opengl support and drawing to a window
	pfd.iPixelType = PFD_TYPE_RGBA; // Set our application to use RGBA pixels
	pfd.cColorBits = 32; // Give us 32 bits of color information (the higher, the more colors)
	pfd.cDepthBits = 32; // Give us 32 bits of depth information (the higher, the more depth levels)
	pfd.iLayerType = PFD_MAIN_PLANE; // Set the layer of the PFD

	int nPixelFormat = ChoosePixelFormat(m_hDC, &pfd); // Check if our PFD is valid and get a pixel format back
	if (nPixelFormat == 0) // If it fails
		return false;

	BOOL bResult = SetPixelFormat(m_hDC, nPixelFormat, &pfd); // Try and set the pixel format based on our PFD
	if (bResult == 0) // If it fails
		return false;

	HGLRC tempOpenGLContext = wglCreateContext(m_hDC); // Create an OpenGL 2.1 context for our device context
	wglMakeCurrent(m_hDC, tempOpenGLContext); // Make the OpenGL 2.1 context current and active

	// init GLEW (Have to be done after create a default Context)
	GLenum error = glewInit(); // Enable GLEW
	if (error != GLEW_OK) // If GLEW fails
		return false;

	// get OpenGL version
	int32_t major, minor;
	GetGLVersion(major, minor);

	// *note* highly suggested to use CORE_PROFILE instead of COMPATIBLE_PROFILE
	uint32_t context_flags = WGL_CONTEXT_DEBUG_BIT_ARB
		//| WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB // Set our OpenGL context to be forward compatible
		;

	int attributes[] = {
		WGL_CONTEXT_MAJOR_VERSION_ARB, major, // Set the MAJOR version of OpenGL to 4
		WGL_CONTEXT_MINOR_VERSION_ARB, minor, // Set the MINOR version of OpenGL to 2
		// *note* highly suggested to use CORE_PROFILE instead of COMPATIBLE_PROFILE
		WGL_CONTEXT_FLAGS_ARB, context_flags,
		WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
		0
	};

	if (wglewIsSupported("WGL_ARB_create_context") == 1) { // If the OpenGL 3.x context creation extension is available
		m_hRC = wglCreateContextAttribsARB(m_hDC, NULL, attributes); // Create and OpenGL 3.x context based on the given attributes
		wglMakeCurrent(NULL, NULL); // Remove the temporary context from being active
		wglDeleteContext(tempOpenGLContext); // Delete the temporary OpenGL 2.1 context
		wglMakeCurrent(m_hDC, m_hRC); // Make our OpenGL 3.0 context current
	}
	else {
		m_hRC = tempOpenGLContext; // If we didn't have support for OpenGL 3.x and up, use the OpenGL 2.1 context
	}

	int glVersion[2] = {-1, -1}; // Set some default values for the version
	glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]); // Get back the OpenGL MAJOR version we are using
	glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]); // Get back the OpenGL MAJOR version we are using

	Debug::Print((boost::wformat(TEXT("Using OpenGL: %1%.%2%")) % glVersion[0] % glVersion[1])); // Output which version of OpenGL we are using

	// setup debug context
	if (context_flags & WGL_CONTEXT_DEBUG_BIT_ARB)
	{
		if (glDebugMessageCallback)
		{
			auto func = &CGLDevice::GLDebugCallback;
			glDebugMessageCallback(func, nullptr);
		}
	}

	// get window info
	glm::vec2 vp_size = BackBufferSize();
	glViewport(0,0,(int32_t)vp_size.x, (int32_t)vp_size.y);

	// setup v-sync
	// http://www.3dbuzz.com/forum/threads/188320-Enable-or-Disable-VSync-in-OpenGL
	if(wglSwapIntervalEXT)
	{
		if(initData.bWaitForVSync)
		{
			wglSwapIntervalEXT(1);
		}
		else
		{
			wglSwapIntervalEXT(0);
		}
	}

	return true;
}