[Add] Add options for enabling vsync.

This commit is contained in:
Allanis 2013-12-25 00:35:51 +00:00
parent 7e2e21c235
commit 7534fe3c9d
3 changed files with 13 additions and 4 deletions

View File

@ -63,6 +63,7 @@ static void print_usage(char** argv) {
LOG("Options are:");
LOG(" -f, --fullscreen - Fullscreen");
LOG(" -F, --fps - Limit frames per second");
LOG(" -V, --vsync - Enable vsync");
LOG(" -d s, --data s - Set the data file to be s");
LOG(" -W n - Set width to n");
LOG(" -H n - Set height to n");
@ -120,7 +121,8 @@ int conf_loadConfig(const char* file) {
if(i) { gl_screen.flags |= OPENGL_AA_LINE; i = 0; }
conf_loadBool("aa_polygon", i);
if(i) { gl_screen.flags |= OPENGL_AA_POLYGON; i = 0; }
conf_loadBool("vsync", i);
if(i) { gl_screen..flags |= OPENG_VSYNC; i = 0; }
/* FPS. */
conf_loadBool("showfps", show_fps);
conf_loadInt("maxfps", max_fps);
@ -211,6 +213,7 @@ void conf_parseCLI(int argc, char** argv) {
static struct option long_options[] = {
{ "fullscreen", no_argument, 0, 'f' },
{ "fps", required_argument, 0, 'F' },
{ "vysnc", no_argument, 0, 'V' },
{ "data", required_argument, 0, 'd' },
{ "joystick", required_argument, 0, 'j' },
{ "Joystick", required_argument, 0, 'J' },
@ -227,7 +230,7 @@ void conf_parseCLI(int argc, char** argv) {
int c = 0;
while((c = getopt_long(argc, argv,
"fF:d:j:J:W:H:MSm:s:Ghv",
"fF:Vd:j:J:W:H:MSm:s:Ghv",
long_options, &option_index)) != -1) {
switch(c) {
case 'f':
@ -236,6 +239,9 @@ void conf_parseCLI(int argc, char** argv) {
case 'F':
max_fps = atoi(optarg);
break;
case 'V':
gl_screen.flags |= OPENGL_VSYNC;
break;
case 'd':
data = strdup(optarg);
break;

View File

@ -871,6 +871,8 @@ int gl_init(void) {
/* Set opengl flags. */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Ideally want double buffering. */
if(gl_has(OPENGL_VSYNC))
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
/* Get available fullscreen modes. */
if(gl_has(OPENGL_FULLSCREEN)) {

View File

@ -25,8 +25,9 @@
#define OPENGL_AA_POINT (1<<2) /**< Antialiasing points. */
#define OPENGL_AA_LINE (1<<3) /**< Antialiasing lines. */
#define OPENGL_AA_POLYGON (1<<4) /**< Antialiasing polygons. */
#define OPENGL_FRAG_SHADER (1<<5) /**< Fragment shaders. */
#define OPENGL_VERT_SHADER (1<<6) /**< Vertex shaders. */
#define OPENGL_VSYNC (1<<5) /**< Sync to monitor vertical refresh rate. */
#define OPENGL_FRAG_SHADER (1<<6) /**< Fragment shaders. */
#define OPENGL_VERT_SHADER (1<<7) /**< Vertex shaders. */
#define gl_has(f) (gl_screen.flags & (f)) /**< Check for the flag. */
/**