Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, January 2, 2011

Installing Latex on Windows and Linux and Latex Document Compilation Instructions

In this article, I’ll present some tips and tricks on how to do certain things on latex such as adding sections, subsections, inserting images and writing equations etc. Then I’ll provide a sample tex file and instructions for compiling the file using latex along with installation instructions of latex software on various operating systems.

Adding sections and subsections in latex documents

To add a section, use section tag. Here’s an example,

\section{Overview}
If this section is in a chapter it is preceded by a numbering. For example, if it is chapter 1 numbering is 1.1, 1.2 etc.

If you want to add a subsection under a section use use subsection tag. Here's an example,


\subsection{Formulation}

It will have numbering like 1.1.1, 1.1.2 etc. If you need subsections under subsection, use subsubsection tag.

No more nesting (after 3 levels) is supported.


How to insert images on latex documents

The first thing you need to do is to convert your image (jpg, png, gif etc) to eps (a postscript format) which is easy to convert to pdf. To convert an image to eps format you need ImageMagick. In fedora installation command of ImageMagick is

# yum install ImageMagick

In Windows you can install ImageMagick after downloading from http://www.imagemagick.org/download/binaries/

Current latest release direct link for Windows:
http://www.imagemagick.org/download/binaries/ImageMagick-6.6.6-7-Q16-windows-dll.exe

Now use the convert command to convert the image.


$ convert filename.jpg filename.eps

In widows you have to put the installation path as well with the command. For example, if it installed in C:\Program Files\ImageMagick directory.

C:> “C:\Program Files\ImageMagick\convert.exe” filename.jpg filename.eps

To view eps files you need ghostscript. In Windows, you can install ghostscript from here:
http://ghostscript.com/releases/gs900w32.exe

In Fedora, you have to apply following command as root to install ghostscript,


# yum install ghostscipt

Now it’s time to include the eps file on tex. Use figure tag to make caption, includegraphics command to include the image. You need to specify the correct path of your image in \includegraphics command. Here’s an example,

 1 \begin{figure}[htbp]
 2   \centering
 3 \includegraphics{./Figures/SA_Spheric.eps}
 4   \caption{Latitude and Longitude \label{ Latitude and Longitude }}
 5 \end{figure}

Set the caption text and label text same. Label text is used on List of figures. In a template they are automatically numbered according to chapter. If you need to scale up image to half of its size use scalebox tag along with includegraphics.

\scalebox{0.5}{ \includegraphics{./Figures/SA_Spheric.eps}}


Writing scientific/math equations in latex

If your equations require numbering on right side use this tag,

\begin{equation}  Your math exp \end{equation}

For example,

\begin{equation}\int r = \sqrt[2]{x^2 + y^2 + z^2}\end{equation}

But if your equation doesn’t require numbering use tag like this,

\begin{math}  Your math exp \end{math}

For example,


Our equation is, \begin{math}\int r = \sqrt[2]{x^2 + y^2 + z^2}\end{math}. Proof ...

Integration symbol: \int

To show only root sign not n-th root use tag: \sqrt{x}, replace x with your expression or symbol

To show nth root use tag: \sqrt[n]{x}

To show fractions like ½ use \frac tag. Example,


thd = \frac{1}{n}

For summation sign use \sum tag,

\sum\limits_{i = 1}^n Abs (t_i - t_{i-1})\end{equation}

\limits is used to set limits on summation sign. Here, i=1 goes down and n goes up. You write texts preceding _ to put them down (subscript) and use ^ to superscript.

For using only one math symbol you can use \ensuremath{} tag. For example,


If angle in degree is \ensuremath{\theta} then the slope is ..

Here are latex tags for some of the math symbols:

\Phi
\lambda
\Pi
\epsilon

You can find a detailed list of latex symbols here:
http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html


Installation Instructions of Latex for Fedora Core

Apply following commands after opening a terminal and logging into root. Alternatively you can apply su command and provide root password for instant switching.

$ su
Password:
# yum install tetex-latex evince-dvi xdvik


Installation Instructions of Latex for Ubuntu

Apply following commands if you are using Ubuntu

# sudo apt-get install tetex-base tetex-bin


Installation Instructions for Windows (XP, Vista, Seven)

Download basic-miktex from here: http://miktex.org/2.9/setup and run the installer.


Compiling Tex Documents

Now let’s learn how to compile latex document file. Here’s a sample tex file,

\documentclass[12pt]{article}
\usepackage{amsmath}
\title{\LaTeX}
\date{}
\begin{document}
  \maketitle 
  \LaTeX{} is a document preparation system for the \TeX{} 
  typesetting program. It offers programmable desktop publishing 
  features and extensive facilities for automating most aspects of 
  typesetting and desktop publishing, including numbering and 
  cross-referencing, tables and figures, page layout, bibliographies, 
  and much more. \LaTeX{} was originally written in 1984 by Leslie 
  Lamport and has become the dominant method for using \TeX; few 
  people write in plain \TeX{} anymore. The current version is 
  \LaTeXe.
 
  % This is a comment; it is not shown in the final output.
  % The following shows a little of the typesetting power of LaTeX:
  \begin{align}
    E &= mc^2                              \\
    m &= \frac{m_0}{\sqrt{1-\frac{v^2}{c^2}}}
  \end{align}
\end{document}

Open a text editor. Create a new file and paste the code given above. Save the file with name test.tex.

Now let’s compile the tex file. In Linux, apply following commands on terminal


$ latex test.tex
$ dvipdf test.dvi

A pdf file will be generated with same filename. In Linux if you need to view dvi files you can use either evince or xdvi

$ evince test.dvi &
$ xdvi test.dvi &

In Windows, you might skip generating dvi files. You can use pdflatex.

To compile tex files in Windows you need to apply following command,


D:> "C:\Program Files\TeX\miktex\bin\pdflatex.exe" test.tex

assuming "C:\Program Files\TeX” is your installation directory for basic-miktex.

If there is no error on the tex file it will generate a pdf document which you can open using a pdf reader like Adobe pdf reader or Foxit Reader.


More tips and tricks

Here’s an example of using bullets for following texts:
  • Dining and canteen system
  • Library, reading room system
  • Debate,language club system
  • Games and sports system
  • Washing and cleaning system and Utensil management

\begin{itemize}
    \item {Dining and canteen system}
    \item {Library, reading room system}
    \item {Debate,language club system}
    \item {Games and sports system  }
    \item {Washing and cleaning system and Utensil management }
\end{itemize}


Using tables
Follow this link: http://en.wikibooks.org/wiki/LaTeX/Tables It explains tables well.

Adding newlines: use \\ to add a newline

Using Bold styles: Use \textbf{text here} tag to bold your text.

Italicizing texts: You can use \emph tag or \textit tag to italicize your text. Example,


\emph{set your text here}
\textit{set your text here }

Subscripting: Write texts preceding _ to make them subscripted. To write xi type x_i

Superscript: use ^ to superscript. To write x^2 use x^2 exactly.


Troubleshooting

If you get errors like this frequently,

! Missing $ inserted.

                $
l.128 ...Distance (C_{i}, C_j)\end{math}, where K_
                                                  i, K_j is Cluster.
?

Latex expects including math tag during usage of math notations like superscript, subscript and symbols. Here’s an example,

\begin{math} Your expression for example C_i end{math}

When this syntax is ensured latex will not display those error messages anymore.

Wednesday, December 22, 2010

How to Update Fedora Core 13 to Fedora Core 14

The process is simple. We have to apply some commands on terminal mode. After that update will be done using internet.

It means we need internet on terminal. But when GUI closes; internet that is configured with NetworkManager is lost. Hence we have to try other way out.

First, install system-config-network and then stop Network Manager Daemon


# yum install system-config-network
# service NetworkManager stop
Now open system-config-network using system-config-network command on the terminal or run. Enter root password if it asks for.

Untick the option "Controlled by Network Manager". Click apply. Now switch to terminal mode by pressing Alt + Ctrl + F2. Log in as root.


# init 3

Doing the update
After it is done press enter and enter following commands.

# rpm --import https://fedoraproject.org/static/97A1071F.txt
# yum update yum
# yum --releasever=14 distro-sync --skip-broken

Accelerate Linux with the ISP ISPROS and other ISPs which support GNU Mirror
After update reboot your system using reboot command. After restart select Fedora 14 from Boot Menu. Once System is booted into Fedora 14 update the system using yum.

If your ISP has its own GNU Linux Mirror then update will be very fast. With around 300 KBPS it will take around half an with an decent configuration PC.

Bangladeshi Linux users can have this benefit with ISPROS isp. They have ubuntu mirror, fedora mirror, cent-os mirror and gnu mirror and some other useful mirrors(apache, php etc).

One thing more if your Fedora yum does not choose ISPROS as mirror you can force it by changing fedora.repo Set your mirror list to this url: http://mirrors.ispros.com.bd/fedora/releases/$releasever/Everything/$basearch/os/ by editing the file /etc/yum.repos.d/fedora.repo.

Enjoy Linux with ISPROS.

Wednesday, December 1, 2010

How to Change MAC Address on Linux using NetworkManager

In previous post I showed how to change MAC address on Linux using ifconfig command and system-config-network tool. Today I will show you how to change MAC address using Network Manager. The method is comparatively easier.

  • Follow the steps given below to change MAC address.

  • Right click on the Network Manager applet and click "Edit Connections"

  • Select eth0 and click edit button
  • On Cloned MAC Address type the MAC address that you want to change to as shown in image below:


[Click Image to Enlarge]

  • Click apply.

You are done. It was damn easy. Right!? ping to check back your internet connection.

$ $ ping www.google.com
PING www.l.google.com (74.125.43.105) 56(84) bytes of data.
64 bytes from bw-in-f105.1e100.net (74.125.43.105): icmp_seq=1 ttl=53 time=220 ms
64 bytes from bw-in-f105.1e100.net (74.125.43.105): icmp_seq=2 ttl=53 time=220 ms
64 bytes from bw-in-f105.1e100.net (74.125.43.105): icmp_seq=3 ttl=53 time=219 ms
64 bytes from bw-in-f105.1e100.net (74.125.43.105): icmp_seq=4 ttl=53 time=220 ms
64 bytes from bw-in-f105.1e100.net (74.125.43.105): icmp_seq=5 ttl=53 time=220 ms
^C
--- www.l.google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4298ms
rtt min/avg/max/mdev = 219.408/220.194/220.799/0.709 ms
$

If you don't find "Cloned MAC address" in Network Manager update your Network Manager and then try again.
$ $ yum update NetworkManager

Wednesday, August 18, 2010

Blog is migrating

Cannot boot Ubuntu 10.04 after installation of Ubuntu or after installation of Windows Seven


You have just installed Ubuntu 10.04 but you cannot boot to it. System boot straights to Windows Seven and you are feeling deceived. I also faced this issue.

May be there’s a problem with Ubuntu 10.04 distro that’s happening with some PCs having Windows Seven. Well here’s a fix. Follow the steps.


Ø Boot the system using Live CD.

Ø Press Alt+F2 and enter gnome-terminal command. And continue by entering:

$ sudo fdisk -l


It shows partition table. Here’s mine.

/dev/sda1 29 8369 66999082+ 83 Linux
/dev/sda2 * 8370 13995 45190845 7 HPFS/NTFS
/dev/sda3 13996 14593 4803435 5 Extended
/dev/sda5 13996 14593 4803403+ 82 Linux swap / Solaris

Now mount Linux boot partition. As you can see from the output of previous command it was sda1 for my system.

$ sudo mount /dev/sda1 /mnt
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /proc /mnt/proc

Now chroot into the enviroment:

$ sudo chroot /mnt


After chrooting, we need not add sudo before commands.
You may want to edit /etc/default/grub file to fit your system (timeout options etc)

# vi /etc/default/grub

After edition press ESC & then :wq to store and exit. Now install/recover Grub2 via command:

# grub-install --recheck /dev/sda

Now you can exit the chroot, umount the system and reboot your system:

# exit
$ sudo umount /mnt/dev
$ sudo umount /mnt/proc
$ sudo umount /mnt
$ sudo reboot

Monday, January 18, 2010

Learning some commands makes Linux life easier

Redirecting inputs and outputs
It's about these two operator '<' and '>'. For example,

$ ls -l > fileList.txt

The output of this command is not printed on the screen, it is written to a file named fileList.txt.

cat command

Purpose of this command is equivalent to "type" command. You can view contents of a text file using cat command. Example given below,

$ cat fileList.txt 
total 36 
drwxrwxrwx   4 ar       root         512 Dec  1 16:45 HarvardPackages 
-rwxrwxrwx   1 ar       root        1098 Dec  1 16:49 IS_OS161_v1.3.1.sh~ 
-rwxrwxrwx   1 ar       root        1140 Dec  1 16:49 IS_OS161_v1.3.2.sh 
drwxrwxrwx   2 ar       root         512 Dec  1 16:44 Package 1.4 
-rwxrwxrwx   1 ar       root         244 Dec  1 16:49 Scripting.txt 
-rwxrwxrwx   1 ar       root         189 Dec  1 16:49 Scripting.txt~ 
drwxrwxrwx  12 ar       root         512 Dec  1 16:47 cs161-binutils-1.4 
drwxrwxrwx   6 ar       root         512 Dec  1 16:48 cs161-gcc-1.4-2 
drwxrwxrwx  14 ar       root         512 Dec  1 16:44 cs161-gdb-1.4-2 
-rw-r--r--   1 ar       other          0 Dec 26 20:03 fileList.txt 
-rwxrwxrwx   1 ar       root         148 Dec  1 16:44 input.sh 
-rwxrwxrwx   1 ar       root         294 Dec  1 16:49 install.sh~ 
-rwxrwxrwx   1 ar       root         695 Dec  1 16:49 install_os161.sh 
-rwxrwxrwx   1 ar       root         668 Dec  1 16:49 install_os161.sh~ 
drwxrwxrwx  10 ar       root         512 Dec  1 16:49 os161-1.11 
drwxrwxrwx  16 ar       root        1024 Dec  1 16:49 sys161-1.12-2 
-rwxrwxrwx   1 ar       root          24 Dec  1 16:49 test2.txt~ 

grep
Very useful command. It is used to filter the outputs (pipes supported). If you don't understand the purpose in theory don't worry you will be able to understand from examples. If you give the command ls -a it will show like this,

$ ls -a 
total 44 
drwxrwxrwx   9 ar       root         512 Dec 26 20:03 . 
drwxrwxrwx   6 ar       root         512 Dec  1 16:43 .. 
drwxrwxrwx   4 ar       root         512 Dec  1 16:45 HarvardPackages 
-rwxrwxrwx   1 ar       root        1098 Dec  1 16:49 IS_OS161_v1.3.1.sh~ 
-rwxrwxrwx   1 ar       root        1140 Dec  1 16:49 IS_OS161_v1.3.2.sh 
drwxrwxrwx   2 ar       root         512 Dec  1 16:44 Package 1.4 
-rwxrwxrwx   1 ar       root         244 Dec  1 16:49 Scripting.txt 
...........................................................................
...........................................................................
drwxrwxrwx  10 ar       root         512 Dec  1 16:49 os161-1.11 
drwxrwxrwx  16 ar       root        1024 Dec  1 16:49 sys161-1.12-2 
-rwxrwxrwx   1 ar       root          24 Dec  1 16:49 test2.txt~

If the output was huge and wanted details about only the file whose name
contains Package. Then give the command like this:


$ ls -l | grep Package 
drwxrwxrwx   4 ar       root         512 Dec  1 16:45 HarvardPackages 
drwxrwxrwx   2 ar       root         512 Dec  1 16:44 Package 1.4

'|' This sign is called pipe which linked the output of first command to the second as input. You can search for files containing certain text string.

$ grep -r "textString" /path

Use -H switch to show line numbers. grep has many useful options learn them from manual ("$ man grep")

find

In case you know the name of a file but you don't know where it is then to find it's location use this command,

find /directoryname -name file.ext

which
If you apply a command but don't know from where it'll be executed or where the executable file resides? To view that location use this syntax,

which commandName
Example,

$ which gcc 
/usr/sfw/bin/gcc

It is the output for Solaris 10. Hence, your output can be different.

tar

An archive is a file containing compressed files and directories.
  • creating an archive using tar command

    $ tar -cvf test.tar local.login local.profile .bashrc 
    a local.login 1K 
    a local.profile 1K 
    a .bashrc 1K

    Why did we use v switch? Let's see the difference.

    $ tar -cf test.tar local.login local.profile .bashrc

    It means if v is included then tar displays information on every file it adds.

    To add a file in an existing archive use -r option(-f means next argument is
    the archive file name).

    $ tar -rf test.tar local.cshrc

  • Extracting archive,
    If file extension contains tar.gz then syntax is,
         tar xzvf fileName.tar.gz

    If extension is tar.bz2
         tar xjvf fileName.tar.bz2

    if extension is only .tar then
         tar xvf fileName.tar.bz2

echo
This is the easiest command. You know about this. An example is,

$ echo "This line will be printed." 
This line will be printed.

zip and unzip
You can create zip files using zip command. Use following syntax.

$ zip ArchiveFileName.zip /path/dir_OR_file

To unzip a zip file (extract an zip archive) use following syntax

$ unzip ArchiveFileName.zip

To work with rar archives follow this post.

Saturday, January 16, 2010

Installing and Configuring Apache, PHP, MySQL on Fedora Core

  • Install Apache (httpd), PHP, MySQL (server and client)

    # yum -y install httpd php mysql mysql-server php-mysql 

  • Configure the new services to start automatically

    # /sbin/chkconfig httpd on 
    # /sbin/chkconfig --add mysqld
    [not required with FC4 and above] 
    # /sbin/chkconfig mysqld on 
    # /sbin/service httpd start 
    # /sbin/service mysqld start

    If everything went okay attempting to open this url:
         http://localhost
    or http://127.0.0.1 will forward to a page like one displayed in image below. Otherwise it will give an error.


    Click image to enlarge

  • By default the document directory is /var/www/html. You can change it modifying /etc/httpd/conf/httpd.conf Modify the lines and set like this:

    DocumentRoot "/home/AR/web"

    And another line

    <Directory "/home/AR/web">


    Changing directory like this may not allow apache to read files or execute scripts. Hence this error message "Forbidded, you don't have permission to access / on this server" can be produced. To get rid of this change the directory attributes to executable.


    # chmod a+x /home 
    # chmod a+x /home/AR 
    # chmod a+x /home/AR/web

    which means that you are giving permission of execution to apache for the entire directory chain. This actually solves the problem. If still the problem persists then apply this command too.

    # chown -R apache:apache /home/AR/web

    Change "/home/AR/web" with your www directory.

  • Add mysqld as startup service

    # /sbin/chkconfig mysqld on 
    # /sbin/service mysqld start

  • Change the mysqladmin password for security reason.

    # mysqladmin -u root password new-password

Notice # means root user prevelige.

How to Install Kaspersky Antivirus/ Internet Security on Linux

Fedora Core Instructions

Command "yum install kaspersky" won't work.

First you have to download your required product/software from
        kes10linux

After that you have to install the downloaded package (rpm for Fedora Core/RHEL/CentOS etc and .deb for debian systems like Ubuntu)

For rpm packages try this command to install Kaspersky Software

# rpm -Uvh packagename.rpm

Also you can try this command

# yum localinstall packagename.rpm

For debian packages try this command to install Kaspersky Software.


$ sudo dpkg -i package.deb

You can choose to install the network agent version if you want to enable installation from Network.

Refreences

https://usa.kaspersky.com/small-to-medium-business-security/endpoint-linux
Kaspersky Endpoint Security 10 for Linux - Administrator's Guide - Application version 10


$ sudo dpkg -i package.deb

Sunday, January 10, 2010

How to Create Makefile from Imakefile

Here we'll describe how to create Makefile using Imakefile.

Create the Imakefile for example with following contents
TARGET = program.out
OBJS = main.o
SRCS = main.cpp

CC = g++
CCOPTIONS = -g

MESAINCDIR = /usr/include
MESALIBDIR = /usr/lib

GLLIB = -L$(MESALIBDIR) -lglut -lGLU -lGL
XLIB = -L/usr/lib -lXmu -lXi -lXext -lX11 -lm -lpthread
INCLUDES = -I$(MESAINCDIR)

LOCAL_LIBRARIES = $(GLLIB) $(XLIB)

ComplexProgramTarget($(TARGET))

Use xmkmf command to create makefile from Imakefile.
$ xmkmf

xmkmf script actually uses imake command to create Imakefile. Hence following command would also work.

$ imake -DUseInstalled -I/usr/share/X11/config

xmkmf command does not necessarily require a parameter. It looks for a file named Imakefile inside current dirctory to create makefile.

If imake package is not installed bash will tell you that Command not found. For Fedora Core Systems login as root and type the following command.

# yum -y install imake

For Ubuntu the command will be something like this.

$ sudo apt-get install imake

Now imake or xmkmf command will work.

Now let's test it compiling and running a program. Create your source file main.cpp for example with following contents.

/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* File for "Basic Shapes" lesson of the OpenGL tutorial on
 * www.videotutorialsrock.com
 */



#include <iostream>
#include <stdlib.h> //Needed for "exit" function

//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
     int x, int y) {    //The current mouse coordinates
 switch (key) {
  case 27: //Escape key
   exit(0); //Exit the program
 }
}

//Initializes 3D rendering
void initRendering() {
 //Makes 3D drawing work when something is in front of something else
 glEnable(GL_DEPTH_TEST);
}

//Called when the window is resized
void handleResize(int w, int h) {
 //Tell OpenGL how to convert from coordinates to pixel values
 glViewport(0, 0, w, h);
 
 glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
 
 //Set the camera perspective
 glLoadIdentity(); //Reset the camera
 gluPerspective(45.0,                  //The camera angle
       (double)w / (double)h, //The width-to-height ratio
       1.0,                   //The near z clipping coordinate
       200.0);                //The far z clipping coordinate
}

//Draws the 3D scene
void drawScene() {
 //Clear information from last draw
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
 glLoadIdentity(); //Reset the drawing perspective
 
 glBegin(GL_QUADS); //Begin quadrilateral coordinates
 
 //Trapezoid
 glVertex3f(-0.7f, -1.5f, -5.0f);
 glVertex3f(0.7f, -1.5f, -5.0f);
 glVertex3f(0.4f, -0.5f, -5.0f);
 glVertex3f(-0.4f, -0.5f, -5.0f);
 
 glEnd(); //End quadrilateral coordinates
 
 glBegin(GL_TRIANGLES); //Begin triangle coordinates
 
 //Pentagon
 glVertex3f(0.5f, 0.5f, -5.0f);
 glVertex3f(1.5f, 0.5f, -5.0f);
 glVertex3f(0.5f, 1.0f, -5.0f);
 
 glVertex3f(0.5f, 1.0f, -5.0f);
 glVertex3f(1.5f, 0.5f, -5.0f);
 glVertex3f(1.5f, 1.0f, -5.0f);
 
 glVertex3f(0.5f, 1.0f, -5.0f);
 glVertex3f(1.5f, 1.0f, -5.0f);
 glVertex3f(1.0f, 1.5f, -5.0f);
 
 //Triangle
 glVertex3f(-0.5f, 0.5f, -5.0f);
 glVertex3f(-1.0f, 1.5f, -5.0f);
 glVertex3f(-1.5f, 0.5f, -5.0f);
 
 glEnd(); //End triangle coordinates
 
 glutSwapBuffers(); //Send the 3D scene to the screen
}

int main(int argc, char** argv) {
 //Initialize GLUT
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
 glutInitWindowSize(400, 400); //Set the window size
 
 //Create the window
 glutCreateWindow("Basic Shapes - videotutorialsrock.com");
 initRendering(); //Initialize rendering
 
 //Set handler functions for drawing, keypresses, and window resizes
 glutDisplayFunc(drawScene);
 glutKeyboardFunc(handleKeypress);
 glutReshapeFunc(handleResize);
 
 glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
 return 0; //This line is never reached
}

Now apply make command to compile and build the program. And then as in our Imakefile output file name was program.out type ./program.out to display output.

$ make
c++ -m32 -O2 -fno-strength-reduce -fno-strict-aliasing   -I/usr/include \
-I/usr/include -Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE\ 
-D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_LARGEFILE_SOURCE \
-D_FILE_OFFSET_BITS=64 -c -o main.o main.cpp
rm -f program.out
g++ -o program.out -O2 -fno-strength-reduce -fno-strict-aliasing -g -L/usr/lib\ 
main.o -L/usr/lib -lglut -lGLU -lGL -L/usr/lib -lXmu -lXi -lXext -lX11 -lm -lpthread
make: *** No rule to make target `program.out.man', needed by `program.out._man'.
Stop.

It is not a must that you have to use an Imakefile to compile sources. You can use simple makefiles.

For example a file named makefile with following contents will serve the same purpose.

CC = g++
CFLAGS = -Wall
PROG = basicshapes

SRCS = main.cpp

ifeq ($(shell uname),Darwin)
 LIBS = -framework OpenGL -framework GLUT
else
 LIBS = -lGL -lGLU -lglut
endif

all: $(PROG)

$(PROG): $(SRCS)
 $(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)

clean:
 rm -f $(PROG)

An easy tutorial on makefile here.
       http://mrbook.org/tutorials/make

How to Load All New Yahoo Mail on Google Chrome Linux

Users of All New Yahoo Mail may be redirected to the following page when using Google Chrome on Linux.

[Click image to zoom]

The page says "Sorry, the all-new Yahoo! Mail does not support your browser.
You can either download a compatible browser or proceed to Yahoo! Mail Classic."

And there are two options; one to download browsers other to "To proceed to Yahoo! Mail Classic"

How weird is that!! This is happening with Google Chrome 4.0.249.43 which is a very much capable browser for the technologies that New Yahoo Mail uses!

So what's the workaround? As Yahoo Mail is dumb we have to bypass their browser and platform check!

Enter the following URL on address bar and enter
       http://us.mg2.mail.yahoo.com/dc/launch?sysreq=ignore

Asians, use this url. It will help faster loading.
       http://aa.mg2.mail.yahoo.com/dc/launch?sysreq=ignore

Sunday, January 3, 2010

How to hide drive icons on gnome desktop Linux

First we need to install gconf-editor. You can check if it exists in your system (Applications Menu->System Tools->Configuration Editor).

On Fedore Core login as root and apply commands

# su
Password: # yum -y install gconf-editor


On Ubuntu

# sudo aptitude install -P gconf-editor

Now using start menu go to Applications->System Tools->Configuration Editor or simply type 'gconf-editor' on terminal.

Go to apps -> nautilus -> desktop


[Click image to enlarge]

Untick the check box besides "volumes_visible" Immediately the change will take effect and you will see the mounted partitions gone from desktop.



[Click image to enlarge]

How to Install Adobe Flash Player on Google Chrome Linux [Deprecated]

This post is for older version of google chrome. Nowadays google chrome is bundled with flash player. So flash player is no more required to be installed separately. For older versions of chrome which doesn't have flash pleas follow instructions below. First determine if flash player is already installed. Apply following command.

# sudo locate libflashplayer.so
/usr/lib/flash-plugin/libflashplayer.so
/usr/lib/mozilla/plugins/libflashplayer.so
If there is no output it means flash player is not installed. In that case you have to install it.

To install flash player, open a terminal. Press Alt + F2. Type gnome-terminal. Hit Enter.

Command for Ubuntu

# sudo aptitude install flashplugin-installer

For Fedora core, login as root. For example, type su and provide root password and apply following commands.

# rpm -Uvh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.\
noarch.rpm
warning: adobe-release-i386-1.0-1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID
f6777c67
Preparing...                ########################################### [100%]
   1:adobe-release-i386     ########################################### [100%]

# yum install flash-plugin
Loaded plugins: presto, refresh-packagekit
adobe-linux-i386                                         |  951 B     00:00     
adobe-linux-i386/primary                                 |  12 kB     00:00     
adobe-linux-i386                                                          17/17
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package flash-plugin.i386 0:10.0.42.34-release set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch     Version                   Repository            Size
================================================================================
Installing:
 flash-plugin     i386     10.0.42.34-release        adobe-linux-i386     3.9 M

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 3.9 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 3.9 M
flash-plugin-10.0.42.34-release.i386.rpm                 | 3.9 MB     03:05     
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID f6777c67
adobe-linux-i386/gpgkey                                  | 3.4 kB     00:00 ... 
Importing GPG key 0xF6777C67 "Adobe Systems Incorporated (Linux RPM Signing Key)
<secure@adobe.com>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB has been altered since the last yum transaction.
  Installing     : flash-plugin-10.0.42.34-release.i386                     1/1 

Installed:
  flash-plugin.i386 0:10.0.42.34-release                                        

Complete!

Press y if asked for confirmation.

Restart your browser. Whether it is Google Chrome or Mozilla Firefox no manual configuration is required. Tested on Google Chrome 4.0.249.43 beta.

[Click image to enlarge]

If you still get trouble with Google Chrome make symbolic link after creating plugins directory.

# sudo mkdir /opt/google/chrome/plugins
# sudo ln -s /usr/lib/flashplugin-installer/libflashplayer.so \
/opt/google/chrome/plugins/libflashplayer.so

How to Setup OpenGL (installing glut) on Linux and Compile Programs


Fedora Core Instructions

I am assuming that you have the primary idea about what OpenGL is and what it does. Hence, without wasting any more time let's see how to set it up or install on Linux Operating System.

First check for files gl.h and glut.h

# cd /usr/include/GL
# ls
glext.h      glu.h         glx.h         glxmd.h      internal
gl.h         glu_mangle.h  glxint.h      glxproto.h
gl_mangle.h  glxext.h      glx_mangle.h  glxtokens.h

We have gl.h but no glut.h Hence we have to install development packages. If you don't have gl.h then you have to install mesa graphics libraries or nvidia libraries if you are using nvidia graphics card.

As freeglut devel package provides glut.h we are going to install it.

# yum -y install freeglut-devel
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package freeglut-devel.i686 0:2.6.0-1.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch         Version              Repository       Size
================================================================================
Installing:
 freeglut-devel         i686         2.6.0-1.fc12         updates         112 k

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 112 k
Downloading Packages:
Setting up and reading Presto delta metadata
updates/prestodelta                                      | 322 kB     00:30     
Processing delta metadata
Package(s) data still to download: 112 k
freeglut-devel-2.6.0-1.fc12.i686.rpm                     | 112 kB     00:11     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : freeglut-devel-2.6.0-1.fc12.i686                         1/1 

Installed:
  freeglut-devel.i686 0:2.6.0-1.fc12                                            

Complete!
# ls
freeglut_ext.h  glext.h      glu.h         glxext.h  glx_mangle.h  glxtokens.h
freeglut.h      gl.h         glu_mangle.h  glx.h     glxmd.h       internal
freeglut_std.h  gl_mangle.h  glut.h        glxint.h  glxproto.h

Installation of OpenGL in a Machine without Internet Connection

Download freeglut-devel according to your distribution using a PC that has internet connection.
      freeglut-devel for Fedora Core 8
      freeglut-devel for Fedora Core 9
      freeglut-devel for Fedora Core 10
      freeglut-devel for Fedora Core 11
      freeglut-devel for Fedora Core 12

You can take the file to your PC using a memory device like USB Stick (pen drive)etc. Copy the file in the machine in which you want to install. Login as root(you can type su and provide root password after hitting enter). cd to the directory where you copied the file. Use this syntax to install them (rpm).

# rpm -Uvh filename.rpm

For Fedora Core 12 it will be like this

# rpm -Uvh freeglut-devel-2.6.0-1.fc12.i686.rpm

Now you'll find glut.h inside /usr/include/GL and that's all about installation.

# cd /usr/include/GL
# ls
glext.h      glu.h         glx.h         glxmd.h      internal
gl.h         glu_mangle.h  glxint.h      glxproto.h
gl_mangle.h  glxext.h      glx_mangle.h  glxtokens.h

Now we have glut.h along with other files. If everything is okay and hardware acceleration is enabled then glxinfo command will show "direct rendering: Yes"

# glxinfo
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
  GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,
......................................................................

Ubuntu Instructions
For ubuntu I would recommend you to follow this Video tutorial. This is a good one.
       http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/video.php

Writing Opengl Programs and Compiling on Linux

Create a new directory.

$ mkdir og

Change directory.

$ cd og
Use a text-editor to create a make file inside the directory with following contents. For example, you can use command like this, (Or you can download files from the bottom of the post)

$ gedit Makefile&

Contents

CC = g++
CFLAGS = -Wall
PROG = basicshapes

SRCS = main.cpp

ifeq ($(shell uname),Darwin)
 LIBS = -framework OpenGL -framework GLUT
else
 LIBS = -lGL -lGLU -lglut
endif

all: $(PROG)

$(PROG): $(SRCS)
 $(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)

clean:
 rm -f $(PROG)

In the same way create a file named "main.cpp" with following contents

/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* File for "Basic Shapes" lesson of the OpenGL tutorial on
 * www.videotutorialsrock.com
 */

#include <iostream>
#include <stdlib.h> //Needed for "exit" function

//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <glut/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
                              int x, int y) {    //The current mouse coordinates
      switch (key) {
            case 27: //Escape key
            exit(0); //Exit the program
      }
}

//Initializes 3D rendering
void initRendering() {
      //Makes 3D drawing work when something is in front of something else
      glEnable(GL_DEPTH_TEST);
}

//Called when the window is resized
void handleResize(int w, int h) {
      //Tell OpenGL how to convert from coordinates to pixel values
      glViewport(0, 0, w, h);
     
      glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
     
      //Set the camera perspective
      glLoadIdentity();      //Reset the camera
      gluPerspective(45.0,                  //The camera angle
                  (double)w / (double)h, //The width-to-height ratio
                  1.0,             //The near z clipping coordinate
                  200.0);          //The far z clipping coordinate
}

//Draws the 3D scene
void drawScene() {
      //Clear information from last draw
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
      glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
      glLoadIdentity(); //Reset the drawing perspective
     
      glBegin(GL_QUADS); //Begin quadrilateral coordinates
     
      //Trapezoid
      glVertex3f(-0.7f, -1.5f, -5.0f);
      glVertex3f(0.7f, -1.5f, -5.0f);
      glVertex3f(0.4f, -0.5f, -5.0f);
      glVertex3f(-0.4f, -0.5f, -5.0f);

      
      glEnd(); //End quadrilateral coordinates
     
      glBegin(GL_TRIANGLES); //Begin triangle coordinates
     
      //Pentagon
      glVertex3f(0.5f, 0.5f, -5.0f);
      glVertex3f(1.5f, 0.5f, -5.0f);
      glVertex3f(0.5f, 1.0f, -5.0f);
     
      glVertex3f(0.5f, 1.0f, -5.0f);
      glVertex3f(1.5f, 0.5f, -5.0f);
      glVertex3f(1.5f, 1.0f, -5.0f);
     
      glVertex3f(0.5f, 1.0f, -5.0f);
      glVertex3f(1.5f, 1.0f, -5.0f);
      glVertex3f(1.0f, 1.5f, -5.0f);
     
      //Triangle
      glVertex3f(-0.5f, 0.5f, -5.0f);
      glVertex3f(-1.0f, 1.5f, -5.0f);
      glVertex3f(-1.5f, 0.5f, -5.0f);
     
      glEnd(); //End triangle coordinates
     
      glutSwapBuffers(); //Send the 3D scene to the screen
}

int main(int argc, char** argv) {
      //Initialize GLUT
      glutInit(&argc, argv);
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowSize(400, 400); //Set the window size
     
      //Create the window
      glutCreateWindow("Basic Shapes - videotutorialsrock.com");
      initRendering(); //Initialize rendering
     
      //Set handler functions for drawing, keypresses, and window resizes
      glutDisplayFunc(drawScene);
      glutKeyboardFunc(handleKeypress);
      glutReshapeFunc(handleResize);
     
      glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
      return 0; //This line is never reached
}


Now compile (simple make command will do this) and run the program

# make
g++ -Wall -o basicshapes main.cpp -lGL -lGLU -lglut
$ ls
basicshapes  main.cpp  Makefile
$ ./basicshapes &

A new window will appear like this one


[Click to enlarge image]


Write in comments if you face any exception.

Download attached files.
          BasicShape.zip