Friday, November 15, 2013

Complete Minimal SDL2 OpenGL Animation Program with no memory leaks


#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <iostream>
using std::cout;

int main()
{
  int width = 640, height = 480;
  SDL_Init(SDL_INIT_VIDEO);
  SDL_Window *window = SDL_CreateWindow( "Grapics Application", 0, 0, width, height, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
  SDL_GLContext glcontext = SDL_GL_CreateContext(window);
  cout << "OpenGL Version " << glGetString(GL_VERSION) << "\n";
  glClearColor(0,0,0,1);
  glViewport( 0, 0, width, height );
  glFrustum( -1, 1, -(float)height/width, (float)height/width, 1, 500 );
  SDL_Event event;
  while( 1 )
  {
    while( SDL_PollEvent( &event ) )
    {
      switch( event.type )
      {
        case SDL_WINDOWEVENT:
          if( event.window.event == SDL_WINDOWEVENT_RESIZED )
          {
            glViewport( 0, 0, event.window.data1, event.window.data2 );
            glLoadIdentity();
            glFrustum( -1, 1, -(float)event.window.data2/event.window.data1, (float)event.window.data2/event.window.data1, 1, 500 );
          }
          break;
        case SDL_QUIT: SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(window);SDL_Quit(); return 0;
      }
    }
  static float delta = 0;
  delta += 0.002;
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_TRIANGLES);
  glVertex3f( delta, 0, -5 );
  glVertex3f( 1+delta, 0, -5 );
  glVertex3f( delta, 1, -5 );
  glEnd();
  SDL_GL_SwapWindow(window);
  SDL_Delay(20);
  }
}

Tuesday, October 22, 2013

Changing the world: Python and XML

Although I have occasionally used Python and I program in C++ 100% of time, if I were to rule the world I would issue an ultimatum to all programming languages to conform to Python syntax within 5 years after which all backward compatibility will be dropped! Python offers a terse human readable syntax.

Now for a verbose machine readable syntax which is still very human friendly, I would choose XML. So again, Latex gets five years to confom to Python (terse) or XML (verbose) or both flavors.

The idea is that we can keep on complicating things in the pretext of simplifying them.

For example, for all publishing needs we can rely on Python and XML syntax, syntax highlighting text editors (Vim for shell and Geany for GUI), PNG format for images and bzip2 to package all the stuff in a single file ready to be dispatched to a printer or a projector via a rendering application. This can unify and simplify hardware, software and application design.

Thursday, September 19, 2013

Show only "Free" software in Ubuntu Software Center

In other words, "How to prevent paid software from being listed in Ubuntu Software Center"


Follow three simple steps as root:

1. In the file
/usr/share/software-center/softwarecenter/db/update.py
 
somewhere near line 480 find the following lines and add the highlighted line:
 
        doc = self.make_doc(cache)
        if not doc:
            LOG.debug("%r.index_app_info: returned invalid doc %r, ignoring.",
                      self.__class__.__name__, doc)
            return
        name = doc.get_data()

        if doc.get_value(XapianValues.PRICE) not in (""): return
        if name in seen:
            LOG.debug("%r.index_app_info: duplicated name %r (%r)",
                      self.__class__.__name__, name, self.desktopf)
        LOG.debug("%r.index_app_info: indexing %r",
                  self.__class__.__name__, name)
        seen.add(name)
  
2. In the file 
/usr/share/software-center/softwarecenter/backend/channel_impl/aptchannels.py
 
find the following lines and commentize the highlighted lines:

        if partner_channel is not None:
            channels.append(partner_channel)
        #if get_distro().PURCHASE_APP_URL:
        #    channels.append(for_purchase_channel)
        if new_apps_channel is not None:
            channels.append(new_apps_channel) 
3. Issue the command:
# update-software-center
 
4. Also disable "multiverse" from "Software and Updates" settings panel.

Friday, August 30, 2013

Some essential remapping of shortcut keys on Ubuntu

Since Ctrl-W is most widely used shortcut to close tabs I find it was a very short sighted decision  to map Super-W to launch window picker in Ubuntu.

Hence I have mapped window picker to Alt-E key combination as follows:

1. Install Compiz Config Settings Manager:

# apt-get install compizconfig-settings-manager

2. Launch compiz config settings manager as "normal" user:

$ ccsm

In the panel that pops up, follow

Advanced Search >>  Scale >> Binding >> Initiate Window Picker

Remap the key binding to Alt-E


Using Super-Q to close a window rather than Alt-F4

Execute following command (Ubuntu 13.04 or Fedora 19)

gsettings set org.gnome.desktop.wm.keybindings close "['<Super>Q']"

Installing Ubuntu on a fresh system

Ubuntu 13.04

1. Download the iso file and create a live bootable USB stick (http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows).

2. Boot the system using the USB stick and install Ubuntu in a 50 GB or 15% of total capacity of your hard disk, whatever is greater. Create a swap equal to installed memory but do not create any partitions at present. Leave rest of the disk free.

3. Log on to new user and create two (or more) encrypted partitions.

4.  Open software center and uninstall useless software.

5. I also remove unity lenses by executing following commands as root:

apt-get autoremove unity-lens-shopping 
apt-get autoremove unity-lens-music 
apt-get autoremove unity-lens-photos 
apt-get autoremove unity-lens-video

6. Execute following command as root:

apt-get update && apt-get upgrade

7. Install essential software:
apt-get install geany g++ vlc gimp ghex 

8. Now open "Disks" utility and create two (or more) encrypted partitions.

Saturday, August 17, 2013

Transition from Gnome 3 to LXDE

1. Install LXDE as root
  # yum install @lxde-desktop

2. Log on as standard user in LXDE mode

3. Edit the file ~/.config/openbox/lxde-rc.xml and change font size for ActiveWindow and InactiveWindow from 10 to 1. This will finally make title bars completely vanish.

4. To enable clicking by tapping on touchpad, add following line to /etc/xdg/lxsession/LXDE/autostart:
  @synclient TapButton1=1

5. (Optional) If you want to adjust font size create file ~/.Xresources and add following line to it (default value 96):
  Xft.dpi: 163

6. Right click the "panel" and click on "panel settings" and set them as follows:
  Geometry
    Edge: Top
    Alignment: Left
    Width: Dynamic
    Height: 18
    Icon Size: 16
  Panel Applets
    Menu
    Application Launch Bar
      Select "Application Launch Bar" and clik on "Edit".
      Then add following items to Application Launch Bar:
        Files
        Firefox
        Terminal
        Sound
    System Tray
    Battery Monitor

7. Skip to step 9 if you don't want Mac-Expose/Gnome-3 style window switching.
  Edit the file ~/.config/openbox/lxde-rc.xml again and add following lines:
  <keybind key="A-grave">
    <action name="NextWindow"/>
  </keybind>
 
  Change key bindings for A-Tab to follows:
 
  <keybind key="A-Tab">
    <action name="Execute"><command>skippy-xd</command></action>
  </keybind>

8. Skippy-xd installation:
  Install mercurial
    # yum install mercurial
 
Install dependencies:
    # yum install libX11-devel libXmu-devel libXfixes-devel libXdamage-devel   
  Install skippy-xd.
    $ hg clone https://code.google.com/p/skippy-xd/
    $ cd skippy-xd
    $ make
   
    If make command results in error, verify if all dependencies given on the following link are installed : http://code.google.com/p/skippy-xd/wiki/Installation
   
    Copy skippy-xd executable to /usr/bin as root:
      # cp skippy-xd /usr/bin

9. Log out and log in again

How to survive the above configuration:
1. Use icons in the panel on the top to launch various applications.
2. Some applications can be launched by pressing Win-r key.
3. Since no window has title bar you can close a window by pressing Alt-F4
    You can replace Alt-F4 with some other value like Alt-q or Ctrl-q in the lxde-rc.xml file.
4. Use Alt-Tab or Alt-` to switch between applications (Mac-Expose/Gnome-3 style).