Subversion Repositories seema-scanner

Rev

Rev 1 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 16
Line 1... Line 1...
1
#include "OpenGLContext.h"
1
#include "OpenGLContext.h"
2
#include <GLFW/glfw3.h>
2
#include <GLFW/glfw3.h>
3
 
3
 
-
 
4
#include <stdio.h>
4
#ifdef __LINUX__
5
#ifdef __unix__
5
    #define GLFW_EXPOSE_NATIVE_X11
6
    #define GLFW_EXPOSE_NATIVE_X11
6
    #define GLFW_EXPOSE_NATIVE_GLX
7
    #define GLFW_EXPOSE_NATIVE_GLX
7
    #include <cstring>
8
    #include <cstring>
-
 
9
    #include <X11/X.h>
-
 
10
 typedef XID RRCrtc;
8
    #include <GLFW/glfw3native.h>
11
    #include <GLFW/glfw3native.h>
9
#endif
12
#endif
10
 
13
 
11
struct OpenGLContext::OpenGLContextInfo{
14
struct OpenGLContext::OpenGLContextInfo{
12
    GLFWmonitor* monitor;
15
    GLFWmonitor* monitor;
Line 68... Line 71...
68
    const GLFWvidmode *videoMode = glfwGetVideoMode(contextInfo->monitor);
71
    const GLFWvidmode *videoMode = glfwGetVideoMode(contextInfo->monitor);
69
 
72
 
70
    screenResX = videoMode->width;
73
    screenResX = videoMode->width;
71
    screenResY = videoMode->height;
74
    screenResY = videoMode->height;
72
 
75
 
-
 
76
    // Set window hints
-
 
77
    glfwDefaultWindowHints();
-
 
78
    // highest available refresh rate
-
 
79
    glfwWindowHint(GLFW_REFRESH_RATE, 0);
-
 
80
 
73
    // Create fullscreen window
81
    // Create fullscreen window
74
    contextInfo->window = glfwCreateWindow(screenResX, screenResY, "GLFW OpenGL Context", contextInfo->monitor, NULL);
82
    contextInfo->window = glfwCreateWindow(screenResX, screenResY, "GLFW OpenGL Context", contextInfo->monitor, NULL);
75
 
83
 
-
 
84
    // make cursor invisible
-
 
85
    glfwSetInputMode(contextInfo->window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
-
 
86
 
76
#ifdef __unix__
87
#ifdef a__unix__
77
    Display *display = glfwGetX11Display();
88
    Display *display = glfwGetX11Display();
78
    Window window = glfwGetX11Window(contextInfo->window);
89
    Window window = glfwGetX11Window(contextInfo->window);
79
 
90
 
-
 
91
    Atom wmStateAbove = XInternAtom( display, "_NET_WM_STATE_ABOVE", 1 );
-
 
92
    if( wmStateAbove != None ) {
-
 
93
        printf( "_NET_WM_STATE_ABOVE has atom of %ld\n", (long)wmStateAbove );
-
 
94
    } else {
-
 
95
        printf( "ERROR: cannot find atom for _NET_WM_STATE_ABOVE !\n" );
-
 
96
    }
-
 
97
 
-
 
98
    Atom wmNetWmState = XInternAtom( display, "_NET_WM_STATE", 1 );
-
 
99
    if( wmNetWmState != None ) {
-
 
100
        printf( "_NET_WM_STATE has atom of %ld\n", (long)wmNetWmState );
-
 
101
    } else {
-
 
102
        printf( "ERROR: cannot find atom for _NET_WM_STATE !\n" );
-
 
103
    }
-
 
104
    // set window always on top hint
-
 
105
    if( wmStateAbove != None ) {
-
 
106
        XClientMessageEvent xclient;
-
 
107
        memset( &xclient, 0, sizeof (xclient) );
-
 
108
        //
-
 
109
        //window  = the respective client window
-
 
110
        //message_type = _NET_WM_STATE
-
 
111
        //format = 32
-
 
112
        //data.l[0] = the action, as listed below
-
 
113
        //data.l[1] = first property to alter
-
 
114
        //data.l[2] = second property to alter
-
 
115
        //data.l[3] = source indication (0-unk,1-normal app,2-pager)
-
 
116
        //other data.l[] elements = 0
-
 
117
        //
-
 
118
        xclient.type = ClientMessage;
-
 
119
        xclient.window = window; // GDK_WINDOW_XID(window);
-
 
120
        xclient.message_type = wmNetWmState; //gdk_x11_get_xatom_by_name_for_display( display, "_NET_WM_STATE" );
-
 
121
        xclient.format = 32;
-
 
122
        xclient.data.l[0] = 1; // add the state
-
 
123
        xclient.data.l[1] = wmStateAbove; //gdk_x11_atom_to_xatom_for_display (display, state1);
-
 
124
        xclient.data.l[2] = 0; //gdk_x11_atom_to_xatom_for_display (display, state2);
-
 
125
        xclient.data.l[3] = 0;
-
 
126
        xclient.data.l[4] = 0;
-
 
127
        //gdk_wmspec_change_state( FALSE, window,
-
 
128
        //  gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
-
 
129
        //  GDK_NONE );
-
 
130
        XSendEvent( display,
-
 
131
          //mywin - wrong, not app window, send to root window!
-
 
132
          DefaultRootWindow(display),
-
 
133
          False,
-
 
134
          SubstructureRedirectMask | SubstructureNotifyMask,
-
 
135
          (XEvent *)&xclient );
-
 
136
      }
80
//    // Set swap interval to 1 for standard vsync
137
//    // Set swap interval to 1 for standard vsync
81
//    typedef GLvoid (*glXSwapIntervalSGIFunc) (GLint);
138
//    typedef GLvoid (*glXSwapIntervalSGIFunc) (GLint);
82
//    const char *glx_extensions = glXQueryExtensionsString(display, screenNum);
139
//    const char *glx_extensions = glXQueryExtensionsString(display, screenNum);
83
//    if (strstr(glx_extensions, "GLX_SGI_swap_control")) {
140
//    if (strstr(glx_extensions, "GLX_SGI_swap_control")) {
84
//        PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalSGI");
141
//        PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalSGI");
85
//        SwapIntervalSGI(1);
142
//        SwapIntervalSGI(1);
86
//    } else if (strstr(glx_extensions, "GLX_EXT_swap_control")) {
143
//    } else if (strstr(glx_extensions, "GLX_EXT_swap_control")) {
87
        PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
144
//        PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
88
        SwapIntervalEXT(display, window, 1);
145
//        SwapIntervalEXT(display, window, 1);
89
//    } else {
146
//    } else {
90
//        std::cerr << "OpenGLContext.Unix Error: Could not access swap interval extension!" << std::endl;
147
//        std::cerr << "OpenGLContext.Unix Error: Could not access swap interval extension!" << std::endl;
91
//    }
148
//    }
92
#endif
149
#endif
93
 
150
 
94
    glfwMakeContextCurrent(contextInfo->window);
151
    glfwMakeContextCurrent(contextInfo->window);
-
 
152
 
95
    // Set vsync (swap interval 1)
153
    // Set vsync (swap interval 1)
96
    glfwSwapInterval(1);
154
    glfwSwapInterval(1);
97
 
155
 
98
    // Adjust gamma to one
156
    // Adjust gamma to one
99
    this->setGamma(1.0);
157
    this->setGamma(1.0);
Line 113... Line 171...
113
    glfwSwapBuffers(contextInfo->window);
171
    glfwSwapBuffers(contextInfo->window);
114
 
172
 
115
    // Poll events in order not to lock up
173
    // Poll events in order not to lock up
116
    glfwPollEvents();
174
    glfwPollEvents();
117
    //glfwWaitEvents();
175
    //glfwWaitEvents();
118
    glFinish();
176
//    glFinish();
119
}
177
}
120
 
178
 
121
OpenGLContext::~OpenGLContext(){
179
OpenGLContext::~OpenGLContext(){
122
 
180
 
123
    glfwDestroyWindow(contextInfo->window);
181
    glfwDestroyWindow(contextInfo->window);