Exemplo n.º 1
0
int WINAPI QEW_SetupPixelFormat(HDC hDC, qboolean zbuffer )
{
    static PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),	// size of this pfd
		1,								              // version number
		PFD_DRAW_TO_WINDOW |			      // support window
		PFD_SUPPORT_OPENGL |			      // support OpenGL
		PFD_DOUBLEBUFFER,				        // double buffered
		PFD_TYPE_RGBA,					        // RGBA type
		24,								              // 24-bit 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,						          // accum bits ignored
		32,							                // depth bits
		0,								              // no stencil buffer
		0,								              // no auxiliary buffer
		PFD_MAIN_PLANE,					        // main layer
		0,								              // reserved
		0, 0, 0							            // layer masks ignored
    };                              //
    int pixelformat = 0;            

	zbuffer = true;
	if ( !zbuffer )
		pfd.cDepthBits = 0;

  if (g_PrefsDlg.m_bSGIOpenGL)
  {
    if ( (pixelformat = qwglChoosePixelFormat(hDC, &pfd)) == 0 )
    {
	    printf("%d",GetLastError());
      Error ("ChoosePixelFormat failed");
    }
  
    if (!qwglSetPixelFormat(hDC, pixelformat, &pfd))
      Error ("SetPixelFormat failed");
  }
  else
  {
    if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
    {
	    printf("%d",GetLastError());
      Error ("ChoosePixelFormat failed");
    }

    if (!SetPixelFormat(hDC, pixelformat, &pfd))
      Error ("SetPixelFormat failed");
  }

	return pixelformat;
}
Exemplo n.º 2
0
static int GLimp_InitGL( void )
{
	PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof( PIXELFORMATDESCRIPTOR ), // size of this pfd
		1,                      // version number
		PFD_DRAW_TO_WINDOW |    // support window
		PFD_SUPPORT_OPENGL |    // support OpenGL
		PFD_DOUBLEBUFFER,       // double buffered
		PFD_TYPE_RGBA,          // RGBA type
		32,                     // 32-bit 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,             // accum bits ignored
		24,                     // 32-bit z-buffer
		0,                      // no stencil buffer
		0,                      // no auxiliary buffer
		PFD_MAIN_PLANE,         // main layer
		0,                      // reserved
		0, 0, 0                 // layer masks ignored
	};
	int pixelformat;
	cvar_t *stereo;

	stereo = Cvar_Get( "cl_stereo", "0", 0 );

	pfd.cStencilBits = max( 0, r_stencilbits->integer );

	if( pfd.cStencilBits != 0 )
		glState.stencilEnabled = qtrue;
	else
		glState.stencilEnabled = qfalse;

	/*
	** set PFD_STEREO if necessary
	*/
	if( stereo->integer != 0 )
	{
		Com_Printf( "...attempting to use stereo\n" );
		pfd.dwFlags |= PFD_STEREO;
		glState.stereoEnabled = qtrue;
	}
	else
	{
		glState.stereoEnabled = qfalse;
	}

	/*
	** figure out if we're running on a minidriver or not
	*/
	if( strstr( gl_driver->string, "opengl32" ) != 0 )
		glw_state.minidriver = qfalse;
	else
		glw_state.minidriver = qtrue;

	/*
	** Get a DC for the specified window
	*/
	if( glw_state.hDC != NULL )
		Com_Printf( "GLimp_Init() - non-NULL DC exists\n" );

	if( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL )
	{
		Com_Printf( "GLimp_Init() - GetDC failed\n" );
		return qfalse;
	}

	if( glw_state.minidriver )
	{
		if( ( pixelformat = qwglChoosePixelFormat( glw_state.hDC, &pfd ) ) == 0 )
		{
			Com_Printf( "GLimp_Init() - qwglChoosePixelFormat failed\n" );
			return qfalse;
		}
		if( qwglSetPixelFormat( glw_state.hDC, pixelformat, &pfd ) == FALSE )
		{
			Com_Printf( "GLimp_Init() - qwglSetPixelFormat failed\n" );
			return qfalse;
		}
		qwglDescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );
	}
	else
	{
		if( ( pixelformat = ChoosePixelFormat( glw_state.hDC, &pfd ) ) == 0 )
		{
			Com_Printf( "GLimp_Init() - ChoosePixelFormat failed\n" );
			return qfalse;
		}
		if( SetPixelFormat( glw_state.hDC, pixelformat, &pfd ) == FALSE )
		{
			Com_Printf( "GLimp_Init() - SetPixelFormat failed\n" );
			return qfalse;
		}
		DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );

		if( !( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) )
		{
			extern cvar_t *r_allow_software;

			if( r_allow_software->integer )
				glw_state.mcd_accelerated = qtrue;
			else
				glw_state.mcd_accelerated = qfalse;
		}
		else
		{
			glw_state.mcd_accelerated = qtrue;
		}
	}

	/*
	** report if stereo is desired but unavailable
	*/
	if( !( pfd.dwFlags & PFD_STEREO ) && ( stereo->integer != 0 ) )
	{
		Com_Printf( "...failed to select stereo pixel format\n" );
		Cvar_SetValue( "cl_stereo", 0 );
		glState.stereoEnabled = qfalse;
	}

	/*
	** startup the OpenGL subsystem by creating a context and making
	** it current
	*/
	if( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 )
	{
		Com_Printf( "GLimp_Init() - qwglCreateContext failed\n" );
		goto fail;
	}

	if( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) )
	{
		Com_Printf( "GLimp_Init() - qwglMakeCurrent failed\n" );
		goto fail;
	}

	if( !VerifyDriver() )
	{
		Com_Printf( "GLimp_Init() - no hardware acceleration detected\n" );
		goto fail;
	}

	/*
	** print out PFD specifics
	*/
	Com_Printf( "GL PFD: color(%d-bits) Z(%d-bit) stencil(%d-bits)\n", ( int ) pfd.cColorBits, ( int ) pfd.cDepthBits, ( int )pfd.cStencilBits );

	return qtrue;

fail:
	if( glw_state.hGLRC )
	{
		qwglDeleteContext( glw_state.hGLRC );
		glw_state.hGLRC = NULL;
	}

	if( glw_state.hDC )
	{
		ReleaseDC( glw_state.hWnd, glw_state.hDC );
		glw_state.hDC = NULL;
	}
	return qfalse;
}
Exemplo n.º 3
0
/*
** GLW_MakeContext
*/
static int GLW_MakeContext( PIXELFORMATDESCRIPTOR *pPFD )
{
	int pixelformat;

	//
	// don't putz around with pixelformat if it's already set (e.g. this is a soft
	// reset of the graphics system)
	//
	if ( !glw_state.pixelFormatSet )
	{
		//
		// choose, set, and describe our desired pixel format.  If we're
		// using a minidriver then we need to bypass the GDI functions,
		// otherwise use the GDI functions.
		//
		if ( ( pixelformat = GLW_ChoosePFD( glw_state.hDC, pPFD ) ) == 0 )
		{
			ri.Printf( PRINT_ALL, "...GLW_ChoosePFD failed\n");
			return TRY_PFD_FAIL_SOFT;
		}
		ri.Printf( PRINT_ALL, "...PIXELFORMAT %d selected\n", pixelformat );

		if ( glConfig.driverType > GLDRV_ICD )
		{
			qwglDescribePixelFormat( glw_state.hDC, pixelformat, sizeof( *pPFD ), pPFD );
			if ( qwglSetPixelFormat( glw_state.hDC, pixelformat, pPFD ) == FALSE )
			{
				ri.Printf ( PRINT_ALL, "...qwglSetPixelFormat failed\n");
				return TRY_PFD_FAIL_SOFT;
			}
		}
		else
		{
			DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( *pPFD ), pPFD );

			if ( SetPixelFormat( glw_state.hDC, pixelformat, pPFD ) == FALSE )
			{
				ri.Printf (PRINT_ALL, "...SetPixelFormat failed\n", glw_state.hDC );
				return TRY_PFD_FAIL_SOFT;
			}
		}

		glw_state.pixelFormatSet = qtrue;
	}

	//
	// startup the OpenGL subsystem by creating a context and making it current
	//
	if ( !glw_state.hGLRC )
	{
		ri.Printf( PRINT_ALL, "...creating GL context: " );
		if ( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 )
		{
			ri.Printf (PRINT_ALL, "failed\n");

			return TRY_PFD_FAIL_HARD;
		}
		ri.Printf( PRINT_ALL, "succeeded\n" );

		ri.Printf( PRINT_ALL, "...making context current: " );
		if ( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) )
		{
			qwglDeleteContext( glw_state.hGLRC );
			glw_state.hGLRC = NULL;
			ri.Printf (PRINT_ALL, "failed\n");
			return TRY_PFD_FAIL_HARD;
		}
		ri.Printf( PRINT_ALL, "succeeded\n" );
	}

	return TRY_PFD_SUCCESS;
}
Exemplo n.º 4
0
static int SetupGL(int colorbits, int depthbits, int stencilbits, int multisamples)
{
    PIXELFORMATDESCRIPTOR pfd;
    int pixelformat;

    // create the main window
    Win_Init();

    if (colorbits == 0)
        colorbits = 24;

    if (depthbits == 0)
        depthbits = colorbits > 16 ? 24 : 16;

    if (depthbits < 24)
        stencilbits = 0;

    // choose pixel format
    if (qwglChoosePixelFormatARB && multisamples > 1) {
        int iAttributes[20];
        UINT numFormats;

        iAttributes[0] = WGL_DRAW_TO_WINDOW_ARB;
        iAttributes[1] = TRUE;
        iAttributes[2] = WGL_SUPPORT_OPENGL_ARB;
        iAttributes[3] = TRUE;
        iAttributes[4] = WGL_DOUBLE_BUFFER_ARB;
        iAttributes[5] = TRUE;
        iAttributes[6] = WGL_PIXEL_TYPE_ARB;
        iAttributes[7] = WGL_TYPE_RGBA_ARB;
        iAttributes[8] = WGL_COLOR_BITS_ARB;
        iAttributes[9] = colorbits;
        iAttributes[10] = WGL_DEPTH_BITS_ARB;
        iAttributes[11] = depthbits;
        iAttributes[12] = WGL_STENCIL_BITS_ARB;
        iAttributes[13] = stencilbits;
        iAttributes[14] = WGL_SAMPLE_BUFFERS_ARB;
        iAttributes[15] = 1;
        iAttributes[16] = WGL_SAMPLES_ARB;
        iAttributes[17] = multisamples;
        iAttributes[18] = 0;
        iAttributes[19] = 0;

        if (qwglChoosePixelFormatARB(win.dc, iAttributes, NULL, 1, &pixelformat, &numFormats) == FALSE) {
            ReportLastError("wglChoosePixelFormatARB");
            goto soft;
        }
        if (numFormats == 0) {
            Com_EPrintf("No suitable OpenGL pixelformat found for %d multisamples\n", multisamples);
            goto soft;
        }
    } else {
        memset(&pfd, 0, sizeof(pfd));
        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 = colorbits;
        pfd.cDepthBits = depthbits;
        pfd.cStencilBits = stencilbits;
        pfd.iLayerType = PFD_MAIN_PLANE;

        if (glw.minidriver) {
            if ((pixelformat = qwglChoosePixelFormat(win.dc, &pfd)) == 0) {
                ReportLastError("wglChoosePixelFormat");
                goto soft;
            }
        } else {
            if ((pixelformat = ChoosePixelFormat(win.dc, &pfd)) == 0) {
                ReportLastError("ChoosePixelFormat");
                goto soft;
            }
        }
    }

    // set pixel format
    if (glw.minidriver) {
        qwglDescribePixelFormat(win.dc, pixelformat, sizeof(pfd), &pfd);
        ReportPixelFormat(pixelformat, &pfd);

        if (qwglSetPixelFormat(win.dc, pixelformat, &pfd) == FALSE) {
            ReportLastError("wglSetPixelFormat");
            goto soft;
        }
    } else {
        DescribePixelFormat(win.dc, pixelformat, sizeof(pfd), &pfd);
        ReportPixelFormat(pixelformat, &pfd);

        if (SetPixelFormat(win.dc, pixelformat, &pfd) == FALSE) {
            ReportLastError("SetPixelFormat");
            goto soft;
        }
    }

    // check for software emulation
    if (pfd.dwFlags & PFD_GENERIC_FORMAT) {
        if (!gl_allow_software->integer) {
            Com_EPrintf("No hardware OpenGL acceleration detected\n");
            goto soft;
        }
        Com_WPrintf("...using software emulation\n");
    } else if (pfd.dwFlags & PFD_GENERIC_ACCELERATED) {
        Com_DPrintf("...MCD acceleration found\n");
        win.flags |= QVF_ACCELERATED;
    } else {
        Com_DPrintf("...ICD acceleration found\n");
        win.flags |= QVF_ACCELERATED;
    }

    // startup the OpenGL subsystem by creating a context and making it current
    if ((glw.hGLRC = qwglCreateContext(win.dc)) == NULL) {
        ReportLastError("wglCreateContext");
        goto hard;
    }

    if (qwglMakeCurrent(win.dc, glw.hGLRC) == FALSE) {
        ReportLastError("wglMakeCurrent");
        qwglDeleteContext(glw.hGLRC);
        glw.hGLRC = NULL;
        goto hard;
    }

    return FAIL_OK;

soft:
    // it failed, clean up
    Win_Shutdown();
    return FAIL_SOFT;

hard:
    Win_Shutdown();
    return FAIL_HARD;
}
Exemplo n.º 5
0
static unsigned GetFakeWindowExtensions(void)
{
    WNDCLASSEX wc;
    PIXELFORMATDESCRIPTOR pfd;
    int pixelformat;
    HWND wnd;
    HDC dc;
    HGLRC rc;
    unsigned extensions = 0;

    memset(&wc, 0, sizeof(wc));
    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc = DefWindowProc;
    wc.hInstance = hGlobalInstance;
    wc.lpszClassName = FAKE_WINDOW_CLASS;

    if (!RegisterClassEx(&wc))
        goto fail0;

    wnd = CreateWindow(
        FAKE_WINDOW_CLASS,
        FAKE_WINDOW_NAME,
        0,
        0, 0, 0, 0,
        NULL,
        NULL,
        hGlobalInstance,
        NULL);
    if (!wnd)
        goto fail1;

    if ((dc = GetDC(wnd)) == NULL)
        goto fail2;

    memset(&pfd, 0, sizeof(pfd));
    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 = 24;
    pfd.cDepthBits = 24;
    pfd.cStencilBits = 8;
    pfd.iLayerType = PFD_MAIN_PLANE;

    if (glw.minidriver) {
        if ((pixelformat = qwglChoosePixelFormat(dc, &pfd)) == 0)
            goto fail3;

        if (qwglSetPixelFormat(dc, pixelformat, &pfd) == FALSE)
            goto fail3;
    } else {
        if ((pixelformat = ChoosePixelFormat(dc, &pfd)) == 0)
            goto fail3;

        if (SetPixelFormat(dc, pixelformat, &pfd) == FALSE)
            goto fail3;
    }

    if ((rc = qwglCreateContext(dc)) == NULL)
        goto fail3;

    if (qwglMakeCurrent(dc, rc) == FALSE)
        goto fail4;

    WGL_InitExtensions(QWGL_ARB_extensions_string);

    if (!qwglGetExtensionsStringARB)
        goto fail5;

    extensions = WGL_ParseExtensionString(qwglGetExtensionsStringARB(dc));

    if (extensions & QWGL_ARB_pixel_format) {
        Com_Printf("...enabling WGL_ARB_pixel_format\n");
        WGL_InitExtensions(QWGL_ARB_pixel_format);
    }

fail5:
    qwglMakeCurrent(NULL, NULL);
fail4:
    qwglDeleteContext(rc);
fail3:
    ReleaseDC(wnd, dc);
fail2:
    DestroyWindow(wnd);
fail1:
    UnregisterClass(FAKE_WINDOW_CLASS, hGlobalInstance);
fail0:
    return extensions;
}
Exemplo n.º 6
0
qboolean GLimp_InitGL (void)
{
    PIXELFORMATDESCRIPTOR pfd = 
	{
		sizeof(PIXELFORMATDESCRIPTOR),	// size of this pfd
		1,								// version number
		PFD_DRAW_TO_WINDOW |			// support window
		PFD_SUPPORT_OPENGL |			// support OpenGL
		PFD_DOUBLEBUFFER,				// double buffered
		PFD_TYPE_RGBA,					// RGBA type
		32,								// 32-bit color depth // was 24
		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, 					// accum bits ignored
		//Knightmare 12/24/2001- stencil buffer
		24,								// 24-bit z-buffer, was 32	
		8,								// 8-bit stencil buffer
		//end Knightmare
		0,								// no auxiliary buffer
		PFD_MAIN_PLANE,					// main layer
		0,								// reserved
		0, 0, 0							// layer masks ignored
    };
    int  pixelformat;
	cvar_t *stereo;
	
	stereo = Cvar_Get( "cl_stereo", "0", 0 );

	/*
	** set PFD_STEREO if necessary
	*/
	if ( stereo->value != 0 )
	{
		VID_Printf( PRINT_ALL, "...attempting to use stereo\n" );
		pfd.dwFlags |= PFD_STEREO;
		gl_state.stereo_enabled = true;
	}
	else
	{
		gl_state.stereo_enabled = false;
	}

	/*
	** figure out if we're running on a minidriver or not
	*/
	if ( strstr( gl_driver->string, "opengl32" ) != 0 )
		glw_state.minidriver = false;
	else
		glw_state.minidriver = true;

	/*
	** Get a DC for the specified window
	*/
	if ( glw_state.hDC != NULL )
		VID_Printf( PRINT_ALL, "GLimp_Init() - non-NULL DC exists\n" );

    if ( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL )
	{
		VID_Printf( PRINT_ALL, "GLimp_Init() - GetDC failed\n" );
		return false;
	}

	if ( glw_state.minidriver )
	{
		if ( (pixelformat = qwglChoosePixelFormat( glw_state.hDC, &pfd)) == 0 )
		{
			VID_Printf (PRINT_ALL, "GLimp_Init() - qwglChoosePixelFormat failed\n");
			return false;
		}
		if ( qwglSetPixelFormat( glw_state.hDC, pixelformat, &pfd) == FALSE )
		{
			VID_Printf (PRINT_ALL, "GLimp_Init() - qwglSetPixelFormat failed\n");
			return false;
		}
		qwglDescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );
	}
	else
	{
		if ( ( pixelformat = ChoosePixelFormat( glw_state.hDC, &pfd)) == 0 )
		{
			VID_Printf (PRINT_ALL, "GLimp_Init() - ChoosePixelFormat failed\n");
			return false;
		}
		if ( SetPixelFormat( glw_state.hDC, pixelformat, &pfd) == FALSE )
		{
			VID_Printf (PRINT_ALL, "GLimp_Init() - SetPixelFormat failed\n");
			return false;
		}
		DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );

		if ( !( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) )
		{
			extern cvar_t *gl_allow_software;

			if ( gl_allow_software->value )
				glw_state.mcd_accelerated = true;
			else
				glw_state.mcd_accelerated = false;
		}
		else
		{
			glw_state.mcd_accelerated = true;
		}
	}

	/*
	** report if stereo is desired but unavailable
	*/
	if ( !( pfd.dwFlags & PFD_STEREO ) && ( stereo->value != 0 ) ) 
	{
		VID_Printf( PRINT_ALL, "...failed to select stereo pixel format\n" );
		Cvar_SetValue( "cl_stereo", 0 );
		gl_state.stereo_enabled = false;
	}

	/*
	** startup the OpenGL subsystem by creating a context and making
	** it current
	*/
	if ( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 )
	{
		VID_Printf (PRINT_ALL, "GLimp_Init() - qwglCreateContext failed\n");

		goto fail;
	}

    if ( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) )
	{
		VID_Printf (PRINT_ALL, "GLimp_Init() - qwglMakeCurrent failed\n");

		goto fail;
	}

	if ( !VerifyDriver() )
	{
		VID_Printf( PRINT_ALL, "GLimp_Init() - no hardware acceleration detected.\nPlease install drivers provided by your video card/GPU vendor.\n" );
		goto fail;
	}

	/*
	** print out PFD specifics 
	*/
	VID_Printf( PRINT_ALL, "PIXELFORMAT: color(%d-bits) Z(%d-bit)\n", ( int ) pfd.cColorBits, ( int ) pfd.cDepthBits );

	//Knightmare- Vic's hardware gamma stuff
	if ( !r_ignorehwgamma->value )
	{
		if( qwglGetDeviceGammaRamp3DFX )
		{
			WORD newramp[3*256];
			int j;

			gl_state.gammaRamp = qwglGetDeviceGammaRamp3DFX ( glw_state.hDC, newramp );

			for( j = 0; j < 256; j++ )
			{
				original_ramp[0][j] = newramp[j+0];
				original_ramp[1][j] = newramp[j+256];
				original_ramp[2][j] = newramp[j+512];
			}
		} else
		{
			gl_state.gammaRamp = GetDeviceGammaRamp ( glw_state.hDC, original_ramp );
		}
	}
	else
	{
		gl_state.gammaRamp = false;
	}

	if (gl_state.gammaRamp)
		vid_gamma->modified = true;

	// moved these to GL_SetDefaultState
	//gl_state.blend = false;
	//gl_state.alphaTest = false;
	//end Knightmare

	//Knightmare- 12/24/2001- stecil buffer
	{
		char buffer[1024];

		strcpy( buffer, qglGetString( GL_RENDERER ) );
		strlwr( buffer );
		if (strstr(buffer, "Voodoo3")) {
			VID_Printf( PRINT_ALL, "... Voodoo3 has no stencil buffer\n" );
			gl_config.have_stencil = false;
		} else {
			if (pfd.cStencilBits) {
				VID_Printf( PRINT_ALL, "... Using stencil buffer\n" );
				gl_config.have_stencil = true; // Stencil shadows - MrG
			}
		}
	}
	//if (pfd.cStencilBits)
	//	gl_config.have_stencil = true;
	//end Knightmare

/*	Moved to GL_SetDefaultState in r_glstate.c
	// Vertex arrays
	qglEnableClientState (GL_TEXTURE_COORD_ARRAY);
	qglEnableClientState (GL_VERTEX_ARRAY);
	qglEnableClientState (GL_COLOR_ARRAY);

	qglTexCoordPointer (2, GL_FLOAT, sizeof(texCoordArray[0][0]), texCoordArray[0][0]);
	qglVertexPointer (3, GL_FLOAT, sizeof(vertexArray[0]), vertexArray[0]);
	qglColorPointer (4, GL_FLOAT, sizeof(colorArray[0]), colorArray[0]);
	//gl_state.activetmu[0] = true;
	// end vertex arrays
*/

	return true;

fail:
	if ( glw_state.hGLRC )
	{
		qwglDeleteContext( glw_state.hGLRC );
		glw_state.hGLRC = NULL;
	}

	if ( glw_state.hDC )
	{
		ReleaseDC( glw_state.hWnd, glw_state.hDC );
		glw_state.hDC = NULL;
	}
	return false;
}
Exemplo n.º 7
0
qboolean GLimp_InitGL (void)
{
    PIXELFORMATDESCRIPTOR pfd =
    {
        sizeof(PIXELFORMATDESCRIPTOR),	// size of this pfd
        1,								// version number
        PFD_DRAW_TO_WINDOW |			// support window
        PFD_SUPPORT_OPENGL |			// support OpenGL
        PFD_DOUBLEBUFFER,				// double buffered
        PFD_TYPE_RGBA,					// RGBA type
        24,								// 24-bit 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, 					// accum bits ignored
        24,								// 32-bit z-buffer
        8,								// no stencil buffer
        0,								// no auxiliary buffer
        PFD_MAIN_PLANE,					// main layer
        0,								// reserved
        0, 0, 0							// layer masks ignored
    };
    int  pixelformat;
    cvar_t *stereo;

    stereo = Cvar_Get( "cl_stereo", "0", 0 );

    /*
    ** set PFD_STEREO if necessary
    */
    if (stereo->integer)
    {
        Com_Printf ( "...attempting to use stereo\n" );
        pfd.dwFlags |= PFD_STEREO;
        gl_state.stereo_enabled = true;
    }
    else
    {
        gl_state.stereo_enabled = false;
    }

    /*
    ** figure out if we're running on a minidriver or not
    */
    if (Q_stristr( gl_driver->string, "opengl32" ) != 0 )
        glw_state.minidriver = false;
    else
        glw_state.minidriver = true;

    /*
    ** Get a DC for the specified window
    */
    if ( glw_state.hDC != NULL )
        Com_Printf ( "GLimp_Init() - non-NULL DC exists\n" );

    if ( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL )
    {
        PrintWinError("GLimp_Init() - GetDC", false);
        return false;
    }

    if ( glw_state.minidriver )
    {
        if ( (pixelformat = qwglChoosePixelFormat( glw_state.hDC, &pfd)) == 0 )
        {
            PrintWinError("GLimp_Init() - wglChoosePixelFormat", false);
            return false;
        }
        if ( qwglSetPixelFormat( glw_state.hDC, pixelformat, &pfd) == FALSE )
        {
            PrintWinError("GLimp_Init() - wglSetPixelFormat", false);
            return false;
        }
        qwglDescribePixelFormat(glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );
    }
    else
    {
        if ((pixelformat = ChoosePixelFormat(glw_state.hDC, &pfd)) == 0)
        {
            PrintWinError("GLimp_Init() - ChoosePixelFormat", false);
            return false;
        }
        if (SetPixelFormat( glw_state.hDC, pixelformat, &pfd) == FALSE)
        {
            PrintWinError("GLimp_Init() - SetPixelFormat", false);
            return false;
        }
        DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );

        if ( !( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) )
        {
            extern cvar_t *gl_allow_software;

            if ( gl_allow_software->integer )
                glw_state.mcd_accelerated = true;
            else
                glw_state.mcd_accelerated = false;
        }
        else
        {
            glw_state.mcd_accelerated = true;
        }
    }

    /*
    ** report if stereo is desired but unavailable
    */
    if ( !( pfd.dwFlags & PFD_STEREO ) && ( stereo->value != 0 ) )
    {
        Com_Printf("...failed to select stereo pixel format\n");
        Cvar_Set("cl_stereo", "0");
        gl_state.stereo_enabled = false;
    }

    /*
    ** startup the OpenGL subsystem by creating a context and making
    ** it current
    */
    if ((glw_state.hGLRC = qwglCreateContext(glw_state.hDC)) == 0)
    {
        PrintWinError("GLimp_Init() - wglCreateContext", false);
        return false;
    }

    if (!qwglMakeCurrent(glw_state.hDC, glw_state.hGLRC))
    {
        PrintWinError("GLimp_Init() - wglMakeCurrent", false);
        return false;
    }

    if (!VerifyDriver())
    {
        Com_Error(ERR_FATAL, "GLimp_Init() - no hardware acceleration detected");
        return false;
    }

    /*
    ** print out PFD specifics
    */
    Com_Printf("GL PFD: Color(%dbits) Depth(%dbits) Stencil(%dbits)\n", (int)pfd.cColorBits, (int)pfd.cDepthBits, (int)pfd.cStencilBits);
    {
        char	buffer[1024];

        Q_strncpyz( buffer, (const char *)qglGetString( GL_RENDERER ), sizeof(buffer));
        Q_strlwr( buffer );

        gl_state.stencil = false;
        if (strstr(buffer, "voodoo3"))
        {
            Com_Printf("... Voodoo3 has no stencil buffer\n");
        }
        else
        {
            if (pfd.cStencilBits > 0)
            {
                Com_Printf("... Using stencil buffer\n");
                gl_state.stencil = true;	// Stencil shadows -MrG
            }
        }
    }

    return true;
}