GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


vsync by DELTRON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
// GLOBALS
int VSYNC_STATE;

// tests vsync state change
bool test_vsync(void)
{
    // get current vsync state
    int    VSYNC_STATE = wglGetSwapIntervalEXT();
    // attempt to change to another state
    wglSwapIntervalEXT(!VSYNC_STATE);
    int nvss = wglGetSwapIntervalEXT();
    // return false if failed
    if (VSYNC_STATE == nvss) return false;
    // else, it's changeable.. restore state
    wglSwapIntervalEXT(VSYNC_STATE);
    return true;
}

// set vsync state (also records global state)
bool set_vsync(int vs)
{
    VSYNC_STATE = wglGetSwapIntervalEXT();
    if (VSYNC_STATE==vs) return true;
    wglSwapIntervalEXT(vs);
    int nvss = wglGetSwapIntervalEXT();
    return (vs==nvss);
}

// restores previous state
void restore_vsync(void)
{
    wglSwapIntervalEXT(VSYNC_STATE);
}    

// init extensions - must not be called before establishing an opengl rendering context
void initextensions()
{
  const unsigned char * extensions_string = glGetString(GL_EXTENSIONS);
  if (!extensions_string)
  {
      MessageBox(NULL,"Could not get supported OpenGL extension list.","ERROR",MB_ICONERROR);
      exit(0);
  }
  if (strstr((const char *)extensions_string,"WGL_EXT_swap_control"))
  {
    wglSwapIntervalEXT = (PFNWGLEXTSWAPCONTROLPROC)wglGetProcAddress("wglSwapIntervalEXT");
    wglGetSwapIntervalEXT = (PFNWGLEXTGETSWAPINTERVALPROC)wglGetProcAddress("wglGetSwapIntervalEXT");
  }
  else
  {
      MessageBox(NULL,"Did not find support for WGL_EXT_swap_control.","ERROR",MB_ICONERROR);
      exit(0);
  }
}