ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all, again me... Although I have knowledge of the C language, I think my I/O on files is way basic for what I need/want to do. My problem is that I have made a BASH script to do a series of tasks, with a nice user interface (Ok, just messages going by asking for user interaction). Anyway, this program depended on file interaction, because after its execution it would generate a specially formatted text file with various information:
Linux version (uname -smrp)
Memory
Graphics
etc.
In a C program, how would I get all this information?
I'd like now to make the same but with a nice Graphical User Interface, where the user may enter all the neede data (the questions of before) and then just let the program execute and verify see the output from that file... I just don't know where to start...
My biggest problem is that I would not know how to edit a text file in a specific location (for example similar to a find/replace function in a text editor.
I want to use GTK, by the way. Thanks for any info.
If I were you I'd get all that information out of /proc. Specifically memory out of /proc/meminfo and linux version from /proc/sys/kernel/osrelease. I'm not sure about the graphics information, are you looking for info on the device or info on the drivers?
Originally posted by Darktyco I'm not sure about the graphics information, are you looking for info on the device or info on the drivers?
If it's possible about both. I'm particularly interested on the Renderer string (as reported by glxinfo under OpenGL renderer) and the OpenGL version (since there is posted the driver version). In my BASH script I used the commands with the aid of grep and gawk, but in C how would I accomplish that... I'm trying to as much as I can... But still I have no clue.
The uname stuff is best taken from the uname function in sys/utsname.h. It would be faster to get it that way then to read/parse the proc files. Read the man page (man 2 uname) to figure out how to use it.
As far as that grapics information, I am guessing that the OpenGL libraries would have functions to get that information.
Check out the Xfree Library Functions. I saw a few that might be helpful at a quick glance like "ScreenOfDisplay", "ServerVendor", and 'VendorRelease".
Yes, but it is a bit more complicated than that, I am afraid.
gl.h is probably in /usr/include/GL/ ... make sure you have the opengl-dev package or whatever RedHat call it nowadays.
However, to make the call, OpenGL must first be initialised and that is performed by the windowing system not OpenGL :-(
You are already using GTK and there are OpenGL widgets for that (gtkglext and gtkglarea, I believe) and there is GLX which is the OpenGL interface to XWindows, which would cover this.
I think the easiest thing for you to do is to use glut, which is a platform independent OpenGl rendering toolkit and extremely easy to use - at least just to get started. The same underlying calls can be made by GTK, raw XWindows or whatever. This is quickest and easiest to give you an example and I am lazy.
Example using glut
You will need to #include <GL/glut.h> which also brings in gl.h and you will need to link to libglut.so.
Write a function that calls glutInit() and glutCreateWindow() - this will perform the necessary initialisation and then call glGetString() to get the information you want. The window will not be displayed and you can then use the information as you desire. Then glutDestroyWindow() the window and return the string.
A c++ example:
Disclaimer: I don't know all the internals of glut, it's just useful sometimes, but you should get the result you want - it runs without the glutInit() call but the manual says this is needed - go figure!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.