Talk:Programming OpenGL in Linux: Changing the Screen Resolution

From OpenGL Wiki
Revision as of 19:00, 26 August 2011 by FrederikHertzum (talk | contribs) (Alternative to system)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Alternative to system

One could use popen instead of system and avoid the creation of files (in a potential read-only environment) The following is an example about how to do so, calling xrandr and writing it's output to stdout:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
	FILE * f = popen("xrandr", "r");
	char buffer [256];
	int i = 0;
	while (feof(f) == 0)
	{
		memset(buffer, 0, 256);
		fread(buffer, 1, 255, f);
		fputs(buffer, stdout);
	}
	pclose(f);
}