OpenGL Pixel Format freeze

I am having a trouble with my OpenGL Powered game engine. The problem arises at the creation of a pixel format.

The program gets stuck loading when i call wglChoosePixelFormat()

Relevant files:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "OGLAbstr.h"

LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
		
	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
		break;
	}
	return (0);
}

OGLAbstr::OGLAbstr(HINSTANCE hInst, LogMgr* mLog)
{
	hInstance = hInst;
	log = mLog;

	fakeClass.cbSize = sizeof(WNDCLASSEX);
	fakeClass.style =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
	fakeClass.lpfnWndProc = wndProc;
	fakeClass.cbClsExtra = 0; fakeClass.cbWndExtra = 0;
	fakeClass.hInstance = hInstance;
	fakeClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	fakeClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	fakeClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	fakeClass.hbrBackground = (HBRUSH)(COLOR_MENUBAR+1);
	fakeClass.lpszMenuName = NULL;
	fakeClass.lpszClassName = "temp";

	RegisterClassEx(&fakeClass);
	log->logMessage(log->WND, "Registered dummy class");
}

OGLAbstr::~OGLAbstr()
{
}

bool OGLAbstr::initGLEW()
{
   HWND hWndFake = CreateWindow("temp", "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

   hDC = GetDC(hWndFake);

   // First, choose false pixel format
   
   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 = 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 false, old style context (OpenGL 2.1 and before)
   HGLRC hRCFake = wglCreateContext(hDC);
   wglMakeCurrent(hDC, hRCFake);

   if(glewInit() != GLEW_OK)
   {
      MessageBox(NULL, "Couldn't initialize GLEW!", "Fatal Error", MB_ICONERROR | MB_OK);
	  log->logMessage(log->GLERR, "Could not initialize GLEW!");
	  return false;
   }
   log->logMessage(log->GL, "Initialized GLEW");

   wglMakeCurrent(NULL, NULL);
   wglDeleteContext(hRCFake);
   DestroyWindow(hWndFake);
   UnregisterClass("temp", hInstance);

   return true;
}

bool OGLAbstr::initGL(int AA)
{
#ifdef _EDITOR
	hDC = GetDC(RenderWindow);
#endif
#ifdef _GAME
	hDC = GetDC(Window);
#endif
	PIXELFORMATDESCRIPTOR pfd;

	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,
		WGL_ARB_multisample, AA,
		WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
		0 // End of attributes list
	};
	int iContextAttribs[] =
	{
		WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
		WGL_CONTEXT_MINOR_VERSION_ARB, 0,
		WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
		0 // End of attributes list
	};

	int iPixelFormat, iNumFormats;
	if(!wglChoosePixelFormatARB(hDC, iPixelFormatAttribList, NULL, 1, &iPixelFormat, (UINT*)&iNumFormats))
	{
		log->logMessage(log->GLERR, "Could not find Pixel Format!");
		return false;
	}

	// 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);

	glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
	return true;
}

bool OGLAbstr::openGameWindow(WNDCLASSEX wc, std::string title, int x, int y)
{
	Window = CreateWindowEx(0, "GC", title.c_str(), WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_VISIBLE, x, y, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, 0);
	if(Window == NULL)
		return false;
	ShowWindow(Window, SW_SHOW);
 	return true;
}

void OGLAbstr::renderFrame()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	SwapBuffers(hDC);
}

bool OGLAbstr::openEditorWindow(WNDCLASSEX wc)
{

	return true;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef _OGLABSTR_H_
#define _OGLABSTR_H_

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glew32.lib")

#include <GL/glew.h>
#include <GL/wglew.h>
#include <string.h>
#include <iostream>
#include <Windows.h>
#include "LogMgr.hpp"

class OGLAbstr
{
public:
	OGLAbstr(HINSTANCE hInst, LogMgr* mLog);
	~OGLAbstr();

	bool initGL(int AA=0);
	bool initGLEW();

	bool openGameWindow(WNDCLASSEX wc, std::string title, int x=0, int y=0);
	bool openEditorWindow(WNDCLASSEX wc);

	void renderFrame();

private:
	HDC hDC;
	HWND Window;
	HWND RenderWindow;
	HMENU Menu;
	HINSTANCE hInstance;
	WNDCLASSEX fakeClass;
	HGLRC hRC;
	std::string className;
	LogMgr* log;
};

#endif 
Last edited on
*bump*
Problem solved, Removed Multisampling from the ARB list and that fixed it. Also forgot about the windows msg dispatching.
Topic archived. No new replies allowed.