开发者

Set screen resolution in game programming [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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 ?


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜