views:

78

answers:

3

I have to make a multiplayer game and give the users(on different) an option to change their screen resolution in order to sustain their hardware requirements.Similar to counterstrike. How can I implement this in c ? how can I give the users sitting on different computers an option to change their screen resolution ?

+2  A: 

There is no standard method in the C language or standard library, and this is entirely dependent on the graphics library you're writing the program in.

If you want a really simple way to do this, you can use xrandr and system():

#include <stdlib.h>
system("xrandr > resolutions.tmp"); // direct output to 'resolutions.tmp'
// retrieve possible resolutions from 'resolutions.tmp'
system("xrandr -s resolution_id"); // select a certain screen resolution

Edit: as you've mentioned you're using OpenGL on Ubuntu, you can follow some of the steps in the following article to change the resolution using library calls:

http://www.opengl.org/wiki/Programming_OpenGL_in_Linux:_Changing_the_Screen_Resolution

Delan Azabani
A: 

http://www.opengl.org/wiki/Programming_OpenGL_in_Linux:_Changing_the_Screen_Resolution worked for me. At the bottom you have command to compile, use it but add -std=c99. Keywords for google (no offense, I would appreciate them): opengl screen resolution

Dadam
A: 

You will definitely use a library which handles the os-specific details for you. This library would be responsible for finding out which combinations fo screen resolution, colour depth and various buffers are available, and then you can choose one, or give the user the option to choose one.

For example, GLFW does this by way of its glfwGetVideoModes function.

The underlying code to do this is both platform-specific, and ugly. You want to spend some time writing your game not messing with it.

MarkR