简体   繁体   English

C ++中的屏幕分辨率

[英]screen resolution in c++

I made a simple game in C++ using SDL 1.2, and I used functions from wtypes.h to get display resolution, and then set game resolution at it's value. 我使用SDL 1.2在C ++中制作了一个简单的游戏,并使用了wtypes.h中的函数来获取显示分辨率,然后将游戏分辨率设置为该值。 The problem is that when i compile it, exe file (my game's resolution) is dependent on resolution of computer it's compiled on. 问题在于,当我编译它时,exe文件(我的游戏的分辨率)取决于它所编译的计算机的分辨率。 So when i copy exe file to another computer and it's run, the game resolution will be the same as my computer's resolution, not that computer's (unless they have same resolution). 因此,当我将exe文件复制到另一台计算机并运行时,游戏分辨率将与我计算机的分辨率相同,而不是该计算机的分辨率(除非它们具有相同的分辨率)。 Is there a way get display resolution at runtime? 有没有办法在运行时获得显示分辨率? I understand I can simply compile my cpp file at that computer, but that requires C:B/VS, dll files and linking dll files :/ 我知道我可以在那台计算机上编译我的cpp文件,但这需要C:B / VS,dll文件和链接dll文件:/

The SDL_GetVideoInfo function returns a read-only pointer to a structure containing information about the video hardware. SDL_GetVideoInfo函数返回指向包含有关视频硬件信息的结构的只读指针。 If it is called before SDL_SetVideoMode , member current_w and current_h of the returned structure will contain the pixel format of the best video mode. 如果在SDL_SetVideoMode之前SDL_SetVideoMode它,则返回结构的成员current_wcurrent_h将包含最佳视频模式的像素格式。

#include "SDL.h"

SDL_Init( SDL_INIT_VIDEO );
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); 
width = videoInfo->current_w;
height = videoInfo->current_h;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM