• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ChoosePixelFormat函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ChoosePixelFormat函数的典型用法代码示例。如果您正苦于以下问题:C++ ChoosePixelFormat函数的具体用法?C++ ChoosePixelFormat怎么用?C++ ChoosePixelFormat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ChoosePixelFormat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: CreateWindowGL

void CreateWindowGL (gl_window_t *win)									// This Code Creates Our OpenGL Window
{
	__int64	timer;														// Holds High Resolution Timer Information
	DWORD windowStyle = WS_OVERLAPPEDWINDOW;							// Define Our Window Style
	DWORD windowExtendedStyle = WS_EX_APPWINDOW;						// Define The Window's Extended Style

	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
		win->init.bitsPerPixel,										// 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
	};

	RECT windowRect = {0, 0, win->init.width, win->init.height};	// Define Our Window Coordinates

	GLuint PixelFormat;													// Will Hold The Selected Pixel Format

	if (win->init.isFullScreen == TRUE)								// Fullscreen Requested, Try Changing Video Modes
	{
		if (ChangeScreenResolution (win->init.width, win->init.height, win->init.bitsPerPixel) == FALSE)
		{
			// Fullscreen Mode Failed.  Run In Windowed Mode Instead
			MessageBox (HWND_DESKTOP, "Mode Switch Failed.\nRunning In Windowed Mode.", "Error", MB_OK | MB_ICONEXCLAMATION);
			win->init.isFullScreen = FALSE;							// Set isFullscreen To False (Windowed Mode)
		}
		else															// Otherwise (If Fullscreen Mode Was Successful)
		{
			ShowCursor (FALSE);											// Turn Off The Cursor
			windowStyle = WS_POPUP;										// Set The WindowStyle To WS_POPUP (Popup Window)
			windowExtendedStyle |= WS_EX_TOPMOST;						// Set The Extended Window Style To WS_EX_TOPMOST
		}																// (Top Window Covering Everything Else)
	}
	else																// If Fullscreen Was Not Selected
	{
		// Adjust Window, Account For Window Borders
		AdjustWindowRectEx (&windowRect, windowStyle, 0, windowExtendedStyle);
	}

	// Create The OpenGL Window
	win->hWnd = CreateWindowExA (windowExtendedStyle,					// Extended Style
								   win->init.application->className,	// Class Name
								   win->init.title,					// Window Title
								   windowStyle,							// Window Style
								   win->init.left, win->init.top,								// Window X,Y Position
								   windowRect.right - windowRect.left,	// Window Width
								   windowRect.bottom - windowRect.top,	// Window Height
								   HWND_DESKTOP,						// Desktop Is Window's Parent
								   0,									// No Menu
								   win->init.application->hInstance, // Pass The Window Instance
								   win);

	if (win->hWnd == 0)												// Was Window Creation A Success?
	{
		win->isCreated = FALSE;
		return;
	}

	win->hDC = GetDC (win->hWnd);									// Grab A Device Context For This Window
	if (win->hDC == 0)												// Did We Get A Device Context?
	{
		// Failed
		DestroyWindow (win->hWnd);									// Destroy The Window
		win->hWnd = 0;												// Zero The Window Handle
		win->isCreated = FALSE;
		return;													// Return False
	}

	PixelFormat = ChoosePixelFormat (win->hDC, &pfd);				// Find A Compatible Pixel Format
	if (PixelFormat == 0)												// Did We Find A Compatible Format?
	{
		// Failed
		ReleaseDC (win->hWnd, win->hDC);							// Release Our Device Context
		win->hDC = 0;												// Zero The Device Context
		DestroyWindow (win->hWnd);									// Destroy The Window
		win->hWnd = 0;												// Zero The Window Handle
		win->isCreated = FALSE;
		return;													// Return False
	}

	if (SetPixelFormat (win->hDC, PixelFormat, &pfd) == FALSE)		// Try To Set The Pixel Format
	{
		// Failed
		ReleaseDC (win->hWnd, win->hDC);							// Release Our Device Context
		win->hDC = 0;												// Zero The Device Context
		DestroyWindow (win->hWnd);									// Destroy The Window
//.........这里部分代码省略.........
开发者ID:kungfooman,项目名称:easygl,代码行数:101,代码来源:NeHeGL.cpp


示例2: throw


//.........这里部分代码省略.........
            tmp += "rgba";

        DJV_LOG(context->debugLog(), "djvWglContext",
                QString("Pixel format %1: %2 %3/%4/%5/%6/%7").
                arg(i).
                arg(tmp.join(" ")).
                arg(pixelFormatInfo.cColorBits).
                arg(pixelFormatInfo.cRedBits).
                arg(pixelFormatInfo.cGreenBits).
                arg(pixelFormatInfo.cBlueBits).
                arg(pixelFormatInfo.cAlphaBits));
    }

    PIXELFORMATDESCRIPTOR pixelFormat =
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
        PFD_TYPE_RGBA,
        32,
        0, 0, 0, 0, 0, 0,
        0,
        0,
        0,
        0, 0, 0, 0,
        0,
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0, 0, 0
    };

    int pixelFormatId = ChoosePixelFormat(_p->device, &pixelFormat);

    //DJV_DEBUG_PRINT("pixel format = " << pixelFormatId);

    DJV_LOG(context->debugLog(), "djvWglContext",
            QString("Chosen pixel format: %1").arg(pixelFormatId));

    if (! pixelFormatId)
    {
        throw djvError(
            "djvWglContext",
            errorLabels()[ERROR_GET_PIXEL_FORMAT].arg(int(GetLastError())));
    }

    if (! SetPixelFormat(_p->device, pixelFormatId, &pixelFormat))
    {
        throw djvError(
            "djvWglContext",
            errorLabels()[ERROR_SET_PIXEL_FORMAT].arg(int(GetLastError())));
    }

    // Create OpengGL context.

    DJV_LOG(context->debugLog(), "djvWglContext", "Creating OpenGL context...");

    _p->context = wglCreateContext(_p->device);

    if (! _p->context)
    {
        throw djvError(
            "djvWglContext",
            errorLabels()[ERROR_CREATE_CONTEXT].arg(int(GetLastError())));
    }
开发者ID:sobotka,项目名称:djv-view,代码行数:67,代码来源:djvWglContextPrivate.cpp


示例3: WIN_GL_SetupWindow


//.........这里部分代码省略.........
	}

	if ( this->gl_config.stereo ) {
		*iAttr++ = WGL_STEREO_ARB;
		*iAttr++ = GL_TRUE;
	}

	if ( this->gl_config.multisamplebuffers ) {
		*iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
		*iAttr++ = this->gl_config.multisamplebuffers;
	}

	if ( this->gl_config.multisamplesamples ) {
		*iAttr++ = WGL_SAMPLES_ARB;
		*iAttr++ = this->gl_config.multisamplesamples;
	}

	if ( this->gl_config.accelerated >= 0 ) {
		*iAttr++ = WGL_ACCELERATION_ARB;
		*iAttr++ = (this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : WGL_NO_ACCELERATION_ARB);
	}

	*iAttr = 0;

	for ( i=0; ; ++i ) {
		/* Get the window device context for our OpenGL drawing */
		GL_hdc = GetDC(SDL_Window);
		if ( GL_hdc == NULL ) {
			SDL_SetError("Unable to get DC for SDL_Window");
			return(-1);
		}

		/* Choose and set the closest available pixel format */
		pixel_format = ChoosePixelFormatARB(this, iAttribs, fAttribs);
		if ( !pixel_format ) {
			pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
		}
		if ( !pixel_format ) {
			SDL_SetError("No matching GL pixel format available");
			return(-1);
		}
		if ( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) {
			if ( i == 0 ) {
				/* First time through, try resetting the window */
				if ( WIN_GL_ResetWindow(this) < 0 ) {
					return(-1);
				}
				continue;
			}
			SDL_SetError("Unable to set HDC pixel format");
			return(-1);
		}
		/* We either succeeded or failed by this point */
		break;
	}
	DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd);

	GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
	if ( GL_hrc == NULL ) {
		SDL_SetError("Unable to create GL context");
		return(-1);
	}
	if ( WIN_GL_MakeCurrent(this) < 0 ) {
		return(-1);
	}
	gl_active = 1;
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:67,代码来源:SDL_wingl.c


示例4: sizeof

int CGraphics::InitAll() {
	GLuint PixelFormat; //Contiene el formato de pixel

	static PIXELFORMATDESCRIPTOR pfd= //Contiene la informacion del formato del pixel
	{
		sizeof(PIXELFORMATDESCRIPTOR), //Tamaño de este descriptor
			1,
			PFD_DRAW_TO_WINDOW | //Formato que soporte Windows
			PFD_SUPPORT_OPENGL | //Formato que soporte OpenGL
			PFD_DOUBLEBUFFER, //Soporta doble buffering
			PFD_TYPE_RGBA, //Peticion de un formato RGBA
			16, // Selecciona el color de la profundidad
			0, 0, 0, 0, 0, 0, //Bits de Color Ignorado
			0, // No Alpha Buffer
			0, // Shift Bit Ignorado
			0, // Buffer de no acumulacion
			0, 0, 0, 0, //Bits de acumulacion ignorados
			16, //16bit Z Buffer (Buffer de profundidad)
			0, //No Stencil Buffer
			0, //No Auxiliary Buffer
			PFD_MAIN_PLANE, //Capa principal de dibujo
			0, //Reservado
			0,0,0 //Mascaras de capa ignoradas
	};

	if (!(hDC=GetDC(GetHWND()))) { //Se obtuvo un contexto de dispositivo?
		MessageBox(NULL, L"It couldn't get window Context", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) {//Windows encontro un formato de pixel similar?
		MessageBox(NULL, L"Non suitable pixel format found", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {//Se pudo iniciar el formato de pixel?
		MessageBox(NULL, L"It couldn't set pixel format", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!(hRC=wglCreateContext(hDC))) {//Conseguimos el contexto para renderear?
		MessageBox(NULL, L"It was not possible to create GL Context", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	if(!wglMakeCurrent(hDC,hRC)) {//Intento de activar el contexto de rendering
		MessageBox(NULL, L"It was not possible to set current GL Context", L"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return -1;
	}

	GLfloat blanco[]= {1.0f,1.0f,1.0f,1.0f};
	//GLfloat LightPosition[]={220.0f,-200.0f,220.0f,1.0f};


	glEnable(GL_LINE_SMOOTH);
	glEnable (GL_LIGHTING);
	glEnable (GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	
	// Buffer de profundidad 
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST); //Habilida la prueba de profundidad
	
	glDepthFunc(GL_LEQUAL); // Tipo de prueba

	glEnable(GL_NORMALIZE);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Mejora la perspectiva

	glClearColor(1.0f, 1.0f, 1.0f, 0); //Pone el color del fondo a gris	

	glLightfv(GL_LIGHT0, GL_DIFFUSE, blanco);
	glEnable (GL_LIGHT0);

	Size();

	return 0;
}
开发者ID:vlopezsa,项目名称:gvoldesc,代码行数:78,代码来源:Graphics.cpp


示例5: OSGL_createOpenGLWindow

void OSGL_createOpenGLWindow(uintf width, uintf height)
{	// Create a temporary window so we can query some values from the video driver
	int nPF;
	HDC				tmphDC;				// Temporary device context
	HGLRC			tmphRC;				// Temporary Renderring Context
	WNDCLASS		tmpWc;				// Temporary Windows class structure
	HWND			tmphWnd;			// Temporary Window Handle
	uintf			iMode;

	// Register Window style
    tmpWc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    tmpWc.lpfnWndProc	= (WNDPROC) wgl_tmpWndProc;
    tmpWc.cbClsExtra	= 0;
    tmpWc.cbWndExtra	= 0;
    tmpWc.hInstance 	= winVars.hinst;
    tmpWc.hIcon			= NULL;
    tmpWc.hCursor		= LoadCursor(NULL, IDC_ARROW);
    tmpWc.hbrBackground	= NULL;										// No need for background brush for OpenGL window
    tmpWc.lpszMenuName	= NULL;
    tmpWc.lpszClassName	= "Windows GL Temp Window";
    if(RegisterClass(&tmpWc) == 0)
		wglError(wgltxt_regClass1);
	tmphWnd = CreateWindowEx(WS_EX_TOPMOST, tmpWc.lpszClassName, tmpWc.lpszClassName, WS_POPUP, 0, 0, 400, 400, NULL, NULL, winVars.hinst, NULL);
	if(tmphWnd == NULL)
		wglError(wgltxt_noWindow1);
	ShowWindow(tmphWnd,SW_SHOW);
	UpdateWindow(tmphWnd);

	PIXELFORMATDESCRIPTOR pfd =		// Not going to be too picky
	{   sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,		// Full color
		32,					// Color depth
		0,0,0,0,0,0,0,		// Ignored
		0,0,0,0,		    // Accumulation buffer
		24,					// Depth bits
		8,					// Stencil bits
		0,0,0,0,0,0 };		// Some used, some not

	// Create a "temporary" OpenGL rendering context
	tmphDC = GetDC(tmphWnd);

	// Set pixel format one time....
	nPF = ChoosePixelFormat(tmphDC, &pfd);
	SetPixelFormat(tmphDC, nPF, &pfd);
	DescribePixelFormat(tmphDC, nPF, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

	// Create the GL context
	tmphRC = wglCreateContext(tmphDC);
	wglMakeCurrent(tmphDC, tmphRC);

	// Find a multisampled and non-multisampled pixel format
	wgl_FindBestPF(tmphDC, &wgl_PixelFormatSTD, &wgl_PixelFormatFSAA);

	iMode = 0;
	int bestMode = 0;
	int bestScore = 0x7FFFFFFF;
	while (EnumDisplaySettings(NULL, iMode, &wgl_devMode))
	{	int score = 1;
		if (wgl_devMode.dmBitsPerPel!=32) score *= 256;
		int xDif = abs((int)(wgl_devMode.dmPelsWidth - width))+1;
		int yDif = abs((int)(wgl_devMode.dmPelsHeight - height))+1;
		score *= xDif * yDif;
		if (score<bestScore)
		{	bestScore = score;
			bestMode = iMode;
		}
		iMode++;
	}
	EnumDisplaySettings(NULL, bestMode, &wgl_devMode);
	wgl_PrefFSWidth = wgl_devMode.dmPelsWidth;			// Preferred fullscreen width, height
	wgl_PrefFSHeight = wgl_devMode.dmPelsHeight;

	// ###!!!### The system is picking it's own window width and height! This HACK code fixed that
	wgl_PrefFSWidth = wgl_devMode.dmPelsWidth = width;			// Preferred fullscreen width, height
	wgl_PrefFSHeight = wgl_devMode.dmPelsHeight = height;

	// Done with GL context
	wglMakeCurrent(tmphDC, NULL);
	wglDeleteContext(tmphRC);
	DestroyWindow(tmphWnd);

	// ***************** Now create the real OGL window
	wgl_createMyWindow(OSGL_isFullScreen, &winVars.mainWin);
	// If window was not created, quit
	if(winVars.mainWin == NULL)
		wglError(wgltxt_noWindow2);

	MSG			msg;				// Windows message structure
	while (applicationState!=AppState_running)
	{	GetMessage(&msg, NULL, 0, 0);
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	OSGL_onWinCreate(winVars.mainWin);
}
开发者ID:gavindi,项目名称:Stephen-Fraser-FC-Engine,代码行数:97,代码来源:WGL_renderer.cpp


示例6: createGLWindow

int createGLWindow(HINSTANCE hInstance, LPCTSTR className)
{
		hWindow = CreateWindow(
							className,
							"GraphicsGame",
							WS_OVERLAPPEDWINDOW|WS_VISIBLE,
							CW_USEDEFAULT, CW_USEDEFAULT,
							windowWidth, windowHeight,	
							NULL,
							NULL,
							hInstance,
							NULL
							);
		if(!hWindow)
		{
		killWindow(className);
			MessageBox(hWindow, "Couldnt Create Window", "Error", MB_OK);
			return false;
		}
		hDeviceContext = GetDC(hWindow);
		if(!hDeviceContext)
		{
			killWindow(className);
			MessageBox(hWindow, "Could Create Device Context", "Error", MB_OK);
			return false;
		}
		PIXELFORMATDESCRIPTOR pfd = {};
		pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
		pfd.nVersion = 1;
		pfd.dwFlags = PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_DOUBLEBUFFER;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 24;
		pfd.cDepthBits = 24;
		pfd.iLayerType = PFD_MAIN_PLANE;
		int pixelFormat = ChoosePixelFormat(hDeviceContext, &pfd);
		if(!pixelFormat)
		{
			killWindow(className);
			MessageBox(hWindow, "Couldnt Select Good Pixel Format", "Error", MB_OK);
			return false;
		}
		if(!SetPixelFormat(hDeviceContext, pixelFormat, &pfd))
		{
			killWindow(className);
			MessageBox(hWindow, "Couldnt Select Good Pixel Format", "Error", MB_OK);
			return false;
		}
		GLRenderContext = wglCreateContext(hDeviceContext);
		if(!GLRenderContext)
		{
			killWindow(className);
			MessageBox(hWindow, "Couldnt make opengl context", "Error", MB_OK);
			return false;
		}
		if(!wglMakeCurrent(hDeviceContext, GLRenderContext))
		{
			killWindow(className);
			MessageBox(hWindow, "Couldnt make gl context current", "Error", MB_OK);
			return false;
		}

		return true;
}
开发者ID:Mcphylus12,项目名称:Graphics1_Game,代码行数:63,代码来源:Game.cpp


示例7: __glutCreateWindow

GLUTwindow *
__glutCreateWindow(GLUTwindow * parent,
  int x, int y, int width, int height)
{
  GLUTwindow *window;
  XSetWindowAttributes wa;
  unsigned long attribMask;
  int winnum;
  int i;

#if defined(WIN32)
  WNDCLASS wc;
  if (!GetClassInfo(GetModuleHandle(NULL), "GLUT", &wc))
    __glutOpenWin32Connection(NULL);
#else
  if (!__glutDisplay)
    __glutOpenXConnection(NULL);
#endif
  winnum = getUnusedWindowSlot();
  window = (GLUTwindow *) malloc(sizeof(GLUTwindow));
  if (!window)
    __glutFatalError("out of memory.");
  window->num = winnum;

#if !defined(WIN32)
  window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
    &window->visAlloced);
  if (!window->vis) {
    __glutFatalError(
      "visual with necessary capabilities not found.");
  }
  __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
#endif
  window->eventMask = StructureNotifyMask | ExposureMask;

  attribMask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
  wa.background_pixmap = None;
  wa.border_pixel = 0;
  wa.colormap = window->cmap;
  wa.event_mask = window->eventMask;
  if (parent) {
    if (parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
      wa.event_mask |= GLUT_HACK_STOP_PROPAGATE_MASK;
    attribMask |= CWDontPropagate;
    wa.do_not_propagate_mask = parent->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
  } else {
    wa.do_not_propagate_mask = 0;
  }

  /* Stash width and height before Win32's __glutAdjustCoords
     possibly overwrites the values. */
  window->width = width;
  window->height = height;
  window->forceReshape = True;

#if defined(WIN32)
  __glutAdjustCoords(parent ? parent->win : NULL, &x, &y, &width, &height);
  window->win = XCreateWindow(__glutDisplay,
    parent == NULL ? __glutRoot : parent->win,
    x, y, width, height, 0,
    0, InputOutput, 0,
    attribMask, &wa);
  window->hdc = GetDC(window->win);
  /* Must set the XHDC for fake glXChooseVisual & fake
     glXCreateContext & fake XAllocColorCells. */
  XHDC = window->hdc;
  window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
    &window->visAlloced);
  if (!window->vis) {
    __glutFatalError(
      "visual with necessary capabilities not found.");
  }
  if (!SetPixelFormat(window->hdc,
      ChoosePixelFormat(window->hdc, window->vis),
      window->vis))
    __glutFatalError("SetPixelFormat() failed in glutCreateWindow().");
  __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
  /* Make sure subwindows get a windowStatus callback. */
  if (parent)
    PostMessage(parent->win, WM_ACTIVATE, 0, 0);
#else
  window->win = XCreateWindow(__glutDisplay,
    parent == NULL ? __glutRoot : parent->win,
    x, y, width, height, 0,
    window->vis->depth, InputOutput, window->vis->visual,
    attribMask, &wa);
#endif
  window->renderWin = window->win;
  window->ctx = glXCreateContext(__glutDisplay, window->vis,
    None, __glutTryDirect);
  if (!window->ctx) {
    __glutFatalError(
      "failed to create OpenGL rendering context.");
  }
  window->renderCtx = window->ctx;
#if !defined(WIN32)
  window->isDirect = glXIsDirect(__glutDisplay, window->ctx);
  if (__glutForceDirect) {
    if (!window->isDirect)
      __glutFatalError("direct rendering not possible.");
//.........这里部分代码省略.........
开发者ID:hiteshsathawane,项目名称:Cube-Rotation,代码行数:101,代码来源:glut_win.c


示例8: CreateGLWindow


//.........这里部分代码省略.........
			}
		}
	}

	if (g_bFullscreen)
	{
		dwExStyle = WS_EX_APPWINDOW;
        dwStyle   = WS_POPUP;
		ShowCursor(FALSE);
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		dwStyle   = WS_OVERLAPPEDWINDOW; 
	}

	AdjustWindowRectEx(&wndRect,dwStyle,FALSE,dwExStyle);

	g_hMainWnd = CreateWindowEx (dwExStyle, 
		g_strClassName, 
		title,
		WS_CLIPCHILDREN|
		WS_CLIPSIBLINGS|
		dwStyle,
		0, 0, 
		wndRect.right - wndRect.left, 
		wndRect.bottom- wndRect.top, 
		NULL, 
		NULL, 
		g_hInst,
		NULL); 
	if (!g_hMainWnd)
	{
		MessageBox(NULL,TEXT("´´½¨´°¿Úʧ°Ü"),TEXT("Error"),MB_OK | MB_ICONERROR);
		KillWindow();
		return FALSE;
	}

	static PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),					// ÉÏÊö¸ñʽÃèÊö·ûµÄ´óС
		1,								                // °æ±¾ºÅ
		PFD_DRAW_TO_WINDOW |				     		// ¸ñʽ֧³Ö´°¿Ú
		PFD_SUPPORT_OPENGL |			     			// ¸ñʽ±ØÐëÖ§³ÖOpenGL
		PFD_DOUBLEBUFFER,				        		// ±ØÐëÖ§³ÖË«»º³å
		PFD_TYPE_RGBA,						        	// ÉêÇë RGBA ¸ñʽ
		bits,						            		// Ñ¡¶¨É«²ÊÉî¶È
		0, 0, 0, 0, 0, 0,						        // ºöÂÔµÄÉ«²Êλ
		0,							                 	// ÎÞAlpha»º´æ
		0,							                	// ºöÂÔShift Bit
		0,							                	// ÎÞÀÛ¼Ó»º´æ
		0, 0, 0, 0,					             		// ºöÂÔ¾Û¼¯Î»
		16,							                 	// 16λ Z-»º´æ (Éî¶È»º´æ)
		0,						                		// ÎÞÃɰ建´æ
		0,						                		// ÎÞ¸¨Öú»º´æ
		PFD_MAIN_PLANE,			          				// Ö÷»æͼ²ã
		0,							                	// Reserved
		0, 0, 0					             			// ºöÂÔ²ãÕÚÕÖ

	};

	if ((g_hdc = GetDC(g_hMainWnd)) == NULL)
	{
		MessageBox(NULL,TEXT("GetDC ´íÎó"),TEXT("Error"),MB_OK | MB_ICONERROR);
		KillWindow();
		return FALSE;
	}
	if (!(PixelFormat =ChoosePixelFormat(g_hdc,&pfd)))
	{
		MessageBox(NULL,TEXT("ChoosePixelFormat ´íÎó"),TEXT("Error"),MB_OK | MB_ICONERROR	);
		KillWindow();
		return FALSE;
	}
	if (! SetPixelFormat(g_hdc,PixelFormat,&pfd))
	{
		MessageBox(NULL,TEXT("SetPixelFormat ´íÎó"),TEXT("Error"),MB_OK | MB_ICONERROR	);
		KillWindow();
		return FALSE;
	}
	if (!(g_hGlrc = wglCreateContext(g_hdc)))
	{
		MessageBox(NULL,TEXT("´´½¨OpenGLÉÏÏÂÎÄ´íÎó"),TEXT("Error"),MB_OK | MB_ICONERROR	);
		KillWindow();
		return FALSE;
	}
	if(! wglMakeCurrent(g_hdc,g_hGlrc))
	{
		MessageBox(NULL,TEXT("wglMakeCurrent´íÎó"),TEXT("Error"),MB_OK | MB_ICONERROR	);
		KillWindow();
		return FALSE;
	}

	SetForegroundWindow(g_hMainWnd);
	SetFocus(g_hMainWnd);
	ShowWindow (g_hMainWnd, SW_SHOW);
	ResizeFunc(width,height);

	return InitOpenGL();
	//UpdateWindow (g_hMainWnd);
}
开发者ID:Wali8822,项目名称:SceneNav,代码行数:101,代码来源:main.cpp


示例9: GetModuleHandle

	bool Window::PlatformInit()
	{
		hInstance = (HINSTANCE)&__ImageBase;

		WNDCLASS winClass = {};
		winClass.hInstance = hInstance; // GetModuleHandle(0);
		winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
		winClass.lpfnWndProc = (WNDPROC)WndProc;
		winClass.lpszClassName = "Sparky Win32 Window";
		winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
		winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);

		if (!RegisterClassA(&winClass))
		{
			// TODO: Handle error
			SPARKY_ERROR("Could not register Win32 class!");
			return false;
		}

		RECT size = { 0, 0, m_Width, m_Height };
		AdjustWindowRectEx(&size, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, false, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);

		hWnd = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
			winClass.lpszClassName, m_Title,
			WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
			GetSystemMetrics(SM_CXSCREEN) / 2 - m_Width / 2,
			GetSystemMetrics(SM_CYSCREEN) / 2 - m_Height / 2,
			// TODO: This requires some... attention
			size.right + (-size.left), size.bottom + (-size.top), NULL, NULL, hInstance, NULL);
			
		if (!hWnd)
		{
			SPARKY_ERROR("Could not create window!");
			return false;
		}

		RegisterWindowClass(hWnd, this);

		hDc = GetDC(hWnd);
		PIXELFORMATDESCRIPTOR pfd = get_pixel_format();
		int pixelFormat = ChoosePixelFormat(hDc, &pfd);
		if (pixelFormat)
		{
			if (!SetPixelFormat(hDc, pixelFormat, &pfd))
			{
				SPARKY_ERROR("Failed setting pixel format!");
				return false;
			}
		}
		else
		{
			SPARKY_ERROR("Failed choosing pixel format!");
			return false;
		}

		HGLRC hrc = wglCreateContext(hDc);
		if (hrc)
		{
			if (!wglMakeCurrent(hDc, hrc))
			{
				SPARKY_ERROR("Failed setting OpenGL context!");
				return false;
			}
		}
		else
		{
			SPARKY_ERROR("Failed creating OpenGL context!");
			return false;
		}

		if (glewInit() != GLEW_OK)
		{
			SPARKY_FATAL("Could not initialize GLEW!");
			return false;
		}

		ShowWindow(hWnd, SW_SHOW);
		SetFocus(hWnd);
		// resize

		return true;
	}
开发者ID:Aymore2,项目名称:Sparky,代码行数:82,代码来源:Win32Window.cpp


示例10: OpenGL_Initialize


//.........这里部分代码省略.........
		{
			RECT rect;
			// full screen mode, we want the window to be on top of everything
			SetWindowPos(g_hWnd,HWND_TOPMOST,0,0,GLPREF_width,GLPREF_height,SWP_FRAMECHANGED);
			width=GLPREF_width;
			height=GLPREF_height;
			GetWindowRect(g_hWnd,&rect);
		}

		GLSTATE_width = width;
		GLSTATE_height = height;

	}

	hDC = GetDC(g_hWnd);

	// Now we finally setup OpenGL
	// If OpenGL is to be dynamically loaded, do this now (if the DLL isn't already
	// loaded)
	// remove the following error when you figure out what you want to do
	// it's put here to make sure you notice this
#ifdef OGL_RUNTIME_LOAD
	OglInitLoadLibrary();
#endif

	// Setup our pixel format

	memset(&pfd,0,sizeof(pfd);
	pfd.nSize        = sizeof(pfd);
	pfd.nVersion     = 1;
	pfd.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
//	pfd.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_GENERIC_ACCELERATED;
	pfd.iPixelType   = PFD_TYPE_RGBA;
	//let the ogl driver decide. (fixes no hw accel in 16bit mode in w2k with tnt2)
//	pfd.cColorBits = 16;
//	pfd.cAlphaBits = 8;
//	pfd.cDepthBits = 0;
//	pfd.cAccumBits = 0;
//	pfd.cStencilBits = 0;
	pfd.iLayerType = PFD_MAIN_PLANE;
	pfd.dwLayerMask = PFD_MAIN_PLANE;


	// Find the user's "best match" PFD 
	pf = ChoosePixelFormat(hDC,&pfd);
	if(pf == 0) 
	{
		errstr="ChoosePixelFormat";
		// no pixel format closely matches
		goto OpenGLError;
	} 

	// Set the new PFD
	if(SetPixelFormat(hDC,pf,&pfd)==FALSE) 
	{
		errstr="SetPixelFormat";
		// unable to set the pixel format
		goto OpenGLError;
	}

	// Now retrieve the PFD, we need to check some things
/*	if(DescribePixelFormat(hDC,pf,sizeof(PIXELFORMATDESCRIPTOR),&pfd_copy)==0)
	{
		errstr="DescribePixelFormat";
		// unable to get the PFD
		goto OpenGLError;
	}

	// Make sure we are hardware accelerated
	if((pfd_copy.dwFlags&PFD_GENERIC_ACCELERATED)==0&&(pfd_copy.dwFlags&PFD_GENERIC_FORMAT)!=0)
	{
		// we are not hardware accelerated!
		goto OpenGLError;
	}*/

	// Finally, create our OpenGL context and make it current
	GL_ResourceContext = wglCreateContext(hDC);
	if(GL_ResourceContext==NULL)
	{
		errstr="wglCreateContext";
		// we couldn't create a context!
		goto OpenGLError;
	}

	// Make the context current
	wglMakeCurrent(hDC,GL_ResourceContext);

	// Save our gamma values because we'll probably be changing them,
	// this way we can restore them on exit

//	GetDeviceGammaRamp(hDC,(LPVOID)Saved_gammaValues);

	return true;

OpenGLError:
	// Shutdown OpenGL
	OpenGL_Shutdown();
	Error("opengl init error: %s\n",errstr);
	return false;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:101,代码来源:wgl.c


示例11: sizeof

Error ContextGL_Win::initialize() {

	static PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
		1,
		PFD_DRAW_TO_WINDOW | // Format Must Support Window
				PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
				PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,
		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, // Accumulation Bits Ignored
		24, // 24Bit 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
	};

	hDC = GetDC(hWnd);
	if (!hDC) {
		MessageBox(NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return ERR_CANT_CREATE; // Return FALSE
	}

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

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

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

	wglMakeCurrent(hDC, hRC);

	if (opengl_3_context) {

		int attribs[] = {
			WGL_CONTEXT_MAJOR_VERSION_ARB, 3, //we want a 3.3 context
			WGL_CONTEXT_MINOR_VERSION_ARB, 3,
			//and it shall be forward compatible so that we can only use up to date functionality
			WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | _WGL_CONTEXT_DEBUG_BIT_ARB,
			0
		}; //zero indicates the end of the array

		PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; //pointer to the method
		wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");

		if (wglCreateContextAttribsARB == NULL) //OpenGL 3.0 is not supported
		{
			MessageBox(NULL, "Cannot get Proc Address for CreateContextAttribs", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			wglDeleteContext(hRC);
			return ERR_CANT_CREATE;
		}

		HGLRC new_hRC = wglCreateContextAttribsARB(hDC, 0, attribs);
		if (!new_hRC) {
			wglDeleteContext(hRC);
			MessageBox(NULL, "Can't Create An OpenGL 3.3 Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			return ERR_CANT_CREATE; // Return false
		}
		wglMakeCurrent(hDC, NULL);
		wglDeleteContext(hRC);
		hRC = new_hRC;

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

		printf("Activated GL 3.3 context");
	}

	wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
	//glWrapperInit(wrapper_get_proc_address);

	return OK;
}
开发者ID:Bonfi96,项目名称:godot,代码行数:96,代码来源:context_gl_win.cpp


示例12: void

bool COpenGLControl::InitOpenGL(HINSTANCE hInstance, HWND* a_hWnd, int iMajorVersion, int iMinorVersion, void (*a_InitScene)(LPVOID), void (*a_RenderScene)(LPVOID), void(*a_ReleaseScene)(LPVOID), LPVOID lpParam)
{
	if(!InitGLEW(hInstance))return false;

	hWnd = a_hWnd;
	hDC = GetDC(*hWnd);

	bool bError = false;
	PIXELFORMATDESCRIPTOR pfd;

	if(iMajorVersion <= 2)
	{
		memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
		pfd.nSize		= sizeof(PIXELFORMATDESCRIPTOR);
		pfd.nVersion   = 1;
		pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 32;
		pfd.cDepthBits = 32;
		pfd.iLayerType = PFD_MAIN_PLANE;
 
		int iPixelFormat = ChoosePixelFormat(hDC, &pfd);
		if (iPixelFormat == 0)return false;

		if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false;

		// Create the old style context (OpenGL 2.1 and before)
		hRC = wglCreateContext(hDC);
		if(hRC)wglMakeCurrent(hDC, hRC);
		else bError = true;
	}
	else if(WGLEW_ARB_create_context && WGLEW_ARB_pixel_format)
	{
		const int iPixelFormatAttribList[] =
		{
			WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
			WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
			WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
			WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
			WGL_COLOR_BITS_ARB, 32,
			WGL_DEPTH_BITS_ARB, 24,
			WGL_STENCIL_BITS_ARB, 8,
			0 // End of attributes list
		};
		int iContextAttribs[] =
		{
			WGL_CONTEXT_MAJOR_VERSION_ARB, iMajorVersion,
			WGL_CONTEXT_MINOR_VERSION_ARB, iMinorVersion,
			WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
			0 // End of attributes list
		};

		int iPixelFormat, iNumFormats;
		wglChoosePixelFormatARB(hDC, iPixelFormatAttribList, NULL, 1, &iPixelFormat, (UINT*)&iNumFormats);

		// PFD seems to be only redundant parameter now
		if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false;

		hRC = wglCreateContextAttribsARB(hDC, 0, iContextAttribs);
		// If everything went OK
		if(hRC) wglMakeCurrent(hDC, hRC);
		else bError = true;

	}
	else bError = true;
	
	if(bError)
	{
		// Generate error messages
		char sErrorMessage[255], sErrorTitle[255];
		sprintf(sErrorMessage, "OpenGL %d.%d is not supported! Please download latest GPU drivers!", iMajorVersion, iMinorVersion);
		sprintf(sErrorTitle, "OpenGL %d.%d Not Supported", iMajorVersion, iMinorVersion);
		MessageBox(*hWnd, sErrorMessage, sErrorTitle, MB_ICONINFORMATION);
		return false;
	}

	RenderScene = a_RenderScene;
	InitScene = a_InitScene;
	ReleaseScene = a_ReleaseScene;

	if(InitScene != NULL)InitScene(lpParam);

	return true;
}
开发者ID:walkevin,项目名称:PBSExercises,代码行数:84,代码来源:OpenGLControl.cpp


示例13: glusCreateWindow


//.........这里部分代码省略.........
	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 (!(g_hWnd = CreateWindowEx(dwExStyle,						// Extended Style For The Window
								"GLUS",								// 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
								g_hInstance,						// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		glusDestroyWindow();
		return GLUS_FALSE;
	}
	
	if (!(g_hDC = GetDC(g_hWnd)))					// Did We Get A Device Context?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if (!(PixelFormat = ChoosePixelFormat(g_hDC, &pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if(!SetPixelFormat(g_hDC, PixelFormat, &pfd))	// Are We Able To Set The Pixel Format?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if (!(g_hRC=wglCreateContext(g_hDC)))			// Are We Able To Get A Rendering Context?
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if(!wglMakeCurrent(g_hDC, g_hRC))				// Try To Activate The Rendering Context
	{
		glusDestroyWindow();
		return GLUS_FALSE;							// Return FALSE
	}

	if (g_major >= 3)
	{
		PFNWGLCREATECONTEXTATTRIBSARBPROCTEMP wglCreateContextAttribsARBTemp = NULL;
		HGLRC hRCTemp = NULL;

		GLUSint attribList[] =
		{
		  WGL_CONTEXT_MAJOR_VERSION_ARB, 1,
		  WGL_CONTEXT_MINOR_VERSION_ARB, 0,
开发者ID:grachyov,项目名称:msu-opengl4-sdk,代码行数:67,代码来源:glus_windows.c


示例14: GetDC

	xdl_int XdevLOpenGLWGL::initOpenGL() {
		m_DC = GetDC(m_wnd);
		if(m_DC == NULL) {
			XDEVL_MODULE_ERROR("GetDC() failed.");
			return ERR_ERROR;
		}

		PIXELFORMATDESCRIPTOR pfd;
		memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
		pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
		pfd.nVersion = 1;
		pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = m_attributes.color_buffer_size;
		pfd.cDepthBits = m_attributes.depth_size;
		pfd.cStencilBits = m_attributes.stencil_size;
		pfd.cRedBits = m_attributes.red_size;
		pfd.cGreenBits = m_attributes.green_size;
		pfd.cBlueBits = m_attributes.blue_size;
		pfd.cAlphaBits = m_attributes.alpha_size;
		pfd.iLayerType = PFD_MAIN_PLANE;

		int iPixelFormat = ChoosePixelFormat(m_DC, &pfd);
		if (FALSE == iPixelFormat) {
			XDEVL_MODULE_ERROR("ChoosePixelFormat failed.\n");
			return ERR_ERROR;
		}

		if (SetPixelFormat(m_DC, iPixelFormat, &pfd) != TRUE) {
			XDEVL_MODULE_ERROR("SetPixelFormat failed.\n");
			return ERR_ERROR;
		}

		// Create the old style context (OpenGL 2.1 and before)
		HGLRC hRC = wglCreateContext(m_DC);
		wglMakeCurrent(m_DC, hRC);

		wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
		wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
		wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");

		wglMakeCurrent(nullptr, nullptr);
		wglDeleteContext(hRC);

		if (wglCreateContextAttribsARB) {
			const int iPixelFormatAttribList[] = {
				WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
				WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
				WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
				WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
				WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
				WGL_SWAP_METHOD_ARB, WGL_SWAP_EXCHANGE_ARB,
				WGL_COLOR_BITS_ARB, 32,
				WGL_DEPTH_BITS_ARB, 24,
				WGL_STENCIL_BITS_ARB, 8,
				WGL_ACCUM_BITS_ARB, 0,
				WGL_RED_BITS_ARB, m_attributes.red_size,
				WGL_GREEN_BITS_ARB, m_attributes.green_size,
				WGL_BLUE_BITS_ARB, m_attributes.blue_size,
				WGL_ALPHA_BITS_ARB, m_attributes.alpha_size,
				0 // End of attributes list
			};

			int iPixelFormat, iNumFormats;
			if (wglChoosePixelFormatARB(m_DC, iPixelFormatAttribList, NULL, 1, &iPixelFormat, (UINT*)&iNumFormats) != TRUE) {
				XDEVL_MODULE_ERROR("wglChoosePixelFormatARB failed.\n");
				return ERR_ERROR;
			}

			// PFD seems to be only redundant parameter now
			if (SetPixelFormat(m_DC, iPixelFormat, &pfd) != TRUE) {
				XDEVL_MODULE_ERROR("SetPixelFormat failed.\n");
				return ERR_ERROR;
			}


			//
			// Set the core profile attributes.
			//
			std::vector<xdl_int> contextAttributes;
			contextAttributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
			contextAttributes.push_back(m_attributes.context_major_version);
			contextAttributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
			contextAttributes.push_back(m_attributes.context_minor_version);

			contextAttributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB);
			if (m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_CORE_PROFILE) {
				contextAttributes.push_back(WGL_CONTEXT_CORE_PROFILE_BIT_ARB);
			} else if (m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_COMPATIBILITY) {
				contextAttributes.push_back(WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
			} else if (m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_ES1) {
				XDEVL_MODULE_ERROR("Not supported WGL_CONTEXT_PROFILE_MASK_ARB .\n");
				return ERR_ERROR;
			} else if (m_attributes.context_profile_mask == XDEVL_OPENGL_CONTEXT_ES2) {
				XDEVL_MODULE_ERROR("Not supported WGL_CONTEXT_PROFILE_MASK_ARB .\n");
				return ERR_ERROR;
			} else {
				XDEVL_MODULE_ERROR("Not supported WGL_CONTEXT_PROFILE_MASK_ARB .\n");
				return ERR_ERROR;
			}
//.........这里部分代码省略.........
开发者ID:houzhenggang,项目名称:XdevLSDK,代码行数:101,代码来源:XdevLOpenGLContextWGL.cpp


示例15: AESDK_OpenGL_Startup

/*
** OS Specific windowing context creation - essential for creating the OpenGL drawing context
*/
AESDK_OpenGL_Err AESDK_OpenGL_Startup(AESDK_OpenGL_EffectCommonData& inData)
{
	AESDK_OpenGL_Err result = AESDK_OpenGL_OK;
	inData.mUsingShaderB = false; //default value
	try
	{
#ifdef AE_OS_WIN
		WNDCLASSEX winClass; 
		MSG        uMsg;

		::memset(&uMsg,0,sizeof(uMsg));

		winClass.lpszClassName = "AESDK_OpenGL_Win_Class";
		winClass.cbSize        = sizeof(WNDCLASSEX);
		winClass.style         = CS_HREDRAW | CS_VREDRAW;
		winClass.lpfnWndProc   = ::DefWindowProc;
		winClass.hInstance     = NULL;
		winClass.hIcon	       = NULL;
		winClass.hIconSm	   = NULL;
		winClass.hCursor       = ::LoadCursor(NULL, IDC_ARROW);
		winClass.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH);
		winClass.lpszMenuName  = NULL;
		winClass.cbClsExtra    = 0;
		winClass.cbWndExtra    = 0;
		
		if( !(::RegisterClassEx(&winClass)) )
			GL_CHECK(AESDK_OpenGL_OS_Load_Err);

		inData.mHWnd = ::CreateWindowEx( NULL, "AESDK_OpenGL_Win_Class", 
								 "OpenGL-using FBOs in AE",
									0,0, 
									0, 50, 50,
									NULL, 
									NULL, 
									NULL,
									NULL	);

		if( inData.mHWnd == NULL )
			GL_CHECK(AESDK_OpenGL_OS_Load_Err);
		
		GLuint PixelFormat;
		PIXELFORMATDESCRIPTOR pfd;
		::ZeroMemory( &pfd, sizeof( pfd ) );

		pfd.nSize      = sizeof(PIXELFORMATDESCRIPTOR);
		pfd.nVersion   = 1;
		pfd.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER ;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 32;
		pfd.cDepthBits = 8;
		
		
		inData.mHDC = ::GetDC( inData.mHWnd );
		PixelFormat = ChoosePixelFormat( inData.mHDC, &pfd );
		SetPixelFormat( inData.mHDC, PixelFormat, &pfd);
		
		inData.mHRC = wglCreateContext( inData.mHDC );
		wglMakeCurrent( inData.mHDC, inData.mHRC );

		//check for the appropriate extensions -  EXT_framebuffer_object
		char *ext = (char*)glGetString( GL_EXTENSIONS );
		if( ::strstr( ext, "EXT_framebuffer_object" ) == NULL )
		{		
			GL_CHECK(AESDK_OpenGL_Extensions_Err);
		}
		else
		{
			glIsRenderbufferEXT = (PFNGLISRENDERBUFFEREXTPROC)GetProcAddress("glIsRenderbufferEXT");
			glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)GetProcAddress("glBindRenderbufferEXT");
			glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)GetProcAddress("glDeleteRenderbuffersEXT");
			glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)GetProcAddress("glGenRenderbuffersEXT");
			glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)GetProcAddress("glRenderbufferStorageEXT");
			glGetRenderbufferParameterivEXT = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC)GetProcAddress("glGetRenderbufferParameterivEXT");
			glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC)GetProcAddress("glIsFramebufferEXT");
			glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)GetProcAddress("glBindFramebufferEXT");
			glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)GetProcAddress("glDeleteFramebuffersEXT");
			glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)GetProcAddress("glGenFramebuffersEXT");
			glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)GetProcAddress("glCheckFramebufferStatusEXT");
			glFramebufferTexture1DEXT = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC)GetProcAddress("glFramebufferTexture1DEXT");
			glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)GetProcAddress("glFramebufferTexture2DEXT");
			glFramebufferTexture3DEXT = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC)GetProcAddress("glFramebufferTexture3DEXT");
			glFram 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ChopWindingInPlace函数代码示例发布时间:2022-05-30
下一篇:
C++ ChooseFont函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap