21 #if defined(OPENGL_WINDOWS) && defined(OPENGL_FBO)
22 static int gl_funcs_found = 0;
23 static PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
24 static PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
25 static PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
26 static PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
27 static PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
28 static PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
29 static PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
32 static void *GetAnyGLFuncAddress(
const char *
name)
34 void *p = (
void *)wglGetProcAddress(
name);
36 if (p == 0 || p == (
void *)0x1 || p == (
void *)0x2 || p == (
void *)0x3 ||
38 HMODULE module = LoadLibraryA(
"opengl32.dll");
40 p = (
void *)GetProcAddress(module,
name);
47 static void find_gl_funcs()
53 (PFNGLGENFRAMEBUFFERSPROC)GetAnyGLFuncAddress(
"glGenFramebuffers");
55 (PFNGLBINDFRAMEBUFFERPROC)GetAnyGLFuncAddress(
"glBindFramebuffer");
57 (PFNGLGENRENDERBUFFERSPROC)GetAnyGLFuncAddress(
"glGenRenderbuffers");
59 (PFNGLBINDRENDERBUFFERPROC)GetAnyGLFuncAddress(
"glBindRenderbuffer");
60 glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)GetAnyGLFuncAddress(
61 "glRenderbufferStorage");
62 glFramebufferRenderbuffer =
63 (PFNGLFRAMEBUFFERRENDERBUFFERPROC)GetAnyGLFuncAddress(
64 "glFramebufferRenderbuffer");
65 glCheckFramebufferStatus =
66 (PFNGLCHECKFRAMEBUFFERSTATUSPROC)GetAnyGLFuncAddress(
67 "glCheckFramebufferStatus");
96 #if defined(OPENGL_X11)
101 #elif defined(OPENGL_AQUA)
102 #if defined(OPENGL_AGL)
103 rwin->pixelFmtId =
NULL;
109 #elif defined(OPENGL_WINDOWS)
125 #if defined(OPENGL_X11)
130 #elif defined(OPENGL_AQUA)
131 #if defined(OPENGL_AGL)
132 aglDestroyPixelFormat(rwin->pixelFmtId);
138 #elif defined(OPENGL_WINDOWS)
160 #if defined(OPENGL_X11)
161 int attributeList[] = {GLX_RGBA,
170 #if !defined(OPENGL_FBO)
176 rwin->
displayId = XOpenDisplay((
char *)display);
191 G_warning(
_(
"Unable to create rendering context"));
204 #elif defined(OPENGL_AQUA)
205 #if defined(OPENGL_AGL)
206 int attributeList[] = {AGL_RGBA,
215 #if !defined(OPENGL_FBO)
223 rwin->pixelFmtId = aglChoosePixelFormat(
NULL, 0, attributeList);
228 aglCreatePBuffer(
width,
height, GL_TEXTURE_2D, GL_RGBA, 0,
232 CGLPixelFormatAttribute attributeList[] = {
233 kCGLPFAColorSize, 24, kCGLPFADepthSize, 32, (CGLPixelFormatAttribute)0};
234 CGLPixelFormatObj pix;
238 error = CGLChoosePixelFormat(attributeList, &pix, &nvirt);
240 G_warning(
_(
"Unable to choose pixel format (CGL error = %d)"), error);
246 G_warning(
_(
"Unable to create context (CGL error = %d)"), error);
250 CGLDestroyPixelFormat(pix);
252 #elif defined(OPENGL_WINDOWS)
256 PIXELFORMATDESCRIPTOR pfd = {
257 sizeof(PIXELFORMATDESCRIPTOR),
288 wc.lpfnWndProc = DefWindowProc;
289 wc.lpszClassName =
"nviz";
291 if (!RegisterClass(&wc)) {
292 G_warning(
_(
"Unable to register window class"));
296 hWnd = CreateWindow(wc.lpszClassName, wc.lpszClassName, WS_POPUP,
306 iPixelFormat = ChoosePixelFormat(rwin->
displayId, &pfd);
307 SetPixelFormat(rwin->
displayId, iPixelFormat, &pfd);
327 #if defined(OPENGL_X11)
331 if (rwin->
contextId == glXGetCurrentContext())
335 #elif defined(OPENGL_AQUA)
336 #if defined(OPENGL_AGL)
340 if (rwin->
contextId == aglGetCurrentContext())
347 error = CGLSetCurrentContext(rwin->
contextId);
349 G_warning(
_(
"Unable to set current context (CGL error = %d)"), error);
353 #elif defined(OPENGL_WINDOWS)
360 #if defined(OPENGL_FBO)
361 #if defined(OPENGL_WINDOWS)
365 GLuint framebuf, renderbuf, depthbuf;
368 glGenFramebuffers(1, &framebuf);
369 glBindFramebuffer(GL_FRAMEBUFFER, framebuf);
371 glGenRenderbuffers(1, &renderbuf);
372 glBindRenderbuffer(GL_RENDERBUFFER, renderbuf);
373 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rwin->
width, rwin->
height);
374 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
375 GL_RENDERBUFFER, renderbuf);
377 glGenRenderbuffers(1, &depthbuf);
378 glBindRenderbuffer(GL_RENDERBUFFER, depthbuf);
379 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, rwin->
width,
381 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
382 GL_RENDERBUFFER, depthbuf);
384 status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
385 if (status != GL_FRAMEBUFFER_COMPLETE) {
386 G_warning(
_(
"Incomplete framebuffer status (status = %d)"), status);
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
int Nviz_create_render_window(struct render_window *rwin, void *display UNUSED, int width, int height)
Create render window.
struct render_window * Nviz_new_render_window(void)
Allocate memory for render window.
void Nviz_destroy_render_window(struct render_window *rwin)
Free render window.
void Nviz_init_render_window(struct render_window *rwin)
Initialize render window.
int Nviz_make_current_render_window(const struct render_window *rwin)
Make window current for rendering.