本文整理匯總了C++中DescribePixelFormat函數的典型用法代碼示例。如果您正苦於以下問題:C++ DescribePixelFormat函數的具體用法?C++ DescribePixelFormat怎麽用?C++ DescribePixelFormat使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DescribePixelFormat函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: GLW_MakeContext
/*
** 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;
}
示例2: choosePixelFormat
// Return a list of available and usable framebuffer configs
//
static GLboolean choosePixelFormat(_GLFWwindow* window,
const _GLFWfbconfig* desired,
int* result)
{
_GLFWfbconfig* usableConfigs;
const _GLFWfbconfig* closest;
int i, nativeCount, usableCount;
if (window->wgl.ARB_pixel_format)
{
nativeCount = getPixelFormatAttrib(window,
1,
WGL_NUMBER_PIXEL_FORMATS_ARB);
}
else
{
nativeCount = DescribePixelFormat(window->wgl.dc,
1,
sizeof(PIXELFORMATDESCRIPTOR),
NULL);
}
if (!nativeCount)
{
_glfwInputError(GLFW_API_UNAVAILABLE, "WGL: No pixel formats found");
return GL_FALSE;
}
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
usableCount = 0;
for (i = 0; i < nativeCount; i++)
{
const int n = i + 1;
_GLFWfbconfig* u = usableConfigs + usableCount;
if (window->wgl.ARB_pixel_format)
{
// Get pixel format attributes through WGL_ARB_pixel_format
if (!getPixelFormatAttrib(window, n, WGL_SUPPORT_OPENGL_ARB) ||
!getPixelFormatAttrib(window, n, WGL_DRAW_TO_WINDOW_ARB) ||
!getPixelFormatAttrib(window, n, WGL_DOUBLE_BUFFER_ARB))
{
continue;
}
if (getPixelFormatAttrib(window, n, WGL_PIXEL_TYPE_ARB) !=
WGL_TYPE_RGBA_ARB)
{
continue;
}
if (getPixelFormatAttrib(window, n, WGL_ACCELERATION_ARB) ==
WGL_NO_ACCELERATION_ARB)
{
continue;
}
u->redBits = getPixelFormatAttrib(window, n, WGL_RED_BITS_ARB);
u->greenBits = getPixelFormatAttrib(window, n, WGL_GREEN_BITS_ARB);
u->blueBits = getPixelFormatAttrib(window, n, WGL_BLUE_BITS_ARB);
u->alphaBits = getPixelFormatAttrib(window, n, WGL_ALPHA_BITS_ARB);
u->depthBits = getPixelFormatAttrib(window, n, WGL_DEPTH_BITS_ARB);
u->stencilBits = getPixelFormatAttrib(window, n, WGL_STENCIL_BITS_ARB);
u->accumRedBits = getPixelFormatAttrib(window, n, WGL_ACCUM_RED_BITS_ARB);
u->accumGreenBits = getPixelFormatAttrib(window, n, WGL_ACCUM_GREEN_BITS_ARB);
u->accumBlueBits = getPixelFormatAttrib(window, n, WGL_ACCUM_BLUE_BITS_ARB);
u->accumAlphaBits = getPixelFormatAttrib(window, n, WGL_ACCUM_ALPHA_BITS_ARB);
u->auxBuffers = getPixelFormatAttrib(window, n, WGL_AUX_BUFFERS_ARB);
u->stereo = getPixelFormatAttrib(window, n, WGL_STEREO_ARB);
if (window->wgl.ARB_multisample)
u->samples = getPixelFormatAttrib(window, n, WGL_SAMPLES_ARB);
if (window->wgl.ARB_framebuffer_sRGB)
u->sRGB = getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
}
else
{
PIXELFORMATDESCRIPTOR pfd;
// Get pixel format attributes through old-fashioned PFDs
if (!DescribePixelFormat(window->wgl.dc,
n,
sizeof(PIXELFORMATDESCRIPTOR),
&pfd))
{
continue;
}
if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
!(pfd.dwFlags & PFD_SUPPORT_OPENGL) ||
!(pfd.dwFlags & PFD_DOUBLEBUFFER))
{
//.........這裏部分代碼省略.........
示例3: findPixelFormatFromBPP
/*
* Find an appropriate pixel format
*/
static int findPixelFormatFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, int bpp, bool double_buffer)
{
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
int alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "alpha", "I"));
int depth = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "depth", "I"));
int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
int num_aux_buffers = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
jboolean stereo = (*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
unsigned int flags = PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL |
(double_buffer ? PFD_DOUBLEBUFFER : 0) |
(stereo ? PFD_STEREO : 0);
PIXELFORMATDESCRIPTOR desc;
int iPixelFormat;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
flags, // RGBA type
PFD_TYPE_RGBA,
(BYTE)bpp,
0, 0, 0, 0, 0, 0, // color bits ignored
(BYTE)alpha,
0, // shift bit ignored
accum_bpp + accum_alpha, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
(BYTE)depth,
(BYTE)stencil,
num_aux_buffers,
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
// get the best available match of pixel format for the device context
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
if (iPixelFormat == 0) {
throwException(env, "Failed to choose pixel format");
return -1;
}
if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) {
throwException(env, "Could not describe pixel format");
return -1;
}
if (desc.cColorBits < bpp) {
throwException(env, "Insufficient color precision");
return -1;
}
if (desc.cAlphaBits < alpha) {
throwException(env, "Insufficient alpha precision");
return -1;
}
if (desc.cStencilBits < stencil) {
throwException(env, "Insufficient stencil precision");
return -1;
}
if (desc.cDepthBits < depth) {
throwException(env, "Insufficient depth buffer precision");
return -1;
}
if ((desc.dwFlags & PFD_GENERIC_FORMAT) != 0) {
jboolean allowSoftwareOpenGL = getBooleanProperty(env, "org.lwjgl.opengl.Display.allowSoftwareOpenGL");
// secondary check for software override
if(!allowSoftwareOpenGL) {
throwException(env, "Pixel format not accelerated");
return -1;
}
}
if ((desc.dwFlags & flags) != flags) {
throwException(env, "Capabilities not supported");
return -1;
}
return iPixelFormat;
}
示例4: OK2_AnimInit
/* Функция инициализации анимации.
* АРГУМЕНТЫ:
* - дескриптор окна:
* HWND hWnd;
* ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет.
*/
BOOL OK2_AnimInit( HWND hWnd )
{
LARGE_INTEGER li;
INT i;
/* Init window parametrs */
OK2_Anim.hDC = GetDC(hWnd);
OK2_Anim.hWnd = hWnd;
OK2_Anim.W = 30;
OK2_Anim.H = 30;
OK2_Anim.NumOfUnits = 0;
/*** Инициализация OpenGL ***/
/* описываем формат точки */
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
i = ChoosePixelFormat(OK2_Anim.hDC, &pfd);
DescribePixelFormat(OK2_Anim.hDC, i, sizeof(pfd), &pfd);
SetPixelFormat(OK2_Anim.hDC, i, &pfd);
/* создаем контекст построения */
OK2_Anim.hRC = wglCreateContext(OK2_Anim.hDC);
/* делаем текущими контексты */
wglMakeCurrent(OK2_Anim.hDC, OK2_Anim.hRC);
/* инициализируем расширения */
if (glewInit() != GLEW_OK ||
!(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader))
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(OK2_Anim.hRC);
ReleaseDC(OK2_Anim.hWnd, OK2_Anim.hDC);
memset(&OK2_Anim, 0, sizeof(ok2ANIM));
return FALSE;
}
/* параметры OpenGL по-умолчанию */
/* инициализируем таймер */
QueryPerformanceFrequency(&li);
TimeFreq = li.QuadPart;
QueryPerformanceCounter(&li);
TimeStart = TimeOld = TimeFPS = li.QuadPart;
TimePause = 0;
FrameCounter = 0;
/* инициализируем захват сообщений от мыши */
SetWindowsHookEx(WH_MOUSE_LL, OK2_MouseHook, GetModuleHandle(NULL), 0);
/* Параметры проецирования */
OK2_Anim.Wp = 4.0, OK2_Anim.Hp = 3.0, /* размеры обрасти проецирования */
OK2_Anim.ProjDist = 1.0, /* расстояние до плоскости проекции */
OK2_Anim.FarClip = 1000.0,
OK2_Anim.ProjSize = 1.0;
OK2_Anim.MatrWorld = /* матрица преобразования мировой СК */
OK2_Anim.MatrView = /* матрица преобразования видовой СК */
OK2_Anim.MatrProjection = MatrIdenity(); /* матрица проекции */
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return TRUE;
} /* End of 'OK2_AnimInit' function */
示例5: WinMain
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
// Allocate program memory
g_program_memory.start = malloc(MAX_INTERNAL_MEMORY_SIZE);
g_program_memory.free_memory = g_program_memory.start;
// TODO: add checks for overflow when allocating
// Main program state
Program_State *state =
(Program_State *)g_program_memory.allocate(sizeof(Program_State));
state->init(&g_program_memory, &g_pixel_buffer,
(Raytrace_Work_Queue *)&g_raytrace_queue);
// Create window class
WNDCLASS WindowClass = {};
WindowClass.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WindowClass.lpfnWndProc = Win32WindowProc;
WindowClass.hInstance = hInstance;
WindowClass.lpszClassName = "VMWindowClass";
// Set target sleep resolution
{
TIMECAPS tc;
UINT wTimerRes;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
OutputDebugStringA("Cannot set the sleep resolution\n");
exit(1);
}
wTimerRes = min(max(tc.wPeriodMin, 1), tc.wPeriodMax); // 1 ms
timeBeginPeriod(wTimerRes);
}
QueryPerformanceFrequency(&gPerformanceFrequency);
if (!RegisterClass(&WindowClass)) {
// TODO: logging
printf("Couldn't register window class\n");
exit(1);
}
// Create window so that its client area is exactly kWindowWidth/Height
DWORD WindowStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
RECT WindowRect = {};
WindowRect.right = state->kWindowWidth;
WindowRect.bottom = state->kWindowHeight;
AdjustWindowRect(&WindowRect, WindowStyle, 0);
int WindowWidth = WindowRect.right - WindowRect.left;
int WindowHeight = WindowRect.bottom - WindowRect.top;
HWND Window = CreateWindow(WindowClass.lpszClassName, 0, WindowStyle,
CW_USEDEFAULT, CW_USEDEFAULT, WindowWidth,
WindowHeight, 0, 0, hInstance, 0);
if (!Window) {
printf("Couldn't create window\n");
exit(1);
}
// We're not going to release it as we use CS_OWNDC
HDC hdc = GetDC(Window);
g_running = true;
// Set proper buffer values based on actual client size
Win32ResizeClientWindow(Window);
// Init OpenGL
{
PIXELFORMATDESCRIPTOR DesiredPixelFormat = {};
DesiredPixelFormat.nSize = sizeof(DesiredPixelFormat);
DesiredPixelFormat.nVersion = 1;
DesiredPixelFormat.iPixelType = PFD_TYPE_RGBA;
DesiredPixelFormat.dwFlags =
PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
DesiredPixelFormat.cColorBits = 32;
DesiredPixelFormat.cAlphaBits = 8;
DesiredPixelFormat.iLayerType = PFD_MAIN_PLANE;
int SuggestedPixelFormatIndex = ChoosePixelFormat(hdc, &DesiredPixelFormat);
PIXELFORMATDESCRIPTOR SuggestedPixelFormat;
DescribePixelFormat(hdc, SuggestedPixelFormatIndex,
sizeof(SuggestedPixelFormat), &SuggestedPixelFormat);
SetPixelFormat(hdc, SuggestedPixelFormatIndex, &SuggestedPixelFormat);
HGLRC OpenGLRC = wglCreateContext(hdc);
if (wglMakeCurrent(hdc, OpenGLRC)) {
// Success
glGenTextures(1, &gTextureHandle);
typedef BOOL WINAPI wgl_swap_interval_ext(int interval);
wgl_swap_interval_ext *wglSwapInterval =
(wgl_swap_interval_ext *)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapInterval) {
wglSwapInterval(1);
} else {
// VSync not enabled or not supported
assert(false);
//.........這裏部分代碼省略.........
示例6: throw
djvWglContext::djvWglContext(djvCoreContext * context) throw (djvError) :
djvOpenGlContext(context),
_p(new djvWglContextPrivate)
{
# if defined(DJV_WINDOWS)
//DJV_DEBUG("djvWglContext::djvWglContext");
// Create a dummy window and OpenGL context for glewInit.
// According to the docs, glewInit can be called just once per-process?
DJV_LOG(context->debugLog(), "djvWglContext", "Creating dummy window...");
HINSTANCE hinstance = GetModuleHandle(0);
if (! hinstance)
{
throw djvError(
"djvWglContext",
errorLabels()[ERROR_MODULE_HANDLE].arg(int(GetLastError())));
}
static const char name [] = "djv";
WNDCLASS wc;
if (! GetClassInfo(hinstance, name, &wc))
{
wc.style = CS_OWNDC;
//wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.lpfnWndProc = DefWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = 0;
wc.lpszMenuName = 0;
wc.lpszClassName = name;
if (! RegisterClass(&wc))
{
throw djvError(
"djvWglContext",
errorLabels()[ERROR_REGISTER_CLASS].arg(int(GetLastError())));
}
}
_p->id = CreateWindow(name, 0, 0, 0, 0, 0, 0, 0, 0, hinstance, 0);
if (! _p->id)
{
throw djvError(
"djvWglContext",
errorLabels()[ERROR_CREATE_WINDOW].arg(int(GetLastError())));
}
_p->device = GetDC(_p->id);
if (! _p->device)
{
throw djvError(
"djvWglContext",
errorLabels()[ERROR_GET_DC].arg(int(GetLastError())));
}
PIXELFORMATDESCRIPTOR pixelFormatInfo;
const int pixelFormatCount = DescribePixelFormat(_p->device, 0, 0, 0);
//DJV_DEBUG_PRINT("pixel format count = " << pixelFormatCount);
DJV_LOG(context->debugLog(), "djvWglContext",
QString("Pixel format count: %1").arg(pixelFormatCount));
for (int i = 1; i < pixelFormatCount; ++i)
{
DescribePixelFormat(
_p->device,
i,
sizeof(PIXELFORMATDESCRIPTOR),
&pixelFormatInfo);
//DJV_DEBUG_PRINT(" id " << i << ": " <<
// ((PFD_SUPPORT_OPENGL & pixelFormatInfo.dwFlags) ? "gl " : "") <<
// ((PFD_GENERIC_FORMAT & pixelFormatInfo.dwFlags) ? "" : "accel ") <<
// ((PFD_TYPE_RGBA == pixelFormatInfo.iPixelType) ? "rgba " : "") <<
// "depth = " << pixelFormatInfo.cColorBits << "/" <<
// pixelFormatInfo.cRedBits << "/" <<
// pixelFormatInfo.cGreenBits << "/" <<
// pixelFormatInfo.cBlueBits << "/" <<
// pixelFormatInfo.cAlphaBits << " ");
QStringList tmp;
if (PFD_SUPPORT_OPENGL & pixelFormatInfo.dwFlags)
tmp += "gl";
if (! (PFD_GENERIC_FORMAT & pixelFormatInfo.dwFlags))
tmp += "accel";
if (PFD_TYPE_RGBA == pixelFormatInfo.iPixelType)
tmp += "rgba";
DJV_LOG(context->debugLog(), "djvWglContext",
//.........這裏部分代碼省略.........
示例7: GetOpenGLPalette
HPALETTE GetOpenGLPalette(HDC hDC)
{
HPALETTE hRetPal = NULL; // Handle to palette to be created
PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
LOGPALETTE *pPal; // Pointer to memory for logical palette
int nPixelFormat; // Pixel format index
int nColors; // Number of entries in palette
int i; // Counting variable
BYTE RedRange, GreenRange, BlueRange;
// Range for each color entry (7,7,and 3)
// Get the pixel format index and retrieve the pixel format description
nPixelFormat = GetPixelFormat(hDC);
DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
// Does this pixel format require a palette? If not, do not create a
// palette and just return NULL
if (!(pfd.dwFlags & PFD_NEED_PALETTE))
return NULL;
// Number of entries in palette. 8 bits yeilds 256 entries
nColors = 1 << pfd.cColorBits;
// Allocate space for a logical palette structure plus all the palette entries
pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors*sizeof(PALETTEENTRY));
// Fill in palette header
pPal->palVersion = 0x300; // Windows 3.0
pPal->palNumEntries = nColors; // table size
// Build mask of all 1's. This creates a number represented by having
// the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
// pfd.cBlueBits.
RedRange = (1 << pfd.cRedBits) - 1;
GreenRange = (1 << pfd.cGreenBits) - 1;
BlueRange = (1 << pfd.cBlueBits) - 1;
// Loop through all the palette entries
for (i = 0; i < nColors; i++)
{
// Fill in the 8-bit equivalents for each component
pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
pPal->palPalEntry[i].peRed = (unsigned char)(
(double)pPal->palPalEntry[i].peRed * 255.0 / RedRange);
pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
pPal->palPalEntry[i].peGreen = (unsigned char)(
(double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
pPal->palPalEntry[i].peBlue = (unsigned char)(
(double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
pPal->palPalEntry[i].peFlags = (unsigned char)NULL;
}
// Create the palette
hRetPal = CreatePalette(pPal);
// Go ahead and select and realize the palette for this device context
SelectPalette(hDC, hRetPal, FALSE);
RealizePalette(hDC);
// Free the memory used for the logical palette structure
free(pPal);
// Return the handle to the new palette
return hRetPal;
}
示例8: DisplayError
BOOL GL11Window::Create(CONST WindowSettings& settings /*= {}*/)
{
m_settings = settings;
CONST auto hInstance{GetModuleHandle(NULL)};
if (!hInstance)
{
DisplayError(TEXT("Failed to retrieve the application handle."), GetLastError());
return FALSE;
}
WNDCLASSEX wndClassEx{};
ZeroMemory(&wndClassEx, sizeof(WNDCLASSEX));
wndClassEx.cbSize = sizeof(WNDCLASSEX);
wndClassEx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndClassEx.lpfnWndProc = WndProc;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = sizeof(VOID*) + sizeof(INT);
wndClassEx.hInstance = hInstance;
wndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClassEx.hbrBackground = NULL;
wndClassEx.lpszMenuName = NULL;
wndClassEx.lpszClassName = TEXT("GL11WindowClass");
wndClassEx.hIconSm = NULL;
if (FAILED(RegisterClassEx(&wndClassEx)))
{
DisplayError(TEXT("Failed to register the window class."), GetLastError());
return FALSE;
}
DWORD windowStyle{WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS};
DWORD windowStyleEx{WS_EX_ACCEPTFILES};
RECT windowRect{0, 0, m_settings.width, m_settings.height};
if (FAILED(AdjustWindowRectEx(&windowRect, windowStyle, FALSE, windowStyleEx)))
{
DisplayError(TEXT("Failed to adjust the window rect."), GetLastError());
return FALSE;
}
m_settings.x = (GetSystemMetrics(SM_CXSCREEN) / 2) - (m_settings.width / 2);
m_settings.y = (GetSystemMetrics(SM_CYSCREEN) / 2) - (m_settings.height / 2);
CONST auto FULL_TITLE{m_settings.title + m_settings.titleEx};
m_handle = CreateWindowEx(windowStyleEx,
wndClassEx.lpszClassName,
FULL_TITLE.c_str(),
windowStyle,
m_settings.x,
m_settings.y,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top,
NULL,
NULL,
hInstance,
this);
if (!m_handle)
{
DisplayError(TEXT("Failed to create the window handle."), GetLastError());
return FALSE;
}
m_deviceContext = GetDC(m_handle);
// Query a pixel format:
PIXELFORMATDESCRIPTOR desiredPixelFormat{};
ZeroMemory(&desiredPixelFormat, sizeof(PIXELFORMATDESCRIPTOR));
desiredPixelFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR);
desiredPixelFormat.nVersion = 1;
desiredPixelFormat.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL;
desiredPixelFormat.iPixelType = PFD_TYPE_RGBA;
desiredPixelFormat.cColorBits = 32;
desiredPixelFormat.cDepthBits = 24;
desiredPixelFormat.cStencilBits = 8;
desiredPixelFormat.iLayerType = PFD_MAIN_PLANE;
auto chosenPixelFormat{ChoosePixelFormat(m_deviceContext, &desiredPixelFormat)};
if (!chosenPixelFormat)
{
DisplayError(TEXT("Failed to choose a dummy pixel format."), GetLastError());
return FALSE;
}
if (FAILED(DescribePixelFormat(m_deviceContext,
chosenPixelFormat,
sizeof(PIXELFORMATDESCRIPTOR),
&desiredPixelFormat)))
{
DisplayError(TEXT("Failed to fill the pixel format."), GetLastError());
return FALSE;
}
if (FAILED(SetPixelFormat(m_deviceContext, chosenPixelFormat, &desiredPixelFormat)))
{
DisplayError(TEXT("Failed to set the pixel format."), GetLastError());
return FALSE;
}
//.........這裏部分代碼省略.........
示例9: GLimp_InitGL
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;
if( r_stencilbits->integer == 8 || r_stencilbits->integer == 16 )
pfd.cStencilBits = r_stencilbits->integer;
/*
** set PFD_STEREO if necessary
*/
if( glConfig.stereoEnabled )
{
ri.Com_DPrintf( "...attempting to use stereo\n" );
pfd.dwFlags |= PFD_STEREO;
}
/*
** Get a DC for the specified window
*/
if( glw_state.hDC != NULL )
ri.Com_Printf( "GLimp_Init() - non-NULL DC exists\n" );
if( ( glw_state.hDC = GetDC( glw_state.hWnd ) ) == NULL )
{
ri.Com_Printf( "GLimp_Init() - GetDC failed\n" );
return false;
}
if( ( pixelformat = ChoosePixelFormat( glw_state.hDC, &pfd ) ) == 0 )
{
ri.Com_Printf( "GLimp_Init() - ChoosePixelFormat failed\n" );
return false;
}
if( SetPixelFormat( glw_state.hDC, pixelformat, &pfd ) == FALSE )
{
ri.Com_Printf( "GLimp_Init() - SetPixelFormat failed\n" );
return false;
}
DescribePixelFormat( glw_state.hDC, pixelformat, sizeof( pfd ), &pfd );
glConfig.stencilBits = pfd.cStencilBits;
/*
** report if stereo is desired but unavailable
*/
if( !( pfd.dwFlags & PFD_STEREO ) && glConfig.stereoEnabled )
{
ri.Com_Printf( "...failed to select stereo pixel format\n" );
glConfig.stereoEnabled = false;
}
/*
** startup the OpenGL subsystem by creating a context and making
** it current
*/
if( ( glw_state.hGLRC = qwglCreateContext( glw_state.hDC ) ) == 0 )
{
ri.Com_Printf( "GLimp_Init() - qwglCreateContext failed\n" );
goto fail;
}
if( !qwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) )
{
ri.Com_Printf( "GLimp_Init() - qwglMakeCurrent failed\n" );
goto fail;
}
/*
** print out PFD specifics
*/
ri.Com_Printf( "GL PFD: color(%d-bits) Z(%d-bit) stencil(%d-bits)\n", ( int ) pfd.cColorBits, ( int ) pfd.cDepthBits, ( int )pfd.cStencilBits );
return true;
fail:
if( glw_state.hGLRC )
{
qwglDeleteContext( glw_state.hGLRC );
glw_state.hGLRC = NULL;
//.........這裏部分代碼省略.........
示例10: memset
//.........這裏部分代碼省略.........
hDC=GetDC(hWindow);
if (!hDC)
{
Close();
return "Unable to obtain a GL device context.";
}
// 6. PixelFormat abfragen und setzen
// **********************************
PIXELFORMATDESCRIPTOR PFD;
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 =BPP;
PFD.cDepthBits =32;
PFD.cStencilBits=8;
PFD.iLayerType=PFD_MAIN_PLANE;
int PixelFormat=ChoosePixelFormat(hDC, &PFD);
if (!PixelFormat)
{
Close();
return "Unable to choose a pixel format.";
}
if (!DescribePixelFormat(hDC, PixelFormat, sizeof(PFD), &PFD))
{
Close();
return "Unable to verify pixel format.";
}
static char ErrorMsg[1024];
const char* s1="Selected pixel format mismatches:\n";
const char* s2="\n\nThis is probably a problem with your video card (or its driver).\n"
"Please make sure you have the latest drivers installed.\n"
"If it still doesn't work, please let me know.\n"
"(Email to [email protected], and please include the above message!)";
if ((PFD.dwFlags & PFD_DRAW_TO_WINDOW)!=PFD_DRAW_TO_WINDOW) { Close(); sprintf(ErrorMsg, "%sPFD_DRAW_TO_WINDOW is not supported. %s", s1, s2); return ErrorMsg; }
if ((PFD.dwFlags & PFD_SUPPORT_OPENGL)!=PFD_SUPPORT_OPENGL) { Close(); sprintf(ErrorMsg, "%sOpenGL is not supported. %s", s1, s2); return ErrorMsg; }
if ((PFD.dwFlags & PFD_DOUBLEBUFFER )!=PFD_DOUBLEBUFFER ) { Close(); sprintf(ErrorMsg, "%sDouble-buffering is not supported. %s", s1, s2); return ErrorMsg; }
if (PFD.iPixelType!=PFD_TYPE_RGBA ) { Close(); sprintf(ErrorMsg, "%sPixel type RGBA is not supported. %s", s1, s2); return ErrorMsg; }
// if (PFD.cColorBits<BPP ) { Close(); sprintf(ErrorMsg, "%sOnly %u color bits found (at least 15 are required). %s", s1, PFD.cColorBits , s2); return ErrorMsg; }
if (PFD.cDepthBits<16 ) { Close(); sprintf(ErrorMsg, "%sOnly %u depth bits found (at least 16 are required). %s", s1, PFD.cDepthBits , s2); return ErrorMsg; }
if (PFD.cStencilBits<8 ) { Close(); sprintf(ErrorMsg, "%sOnly %u stencil bits found (at least 8 are required).%s", s1, PFD.cStencilBits, s2); return ErrorMsg; }
if (PFD.iLayerType!=PFD_MAIN_PLANE ) { Close(); sprintf(ErrorMsg, "%sLayer type PFD_MAIN_PLANE is not supported. %s", s1, s2); return ErrorMsg; }
if(!SetPixelFormat(hDC, PixelFormat, &PFD))
{
Close();
return "Unable to set the pixel format.";
}
// 7. Rendering Context erzeugen und aktivieren
// ********************************************
hRC=wglCreateContext(hDC);
示例11: BGFX_FATAL
void GlContext::create(uint32_t /*_width*/, uint32_t /*_height*/)
{
m_opengl32dll = bx::dlopen("opengl32.dll");
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll.");
wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)bx::dlsym(m_opengl32dll, "wglGetProcAddress");
BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress.");
// If g_bgfxHwnd is NULL, the assumption is that GL context was created
// by user (for example, using SDL, GLFW, etc.)
BX_WARN(NULL != g_bgfxHwnd
, "bgfx::winSetHwnd with valid window is not called. This might "
"be intentional when GL context is created by the user."
);
if (NULL != g_bgfxHwnd)
{
wglMakeCurrent = (PFNWGLMAKECURRENTPROC)bx::dlsym(m_opengl32dll, "wglMakeCurrent");
BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent.");
wglCreateContext = (PFNWGLCREATECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglCreateContext");
BGFX_FATAL(NULL != wglCreateContext, Fatal::UnableToInitialize, "Failed get wglCreateContext.");
wglDeleteContext = (PFNWGLDELETECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglDeleteContext");
BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext.");
m_hdc = GetDC(g_bgfxHwnd);
BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!");
// Dummy window to peek into WGL functionality.
//
// An application can only set the pixel format of a window one time.
// Once a window's pixel format is set, it cannot be changed.
// MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx
HWND hwnd = CreateWindowA("STATIC"
, ""
, WS_POPUP|WS_DISABLED
, -32000
, -32000
, 0
, 0
, NULL
, NULL
, GetModuleHandle(NULL)
, 0
);
HDC hdc = GetDC(hwnd);
BGFX_FATAL(NULL != hdc, Fatal::UnableToInitialize, "GetDC failed!");
HGLRC context = createContext(hdc);
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (NULL != wglGetExtensionsStringARB)
{
const char* extensions = (const char*)wglGetExtensionsStringARB(hdc);
BX_TRACE("WGL extensions:");
dumpExtensions(extensions);
}
if (NULL != wglChoosePixelFormatARB
&& NULL != wglCreateContextAttribsARB)
{
int32_t attrs[] =
{
WGL_SAMPLE_BUFFERS_ARB, 0,
WGL_SAMPLES_ARB, 0,
WGL_SUPPORT_OPENGL_ARB, true,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_DRAW_TO_WINDOW_ARB, true,
WGL_DOUBLE_BUFFER_ARB, true,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0
};
int result;
int pixelFormat;
uint32_t numFormats = 0;
do
{
result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &pixelFormat, &numFormats);
if (0 == result
|| 0 == numFormats)
{
attrs[3] >>= 1;
attrs[1] = attrs[3] == 0 ? 0 : 1;
}
} while (0 == numFormats);
PIXELFORMATDESCRIPTOR pfd;
DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
BX_TRACE("Pixel format:\n"
//.........這裏部分代碼省略.........
示例12: VisualInfo
void
VisualInfo(HDC hDC, int verbose)
{
int i, maxpf;
PIXELFORMATDESCRIPTOR pfd;
/* calling DescribePixelFormat() with NULL args return maximum
number of pixel formats */
maxpf = DescribePixelFormat(hDC, 0, 0, NULL);
if (!verbose) {
printf(" visual x bf lv rg d st r g b a ax dp st accum buffs ms \n");
printf(" id dep cl sp sz l ci b ro sz sz sz sz bf th cl r g b a ns b\n");
printf("-----------------------------------------------------------------\n");
/* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++) {
DescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* only describe this format if it supports OpenGL */
if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
continue;
/* other criteria could be tested here for actual pixel format
choosing in an application:
for (...each pixel format...) {
if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
pfd.dwFlags & PFD_DOUBLEBUFFER &&
pfd.cDepthBits >= 24 &&
pfd.cColorBits >= 24)
{
goto found;
}
}
... not found so exit ...
found:
... found so use it ...
*/
/* print out the information for this pixel format */
printf("0x%02x ", i);
printf("%2d ", pfd.cColorBits);
if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) printf("wn ");
else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) printf("bm ");
else printf(". ");
/* should find transparent pixel from LAYERPLANEDESCRIPTOR */
printf(" . ");
printf("%2d ", pfd.cColorBits);
/* bReserved field indicates number of over/underlays */
if(pfd.bReserved) printf(" %d ", pfd.bReserved);
else printf(" . ");
printf(" %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');
printf("%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');
printf(" %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');
if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA)
printf("%2d ", pfd.cRedBits);
else printf(" . ");
if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA)
printf("%2d ", pfd.cGreenBits);
else printf(" . ");
if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA)
printf("%2d ", pfd.cBlueBits);
else printf(" . ");
if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA)
printf("%2d ", pfd.cAlphaBits);
else printf(" . ");
if(pfd.cAuxBuffers) printf("%2d ", pfd.cAuxBuffers);
else printf(" . ");
if(pfd.cDepthBits) printf("%2d ", pfd.cDepthBits);
else printf(" . ");
if(pfd.cStencilBits) printf("%2d ", pfd.cStencilBits);
else printf(" . ");
if(pfd.cAccumRedBits) printf("%2d ", pfd.cAccumRedBits);
else printf(" . ");
if(pfd.cAccumGreenBits) printf("%2d ", pfd.cAccumGreenBits);
else printf(" . ");
if(pfd.cAccumBlueBits) printf("%2d ", pfd.cAccumBlueBits);
else printf(" . ");
//.........這裏部分代碼省略.........
示例13: CreateOpenGLWindow
HWND
CreateOpenGLWindow(char* title, int x, int y, int width, int height,
BYTE type, DWORD flags)
{
int pf;
HDC hDC;
HWND hWnd;
WNDCLASS wc;
PIXELFORMATDESCRIPTOR pfd;
static HINSTANCE hInstance = 0;
/* only register the window class once - use hInstance as a flag. */
if (!hInstance) {
hInstance = GetModuleHandle(NULL);
wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";
if (!RegisterClass(&wc)) {
MessageBox(NULL, "RegisterClass() failed: "
"Cannot register window class.", "Error", MB_OK);
return NULL;
}
}
hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
x, y, width, height, NULL, NULL, hInstance, NULL);
if (hWnd == NULL) {
MessageBox(NULL, "CreateWindow() failed: Cannot create a window.",
"Error", MB_OK);
return NULL;
}
hDC = GetDC(hWnd);
/* there is no guarantee that the contents of the stack that become
the pfd are zeroed, therefore _make sure_ to clear these bits. */
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | flags;
pfd.iPixelType = type;
pfd.cColorBits = 32;
pf = ChoosePixelFormat(hDC, &pfd);
if (pf == 0) {
MessageBox(NULL, "ChoosePixelFormat() failed: "
"Cannot find a suitable pixel format.", "Error", MB_OK);
return 0;
}
if (SetPixelFormat(hDC, pf, &pfd) == FALSE) {
MessageBox(NULL, "SetPixelFormat() failed: "
"Cannot set format specified.", "Error", MB_OK);
return 0;
}
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
ReleaseDC(hDC, hWnd);
return hWnd;
}
示例14: sizeof
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//Trace("CChildView::OnCreate - Initializing OpenGL");
if (CWnd::OnCreate(lpCreateStruct) == -1){
//Trace("CChildView::OnCreate - Failed");
return -1;
}
// Initialize OpenGL parameters
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // Structure size
1, // Version number
PFD_DRAW_TO_WINDOW | // Property flags
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER, // (remove if no double buf)
PFD_TYPE_RGBA, // PixelType
24, // 24-bit color
0, 0, 0, 0, 0, 0, // Color bits and shift
0, 0, 0, 0, 0, 0, 0, // Alpha and accum buffer bits
32, // 32-bit depth buffer
0, 0, // No stencil or aux buffer
PFD_MAIN_PLANE, // Layer type
0, // Reserved
0, 0, 0 // Unsupported
};
// Tell GDI to convert device context from Win32 to OpenGL.
CClientDC dcClient(this);
int iPixelFormat = ChoosePixelFormat(dcClient.m_hDC,&pfd);
if ( !iPixelFormat ) {
// This system cannot run OpenGL
//Trace("CChildView::OnCreate - Error retrieving pixel format index...");
ASSERT(FALSE);
AfxMessageBox("Cannot initialize OpenGL...quitting.",
MB_OK | MB_ICONERROR);
return -1; // will fail new document creation...
} // if
//Trace("CChildView::OnCreate - OpenGL - Chosen Pixel Format");
if ( !SetPixelFormat(dcClient.m_hDC,iPixelFormat,&pfd) ) {
// This system cannot run OpenGL
//Trace("CChildView::OnCreate - Error setting new pixel format...");
ASSERT(FALSE);
AfxMessageBox("Cannot initialize OpenGL...quitting.",
MB_OK | MB_ICONERROR);
return -1; // will fail new document creation...
} // if
//Trace("CChildView::OnCreate - OpenGL - Pixel Format is set");
// Update the PIXELFORMATDESCRIPTOR structure once
// the device context has been modified.
DescribePixelFormat(dcClient.m_hDC,iPixelFormat,
sizeof(pfd),&pfd);
// The PIXELFORMATDESCRIPTOR has been updated, so we now
// determine whether to create and manage a custom
// palette.
if ( pfd.dwFlags & PFD_NEED_PALETTE ) {
// We do, so build a new palette...
//Trace("CChildView::OnCreate - Setting up palette...");
GLSetupPalette();
//Trace("CChildView::OnCreate - Palette is set...");
} // if
// Create the OpenGL rendering context
m_hRC = wglCreateContext(dcClient.m_hDC);
if ( m_hRC == NULL ) {
// This system cannot run OpenGL
//Trace("CChildView::OnCreate - Error creating OpenGL rendering context...\n");
ASSERT(FALSE);
AfxMessageBox("Cannot initialize OpenGL...quitting.",
MB_OK | MB_ICONERROR);
return -1; // will fail new document creation...
} // if
//Trace("CChildView::OnCreate - OpenGL - created rendering context");
// We now make it the current rendering context so
// we might set our clear color
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
wglMakeCurrent(dcClient.m_hDC,m_hRC);
GLLoadFont();
glClearColor(0.0,0.0,0.0,0.0); // black
wglMakeCurrent(dcClient.m_hDC,NULL);
//Trace("CChildView::OnCreate - Done");
return 0;
}
示例15: VisualInfoGDI
void
VisualInfoGDI (GLContext* ctx)
{
int i, maxpf;
PIXELFORMATDESCRIPTOR pfd;
/* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
number of pixel formats */
maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);
if (!verbose)
{
fprintf(file, "-----------------------------------------------------------------------------\n");
fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
fprintf(file, "-----------------------------------------------------------------------------\n");
/* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++)
{
DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* only describe this format if it supports OpenGL */
if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
|| (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;
/* other criteria could be tested here for actual pixel format
choosing in an application:
for (...each pixel format...) {
if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
pfd.dwFlags & PFD_DOUBLEBUFFER &&
pfd.cDepthBits >= 24 &&
pfd.cColorBits >= 24)
{
goto found;
}
}
... not found so exit ...
found:
... found so use it ...
*/
/* print out the information for this pixel format */
fprintf(file, "0x%02x ", i);
fprintf(file, "%3d ", pfd.cColorBits);
if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) fprintf(file, "wn ");
else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) fprintf(file, "bm ");
else fprintf(file, "pb ");
/* should find transparent pixel from LAYERPLANEDESCRIPTOR */
fprintf(file, " . ");
fprintf(file, "%3d ", pfd.cColorBits);
/* bReserved field indicates number of over/underlays */
if(pfd.bReserved) fprintf(file, " %d ", pfd.bReserved);
else fprintf(file, " . ");
fprintf(file, " %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');
fprintf(file, "%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');
fprintf(file, " %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');
/* added: */
fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_FORMAT ? 'y' : '.');
fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_ACCELERATED ? 'y' : '.');
if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA)
fprintf(file, "%2d ", pfd.cRedBits);
else fprintf(file, " . ");
if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA)
fprintf(file, "%2d ", pfd.cGreenBits);
else fprintf(file, " . ");
if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA)
fprintf(file, "%2d ", pfd.cBlueBits);
else fprintf(file, " . ");
if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA)
fprintf(file, "%2d ", pfd.cAlphaBits);
else fprintf(file, " . ");
if(pfd.cAuxBuffers) fprintf(file, "%2d ", pfd.cAuxBuffers);
else fprintf(file, " . ");
if(pfd.cDepthBits) fprintf(file, "%2d ", pfd.cDepthBits);
else fprintf(file, " . ");
if(pfd.cStencilBits) fprintf(file, "%2d ", pfd.cStencilBits);
else fprintf(file, " . ");
if(pfd.cAccumBits) fprintf(file, "%3d ", pfd.cAccumBits);
else fprintf(file, " . ");
if(pfd.cAccumRedBits) fprintf(file, "%2d ", pfd.cAccumRedBits);
else fprintf(file, " . ");
if(pfd.cAccumGreenBits) fprintf(file, "%2d ", pfd.cAccumGreenBits);
else fprintf(file, " . ");
if(pfd.cAccumBlueBits) fprintf(file, "%2d ", pfd.cAccumBlueBits);
else fprintf(file, " . ");
if(pfd.cAccumAlphaBits) fprintf(file, "%2d ", pfd.cAccumAlphaBits);
else fprintf(file, " . ");
/* no multisample in win32 */
fprintf(file, " . .\n");
}
/* print table footer */
fprintf(file, "-----------------------------------------------------------------------------\n");
fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
fprintf(file, "-----------------------------------------------------------------------------\n");
}
else /* verbose */
{
fprintf(file, "\n");
/* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++)
//.........這裏部分代碼省略.........