Archive

Archive for November, 2006

Linux on USB

Written on November 30th 2006, 13:11 by sYnie

Once this was a very detailed post about which distribution to use on a USB stick and how to get that managed. As I just translated it for devl.net, I keep it short.

I have used Slax in order to install it on a USB stick. Just plug it into any (new) computer, and it’ll boot from it (as long as the mainboard is able to do this and as long as it’s activated in the BIOS). Every Linux user will know the benefits of a full OS on a USB stick.

This is a short how-to about installing Slax on a USB stick:

  1. Plug in the stick and type `dmesg |tail` in order to get to know how the stick is named. Usually it’s sda or the partition sda1, which I’m also using furtheron. (Use your own device name instead of sda)
  2. Create partition table: `cfdisk /dev/sda`. Format the whole stick as Fat32 (Type 0B). Also give it a “Bootable Flag”. After writing, it should look something like this: sda1 Boot Primary W95 FAT32 [ ] 1022.92
  3. Format: `mkdosfs -F 16 /dev/sda1` creates a Fat16 partition, which can be also read by windows.
  4. Create a directory called “usb” (or whatever) in /mnt and mount /dev/sda to it: `mkdir /mnt/usb && mount /dev/sda1 /mnt/usb`
  5. Download Slax. It’s not important which version you use. I downloaded Slax Popcorn Edition.
  6. Open a shell and go to the directory where you have downloaded slax to  (`cd /home/you/whereever/downloads`) and create a directory called ‘usbslax’ by typing `mkdir usbslax`.
  7. Mount the iso to the just created directory: `mount -o loop slax-*.iso usbslax`.
  8. `cp -r slax/* /mnt/usb` will copy all the data to the USB stick.
  9. Go to the stick (`cd /mnt/usb`)
  10. copy isolinux.cfg to syslinux.cfg, as we want to use syslinux: `mv isolinux.cfg syslinux.cfg`
  11. Copy the kernel and initrd to the root directory of the stick, as it won’t be a live CD: `cp boot/vmlinuz boot/initrd.gz ./`
  12. Open syslinux.cfg in a any text edit tool (e.g. `vim syslinux.cfg`) change every  ‘/boot/vmlinuz’ to ‘vmlinuz’ and ‘/boot/initrd.gz’ to ‘initrd.gz’.
  13. Unmount: `cd .. && umount /dev/sda1`
  14. Install Lilo to the stick: `lilo -M /dev/sda` [grub didn't work for me]
  15. Make it bootable: `syslinux -s /dev/sda1`
  16. Reboot and enjoy: `sudo reboot`

Code Snippet: OGRE

Written on November 20th 2006, 12:11 by sYnie

Some days ago I started to work with ogre. In order to display 2D elements, I have used a nice class written by Hernán Moraldo (Nov 06).

I wrote a small class in order to set pictures using pixel coordinates. I’ve also implementet things like animations, etc.

image.h:

#ifndef image_h
#define image_h

#include “2d.h”
#include <iostream>
#include <ogre .h>
#include <ogretimer .h>
using namespace Ogre;
using namespace std;

class OImage : public Ogre2dManager
{
public:
OImage(Root *r, std::string cF);
~OImage();
void addImage(std::string cF);
void draw();
void setXYByPx(int x, int y);
void setWHByPx(int w, int h);
void moveX(float px);
void moveY(float py);
void setX(float px);
void setY(float py);
float getX();
float getY();
float getW();
float getH();
void setVisible(bool vis);
bool getVisible();
void setAnimated(bool anim);
bool getAnimated();
void setAnimationspeed(int time);
int getAnimationspeed();

protected:
Root *r;
SceneManager *sm;  // Scenemanager device
std::string images[24];  // the image array
int curImage;  // Which image shall be displayed ?
float x;  // x from 0 to 1
float y;  // y from 0 to 1
float w;  // w from 0 to 1
float h;  // h from 0 to 1
float pxw;  // W in pixels
float pxh;  // H in pixels
bool visible;
bool animated;
int animSpeed;
unsigned long lastTime;
Timer* timer;

};

#endif

image.cpp:

#include “image.h”

OImage::OImage(Root *rp, std::string cF) : Ogre2dManager()
{
timer = new Timer();
visible = 1;
animated = 0;
lastTime = timer->getMilliseconds();
x = 0.5;
y = 0.5;
w = 0.5;
h = 0.5;
r = rp;
sm = r->getSceneManager(”sceneManager”);
images[0] = cF;
curImage = 0;
animSpeed = 30;
init(sm, Ogre::RENDER_QUEUE_OVERLAY, true);
TextureManager::getSingleton().load(images[curImage], “General”);
}

OImage::~OImage()
{
end();
}

void OImage::addImage(std::string cF)
{
for (int i = 0; i < = 31; i++)
{
if (images[i] == “”)
{
images[i] = cF;
TextureManager::getSingleton().load(images[i], “General”);
break;
}
}
}

void OImage::draw()
{
if (animated)
{
if ((timer->getMilliseconds()-lastTime) >= animSpeed)
{
curImage++;
if (curImage >= 32)
curImage = 0;
if (images[curImage] == “”)
curImage = 0;
lastTime = timer->getMilliseconds();
}
}

if (visible)
spriteBltFull(images[curImage], (x*2)-1, ((y*2)-1)*(-1), ((x*2)-1)+(w*2), ((y*2)-1)*(-1)-(h*2));
}

void OImage::setXYByPx(int px, int py)
{
x = ((1.0/r->getAutoCreatedWindow()->getWidth())*px);
y = ((1.0/r->getAutoCreatedWindow()->getHeight())*py);
setWHByPx(pxw, pxh);
}

void OImage::setWHByPx(int pw, int ph)
{
pxw = pw;
pxh = ph;
w = ((1.0/r->getAutoCreatedWindow()->getWidth())*pw);
h = ((1.0/r->getAutoCreatedWindow()->getHeight())*ph);
}

//
// to move the image between -1 and 1
//
void OImage::moveX(float px)
{
x += px;
}

//
// to move the image between -1 and 1
//
void OImage::moveY(float py)
{
y -= py;
}

//
// to set the image
//
void OImage::setX(float px)
{
x = px;
}

//
// to set the image
//
void OImage::setY(float py)
{
y = py;
}

float OImage::getX()
{
return x;
}

float OImage::getY()
{
return y;
}

float OImage::getW()
{
return w;
}

float OImage::getH()
{
return h;
}

//
// sets wether the image is blitted or not
//
void OImage::setVisible(bool vis)
{
visible = vis;
}

//
// will the image be blitted ?
//
bool OImage::getVisible()
{
return visible;
}

//
// changes the images from the image array
//
void OImage::setAnimated(bool anim)
{
animated = anim;
}

//
// is it animated ?
//
bool OImage::getAnimated()
{
return animated;
}

//
// Changes the time (in MS) between the images (animation)
//
void OImage::setAnimationspeed(int time)
{
animSpeed = time;
}

//
// Get the animationsoeed
//
int OImage::getAnimationspeed()
{
return animSpeed;
}

This is a Example:

OImage* anim;
cursor = new OImage(r, “anim1.png”);
cursor->addImage(”anim2.png”);
cursor->addImage(”anim3.png”); …
cursor->setWHByPx(32,32);
// In die mitte des Fensters setzen. r = Root-Objekt.
cursor->setXYByPx(r->getAutoCreatedWindow()->getWidth()/2,r->getAutoCreatedWindow()->getHeight()/2);
// Animation:
cursor->setAnimated(1);
cursor->setAnimationspeed(15);

// In frameStarted():
cursor->draw();