Welcome

Troves being gleaned while surfing on the Internet mostly about computer/IT/system skills and tricks, Welcome here ...
Powered By Blogger

Disclaimer

This blog is written by the owner with real practices and tests and intended to hold all original posts except there is a clear declaration for referencing from others. Thanks for tagging with the source link or other tips for reference from here if you would like to quote partial or full text from posts in this blog.

Saturday, January 8, 2011

Enable X Shared Memory Extension Pixmaps

Definitely not encouraged to use, sometimes this feature is needed for using certain applications what depends on this deprecated X window extension.

Found the solution on http://fxc.noaa.gov/FSD-NVIDIA-OB9-FXC.htm. More precisely, an example illustrating the details with Nvidia series on Fedora 14 is shown as follows.

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 260.19.29 
# (buildmeister@swio-display-x86-rhel47-04.nvidia.com)  Wed Dec 
# 8 12:27:39 PST 2010


Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
    FontPath        "/usr/share/fonts/default/Type1"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/input/mice"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

    # generated from data in "/etc/sysconfig/keyboard"
    Identifier     "Keyboard0"
    Driver         "kbd"
    Option         "XkbLayout" "us"
    Option         "XkbModel" "pc105"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    HorizSync       28.0 - 33.0
    VertRefresh     43.0 - 72.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    Option    "AllowSHMPixmaps" "true"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

The enabling appendix is simply the single line below.
Option "AllowSHMPixmaps" "true"

Then reboot the system to make it effect.

Following code snippet could be used for verifying the availability of this feature:

int vmajor;

int vminor;
bool vpixmap;
bool shm_flag;
if (XShmQueryVersion(window->getDisplay(),&vmajor,&vminor,&vpixmap) != True) { 
    cerr << "X Shared Memory Extension not supported." << endl;
    shm_flag=false;
}
else if (vpixmap != True) { 
    cerr << "X Shared Memory Extension Pixmap not supported." << endl;
    shm_flag=false;
}
else {
    // do what is relying on the MIT-SHM feature from here on
    ......
}

Thursday, January 6, 2011

How to get the screen resolution in Linux C (and more X window information)

Linux C: get the screen resolution and window size 

Happened to necessitate the retrieval of information about the screen of the canonical X window system (X11)  in use while I am employing Fedora Linux release 14.

Some guys (or gals maybe) suggest achieving this by GTK calls like gdk_screen_get_resolution or the like, I will prefer to using the legacy routines of Xlib for accessing to the X window information. For at least one thing, the X window system is presumably more likely to be installed in Linux OS than is the GTK/GTK+ libraries in my view.

Actually it is quite simpler than it might be postulated to be:

// -----------------------------------------------------------
// Purpose : simply retrieve current X screen resolution and 
//    the size of current root window of the default 
//    screen of curent default window
// -----------------------------------------------------------

#include <X11/Xlib.h>
#include <stdio.h>

int getRootWindowSize(int *w, int *h)
{
 Display* pdsp = NULL;
 Window wid = 0;
 XWindowAttributes xwAttr;

 pdsp = XOpenDisplay( NULL );
 if ( !pdsp ) {
  fprintf(stderr, "Failed to open default display.\n");
  return -1;
 }

 wid = DefaultRootWindow( pdsp );
 if ( 0 > wid ) {
  fprintf(stderr, "Failed to obtain the root windows Id "
      "of the default screen of given display.\n");
  return -2;
 }
 
 Status ret = XGetWindowAttributes( pdsp, wid, &xwAttr );
 *w = xwAttr.width;
 *h = xwAttr.height;

 XCloseDisplay( pdsp );
 return 0;
}

int getScreenSize(int *w, int*h)
{

 Display* pdsp = NULL;
 Screen* pscr = NULL;

 pdsp = XOpenDisplay( NULL );
 if ( !pdsp ) {
  fprintf(stderr, "Failed to open default display.\n");
  return -1;
 }

    pscr = DefaultScreenOfDisplay( pdsp );
 if ( !pscr ) {
  fprintf(stderr, "Failed to obtain the default screen of given display.\n");
  return -2;
 }

 *w = pscr->width;
 *h = pscr->height;

 XCloseDisplay( pdsp );
 return 0;
}

int main()
{
 int w, h;

 getScreenSize(&w, &h);
 printf (" Screen:  width = %d, height = %d \n", w, h);

 getRootWindowSize(&w, &h);
 printf (" Root Window:  width = %d, height = %d \n", w, h);
 
 return 1;
 
}


/* gcc -o $@ $< -lX11 */


/* set ts=4 sts=4 tw=100 sw=4 */
You can also retrieve more information about the X window system you are currently using, such as display name and the tag of vendor.
// -----------------------------------------------------------
// Purpose : simply retrieve current X windows information
// -----------------------------------------------------------
#define XLIB_ILLEGAL_ACCESS
#include <X11/Xlib.h>
#include <stdio.h>

int main()
{

 Display* pdsp = XOpenDisplay(NULL);
 Window wid = DefaultRootWindow(pdsp);

 Screen* pwnd = DefaultScreenOfDisplay(pdsp);
 int sid = DefaultScreen(pdsp);
 
 XWindowAttributes xwAttr;
 XGetWindowAttributes(pdsp,wid,&xwAttr);

 printf (" name : %s\n vendor : %s\n", pdsp->display_name, pdsp->vendor);
 printf (" pos : (%d, %d), width = %d, height = %d \n",
   xwAttr.x, xwAttr.y, xwAttr.width, xwAttr.height);

 XCloseDisplay( pdsp );
 
 return 1;
}


/* gcc -o $@ $< -lX11 */
/* set ts=4 sts=4 tw=100 sw=4 */

Note that here "#define XLIB_ILLEGAL_ACCESS" was used for accessing to some of the data member in the Display structure in C.

For more data member accessible, see the definition/declarations in the header /usr/include/X11/Xlib.h.

PS: It is thankfully in the courtesy of http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html to make the code snippets I posted above have a highlighted effect and look organized more trimly (otherwise it is always bit of mangled!) Thanks to craftyfella!

Monday, January 3, 2011

Can not find man page for GLUT routines in Linux?

I made up the man page for GLUT (so that I can ^K to call the API manual out while the cursor is on the words symbolizing GLUT routines) by the simplest way:

sudo yum  list "*glut*"

more than a couple was found and following two are among the alternatives:

sudo -y install freeglut freeglut-evel


now enter into vim again and try ^K on "glutWindowSize" for instance, check if it works now.

Fix bugs for Buidling installation of G3D 7.01 in Fedora 14

Today I am porting such and such a  project which is dependent on G3D and for historical reasons this project could not work with other versions of G3D including the latest ones but versions before 8.0 since it calls some of the routines in the Libraries whose prototypes had been modified!

In conclusion, we have two bugs to fix before the G3D 7.01 library can be successfully built from the downloaded source code found at http://sourceforge.net/projects/g3d/files/g3d-cpp/7.01/G3D-7.01-src.zip/download in Fedora 14. I deem  the same problems and solutions  may as well be portable to other Linux distributions and various versions of specific distribution.

1. Edit   GLG3D.lib/include/GLG3D/Discovery2.h, add the header including definition of the macro "INT_MAX" which was referred at line 68 in this file, where the first problem you will run across in the first try of building using "./buildg3d  all" or "buildg3d --install all", or so forth the similar.

 I simply added "#include <limits.h>" right after "#include <string.h>", actually an c++ header equivalent is "climits".


(Where is "INT_MAX", "LONG_MAX", etc, defined?)
I found the container header of this macro at http://www.fredosaurus.com/notes-cpp/90summaries/summary-headers.html, you may find it useful further in the future.

2. In order to get a complete installation, test code should not be skipped either, so this fix is necessary:

in tools/viewer/MD2Viewer.cpp : 108, change
currentPose = MD2Model::Pose::Pose(MD2Model::STAND, 0);
into
currentPose = MD2Model::Pose(MD2Model::STAND, 0);

I am bit of wondering why there the class Pose 's constructor should be called in this explicit way with this originally buggy code.

3. now get back to the source directory (where ./buildg3d lies),
./buildg3d --install all"

then the library will be installed straightforwardly.

A Funny Time Varying VIM color scheme switching

Vi/vim is really the most popular editor under Linux esp. for those advanced users or Linux fans, even though there are dozen of other featured ones including visual editors and the most worthy of mentioning, Emacs for programming gurus.

Here I just got a whimsy yet actually a fortuitous idea, to make this editor of daily use to be adaptive with current local time periods such as morning, noon, evening and other phases of a day.

The snippet  meant to be placed in or tailed at the vim configuration file, as is mostly the /etc/vimrc or $HOME/vimrc, will make the vim editor apply different color scheme that is meaningfully in accordance with the time of period when vim is launched. Additionally, color schemes for other time of period than morning and evening will be changed with the weekday.


" # intelligent colorscheme switching
let weekday=system('date +%u')
let hour=system('date +%H')

" if the shell command gets any exception during execution, nothing will be 
" done on color scheme setting
if !v:shell_error


   " in other time slots than mornings and evenings, scheme to be applied depends 
   " on which the weekday it is today, beginning from 1 as Monday, through 6 as 
   " Saturday and Sunday numbered as 0
    if     1== weekday
        let coloration="elflord"
    elseif 2 == weekday
        let coloration="koehler"
    elseif 3 == weekday
        let coloration="slate"
    elseif 4 == weekday
        let coloration="zellner"
    elseif 5 == weekday
        let coloration="torte"
    elseif 6 == weekday
        let coloration="ron"
    else "Sundays
        let coloration="blue"
    endif 
 
    " exert the color scheme application
    execute "colorscheme ".coloration 
 
    " in mornings, alwasy using the "morning" scheme
    if hour >= 7 && hour <= 10
        let coloration="morning"
    " in evenings, alwasy using the "evening" scheme
    elseif hour >= 18 && hour <= 23
        let coloration="evening"
    endif
 
endif


Just give it a try, you may be intrigued with use of it afterwards like me!

-----------------------------------
other interesting links
-------------------------------------

Full range of vim color scheme implemented in a Google code project
http://vimcolorschemetest.googlecode.com/svn/html/index-c.html

A find-tweaked color scheme for Mac:
http://blog.toddwerth.com/entries/show/8

Saturday, January 1, 2011

Install Nvidia Driver (non Gefore series) in Fedora 14

Intro: 

While here places a complete guide that is already great for novices in Fedora community at http://www.if-not-true-then-false.com/2010/fedora-14-nvidia-drivers-install-guide-disable-nouveau-driver/, following text will act as a complementary instruction for those who are using Nvidia Driver Card other than in the Geforce / Geforce FX series,  Quadro FX, for instance. (some parts actually are learned from the this page)

Steps: 

1. update to the latest kernel and restart the OS
by
yum update kernel*
reboot

2. make sure a correct xorg configuration, i.e. /etc/X11/xorg.conf, contains things about nvidia like the following
Section "Files"
    ModulePath   "/usr/lib64/xorg/modules/extensions/nvidia"
    ModulePath   "/usr/lib64/xorg/modules"
EndSection

(If for 32bit platform, use lib instead of lib64 in the paths above)
(If the xorg.conf file does not exist before, simply create it and add the stuff above)

3. Change Configuration of the Grub Bootloader by changing the current /boot/grub/grub.conf into text 
like the following 

default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz 
 
hiddenmenu 
title Fedora (2.6.35.10-74.fc14.x86_64)
 root (hd0,0)
 kernel /boot/vmlinuz-2.6.35.10-74.fc14.x86_64 ro root=UUID=e36dbe41-49ac-458f-8942-ba3fbdd22e32
 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 
KEYTABLE=us rhgb quiet rdblacklist=nouveau nouveau.modeset=0
 initrd /boot/initramfs-2.6.35.10-74.fc14.x86_64.img 
 
title Fedora Linux 14 (2.6.35.6-45.fc14.x86_64)
 root (hd0,0)
 kernel /boot/vmlinuz-2.6.35.6-45.fc14.x86_64 ro root=UUID=e36dbe41-49ac-458f-8942-ba3fbdd22e32 
rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16
 KEYTABLE=us rhgb quiet
 initrd /boot/initramfs-2.6.35.6-45.fc14.x86_64.img 
 
title windows 7
 rootnoverify (hd0,3)
 chainloader +1

the key is the blued text, which is added to disable the default display driver : nouveau. If this is 
missed, you will be told in the step 4 below that the installer can not proceed due to the nouveau is not
disabled.

4. download driver from Nvidia official site, for linux x86_64 we are using 
http://us.download.nvidia.com/XFree86/Linux-x86_64/260.19.29/NVIDIA-Linux-x86_64-260.19.29.run 
for now, wget it to a handy location, /root, say.

5. reboot,  then select the latest kernel item, and
 press "e" to edit it
 choose the "kernel /boot/vmlinuz-2.6.35.10-7...." line and press "e" to edit again
 append "single" to the line and press enter to get back to the previous interface
 press "b" to trigger the bootstrap
 
6. now that get in the Level 1 (single user mode), enter Level 3 (I did not check if this is necessary)
by "/sbin/init 3"
 
7. Run the installer
 sh /root/NVIDIA-Linux-x86_64-260.19.29.run -a
 
(if you are installing for the first time, you might already nvidia-installer on you machine,
then you don't need to download beforehand, instead a simpler way is :
 
nvidia-install -a --update  
 
you can by this get the latest driver and install it. but this will demand a network access
of course, see this page (http://surfingtroves.blogspot.com/2010/12/linux-access-network
-service-in-single.html ) for enabling network access in the single user mode, as is suitable
for being at Level 3. 
 
8. when finished, restart, and the installation should be well done.


Surfing Troves: Building installation of FreeWRL for Fedora 12/13/...

Surfing Troves: Building installation of FreeWRL for Fedora 12/13/...: "The official site of FreeWRL only provides installation guide for Ubuntu in the range of Linux series. While different OS has different too..."