$search
00001 00002 #ifdef LINUX 00003 00004 #include <blort/GLWindow/GLWindow.h> 00005 #include <stdio.h> 00006 #include <stdexcept> 00007 #include <vector> 00008 00009 namespace blortGLWindow{ 00010 00011 void GLWindow::init(unsigned int width, unsigned int height, const char* name, bool visible){ 00012 GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; 00013 dpy = XOpenDisplay(NULL); 00014 00015 if(dpy == NULL){ 00016 throw std::runtime_error("[GLWindow::init] Error cannot connect to X server"); 00017 } 00018 00019 root = DefaultRootWindow(dpy); 00020 vi = glXChooseVisual(dpy, 0, att); 00021 00022 if(vi == NULL) 00023 throw std::runtime_error("[GLWindow::init] Error no appropriate visual found"); 00024 00025 cmap = XCreateColormap(dpy, root, vi->visual, AllocNone); 00026 00027 swa.colormap = cmap; 00028 swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; 00029 00030 glWin = XCreateWindow(dpy, root, 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa); 00031 wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", true); 00032 XSetWMProtocols(dpy, glWin, &wmDelete, 1); 00033 00034 if ( visible ) 00035 XMapWindow(dpy, glWin); //makes it visible 00036 00037 XStoreName(dpy, glWin, name); 00038 00039 glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); 00040 glXMakeCurrent(dpy, glWin, glc); 00041 00042 printf("OpenGL Version: %s\n", glGetString(GL_VERSION)); 00043 00044 glXSwapBuffers(dpy, glWin); 00045 } 00046 00047 void GLWindow::quit(){ 00048 glXMakeCurrent(dpy, None, NULL); 00049 glXDestroyContext(dpy, glc); 00050 XDestroyWindow(dpy, glWin); 00051 XCloseDisplay(dpy); 00052 } 00053 00054 GLWindow::GLWindow(){ 00055 init(320,240,"OpenGL Window"); 00056 } 00057 GLWindow::GLWindow(unsigned int width, unsigned int height){ 00058 init(width, height, "OpenGL Window"); 00059 } 00060 GLWindow::GLWindow(unsigned int width, unsigned int height, const char* name, bool visible){ 00061 init(width, height, name, visible); 00062 } 00063 GLWindow::~GLWindow(){ 00064 quit(); 00065 } 00066 00067 void GLWindow::Activate(){ 00068 glXMakeCurrent(dpy, glWin, glc); 00069 } 00070 00071 void GLWindow::Update(){ 00072 glXSwapBuffers(dpy, glWin); 00073 } 00074 00075 } /* namespace */ 00076 00077 #endif /* LINUX */ 00078