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[] = {
171 #if !defined(OPENGL_FBO)
178 rwin->
displayId = XOpenDisplay((
char *)display);
193 G_warning(
_(
"Unable to create rendering context"));
206 #elif defined(OPENGL_AQUA)
207 #if defined(OPENGL_AGL)
208 int attributeList[] = {
218 #if !defined(OPENGL_FBO)
227 rwin->pixelFmtId = aglChoosePixelFormat(
NULL, 0, attributeList);
232 aglCreatePBuffer(
width,
height, GL_TEXTURE_2D, GL_RGBA, 0,
236 CGLPixelFormatAttribute attributeList[] = {
237 kCGLPFAColorSize, 24, kCGLPFADepthSize, 32, (CGLPixelFormatAttribute)0};
238 CGLPixelFormatObj pix;
242 error = CGLChoosePixelFormat(attributeList, &pix, &nvirt);
244 G_warning(
_(
"Unable to choose pixel format (CGL error = %d)"), error);
250 G_warning(
_(
"Unable to create context (CGL error = %d)"), error);
254 CGLDestroyPixelFormat(pix);
256 #elif defined(OPENGL_WINDOWS)
260 PIXELFORMATDESCRIPTOR pfd = {
261 sizeof(PIXELFORMATDESCRIPTOR),
292 wc.lpfnWndProc = DefWindowProc;
293 wc.lpszClassName =
"nviz";
295 if (!RegisterClass(&wc)) {
296 G_warning(
_(
"Unable to register window class"));
300 hWnd = CreateWindow(wc.lpszClassName, wc.lpszClassName, WS_POPUP,
310 iPixelFormat = ChoosePixelFormat(rwin->
displayId, &pfd);
311 SetPixelFormat(rwin->
displayId, iPixelFormat, &pfd);
331 #if defined(OPENGL_X11)
335 if (rwin->
contextId == glXGetCurrentContext())
339 #elif defined(OPENGL_AQUA)
340 #if defined(OPENGL_AGL)
344 if (rwin->
contextId == aglGetCurrentContext())
351 error = CGLSetCurrentContext(rwin->
contextId);
353 G_warning(
_(
"Unable to set current context (CGL error = %d)"), error);
357 #elif defined(OPENGL_WINDOWS)
364 #if defined(OPENGL_FBO)
365 #if defined(OPENGL_WINDOWS)
369 GLuint framebuf, renderbuf, depthbuf;
372 glGenFramebuffers(1, &framebuf);
373 glBindFramebuffer(GL_FRAMEBUFFER, framebuf);
375 glGenRenderbuffers(1, &renderbuf);
376 glBindRenderbuffer(GL_RENDERBUFFER, renderbuf);
377 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rwin->
width, rwin->
height);
378 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
379 GL_RENDERBUFFER, renderbuf);
381 glGenRenderbuffers(1, &depthbuf);
382 glBindRenderbuffer(GL_RENDERBUFFER, depthbuf);
383 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, rwin->
width,
385 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
386 GL_RENDERBUFFER, depthbuf);
388 status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
389 if (status != GL_FRAMEBUFFER_COMPLETE) {
390 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.