46
46
using namespace std;
49
LONG WINAPI imagingWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
51
return DefWindowProc(hwnd, msg, wParam, lParam);
54
void registerWindowClass()
56
static char * pClassName;
62
HINSTANCE hInstance = GetModuleHandle(NULL);
64
memset(&wc, 0, sizeof(WNDCLASS));
66
wc.lpfnWndProc = (WNDPROC)imagingWindowProc;
67
wc.hInstance = hInstance;
68
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
69
wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
70
wc.hbrBackground = NULL;
71
wc.lpszMenuName = NULL;
72
wc.lpszClassName = pClassName;
74
BOOL bOK = RegisterClass(&wc);
80
static bool s_bX11Error;
81
static int (*s_DefaultErrorHandler) (Display *, XErrorEvent *);
83
int X11ErrorHandler(Display * pDisplay, XErrorEvent * pErrEvent)
85
cerr << "X11 error creating offscreen context: " << (int)(pErrEvent->request_code)
86
<< ", " << (int)(pErrEvent->minor_code) << endl;
92
48
OGLImagingContext::OGLImagingContext()
95
GLint attributes[] = {AGL_RGBA, AGL_ALL_RENDERERS,AGL_NONE};
96
AGLPixelFormat format;
97
format = aglChoosePixelFormat(NULL, 0, attributes);
100
m_Context = aglCreateContext(format, NULL);
101
AVG_ASSERT(m_Context);
102
aglDestroyPixelFormat(format);
104
bool bOk = aglSetCurrentContext(m_Context);
109
dpy = XOpenDisplay(0);
111
throw Exception(AVG_ERR_VIDEO_GENERAL, "No X windows display available.");
114
static int attributes[] = {GLX_RGBA,
119
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributes);
120
m_Context = glXCreateContext(dpy, vi, 0, GL_TRUE);
121
AVG_ASSERT(m_Context);
122
Pixmap pmp = XCreatePixmap(dpy, RootWindow(dpy, vi->screen),
124
GLXPixmap pixmap = glXCreateGLXPixmap(dpy, vi, pmp);
127
s_DefaultErrorHandler = XSetErrorHandler(X11ErrorHandler);
128
glXMakeCurrent(dpy, pixmap, m_Context);
129
XSetErrorHandler(s_DefaultErrorHandler);
132
throw Exception(AVG_ERR_VIDEO_GENERAL, "X error creating OpenGL context.");
136
registerWindowClass();
137
m_hwnd = CreateWindow("GLUT", "GLUT",
138
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
139
0, 0, 500, 300, 0, 0, GetModuleHandle(NULL), 0);
140
winOGLErrorCheck(m_hDC != 0, "CreateWindow");
142
m_hDC = GetDC(m_hwnd);
143
winOGLErrorCheck(m_hDC != 0, "GetDC");
145
PIXELFORMATDESCRIPTOR pfd;
146
ZeroMemory(&pfd, sizeof(pfd));
147
pfd.nSize = sizeof(pfd);
149
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
150
pfd.iPixelType = PFD_TYPE_RGBA;
153
pfd.iLayerType = PFD_MAIN_PLANE;
155
int iFormat = ChoosePixelFormat(m_hDC, &pfd);
156
winOGLErrorCheck(iFormat != 0, "ChoosePixelFormat");
157
SetPixelFormat(m_hDC, iFormat, &pfd);
158
m_Context = wglCreateContext(m_hDC);
159
winOGLErrorCheck(m_Context != 0, "wglCreateContext");
161
BOOL bOK = wglMakeCurrent(m_hDC, m_Context);
162
winOGLErrorCheck(bOK, "wglMakeCurrent");
168
53
if (!isSupported()) {
169
54
throw Exception(AVG_ERR_VIDEO_GENERAL,