19 #if defined(OPENGL_WINDOWS) && defined(OPENGL_FBO) 20 static int gl_funcs_found = 0;
21 static PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
22 static PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
23 static PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
24 static PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
25 static PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
26 static PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
27 static PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
30 static void *GetAnyGLFuncAddress(
const char *
name)
32 void *p = (
void *)wglGetProcAddress(name);
33 if (p == 0 || p == (
void*)0x1 || p == (
void*)0x2 || p == (
void*)0x3 ||
35 HMODULE module = LoadLibraryA(
"opengl32.dll");
36 p = (
void *)GetProcAddress(module, name);
43 static void find_gl_funcs()
48 glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)GetAnyGLFuncAddress(
"glGenFramebuffers");
49 glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)GetAnyGLFuncAddress(
"glBindFramebuffer");
50 glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)GetAnyGLFuncAddress(
"glGenRenderbuffers");
51 glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)GetAnyGLFuncAddress(
"glBindRenderbuffer");
52 glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)GetAnyGLFuncAddress(
"glRenderbufferStorage");
53 glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)GetAnyGLFuncAddress(
"glFramebufferRenderbuffer");
54 glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)GetAnyGLFuncAddress(
"glCheckFramebufferStatus");
83 #if defined(OPENGL_X11) 88 #elif defined(OPENGL_AQUA) 89 #if defined(OPENGL_AGL) 90 rwin->pixelFmtId =
NULL;
96 #elif defined(OPENGL_WINDOWS) 112 #if defined(OPENGL_X11) 117 #elif defined(OPENGL_AQUA) 118 #if defined(OPENGL_AGL) 119 aglDestroyPixelFormat(rwin->pixelFmtId);
125 #elif defined(OPENGL_WINDOWS) 147 #if defined(OPENGL_X11) 148 int attributeList[] = {
154 #if !defined(OPENGL_FBO) 161 rwin->
displayId = XOpenDisplay((
char *)display);
167 DefaultScreen(rwin->
displayId), attributeList);
176 G_warning(
_(
"Unable to create rendering context"));
183 width, height, v->depth);
189 #elif defined(OPENGL_AQUA) 190 #if defined(OPENGL_AGL) 191 int attributeList[] = {
197 #if !defined(OPENGL_FBO) 206 rwin->pixelFmtId = aglChoosePixelFormat(
NULL, 0, attributeList);
211 aglCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, 0, &(rwin->
windowId));
214 CGLPixelFormatAttribute attributeList[] = {
215 kCGLPFAColorSize, 24,
216 kCGLPFADepthSize, 32,
217 (CGLPixelFormatAttribute) 0
219 CGLPixelFormatObj pix;
223 error = CGLChoosePixelFormat(attributeList, &pix, &nvirt);
225 G_warning(
_(
"Unable to choose pixel format (CGL error = %d)"), error);
231 G_warning(
_(
"Unable to create context (CGL error = %d)"), error);
235 CGLDestroyPixelFormat(pix);
237 #elif defined(OPENGL_WINDOWS) 240 PIXELFORMATDESCRIPTOR pfd = {
241 sizeof(PIXELFORMATDESCRIPTOR),
262 wc.lpfnWndProc = DefWindowProc;
263 wc.lpszClassName =
"nviz";
265 if (!RegisterClass(&wc)) {
266 G_warning(
_(
"Unable to register window class"));
270 hWnd = CreateWindow(wc.lpszClassName, wc.lpszClassName, WS_POPUP,
271 CW_USEDEFAULT, CW_USEDEFAULT, width, height,
280 iPixelFormat = ChoosePixelFormat(rwin->
displayId, &pfd);
281 SetPixelFormat(rwin->
displayId, iPixelFormat, &pfd);
301 #if defined(OPENGL_X11) 305 if (rwin->
contextId == glXGetCurrentContext())
309 #elif defined(OPENGL_AQUA) 310 #if defined(OPENGL_AGL) 314 if (rwin->
contextId == aglGetCurrentContext())
321 error = CGLSetCurrentContext(rwin->
contextId);
323 G_warning(
_(
"Unable to set current context (CGL error = %d)"), error);
327 #elif defined(OPENGL_WINDOWS) 334 #if defined(OPENGL_FBO) 335 #if defined(OPENGL_WINDOWS) 339 GLuint framebuf, renderbuf, depthbuf;
342 glGenFramebuffers(1, &framebuf);
343 glBindFramebuffer(GL_FRAMEBUFFER, framebuf);
345 glGenRenderbuffers(1, &renderbuf);
346 glBindRenderbuffer(GL_RENDERBUFFER, renderbuf);
347 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8,
349 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
350 GL_RENDERBUFFER, renderbuf);
352 glGenRenderbuffers(1, &depthbuf);
353 glBindRenderbuffer(GL_RENDERBUFFER, depthbuf);
354 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
356 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
357 GL_RENDERBUFFER, depthbuf);
359 status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
360 if (status != GL_FRAMEBUFFER_COMPLETE) {
361 G_warning(
_(
"Incomplete framebuffer status (status = %d)"), status);
int Nviz_make_current_render_window(const struct render_window *rwin)
Make window current for rendering.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_free(void *)
Free allocated memory.
void Nviz_destroy_render_window(struct render_window *rwin)
Free render window.
struct render_window * Nviz_new_render_window(void)
Allocate memory for render window.
int Nviz_create_render_window(struct render_window *rwin, void *display, int width, int height)
Create render window.
void G_warning(const char *,...) __attribute__((format(printf
void Nviz_init_render_window(struct render_window *rwin)
Initialize render window.