An Old Chinese Proverb : "One Picture Is Worth Ten Thousand Words !"





Hacking on assembly code: Dynamic memory allocation on stack?

So I started dabbling with assembly language programming a couple of days ago. This was the next logical step in the "going lower down" move I have been doing ever since I started writing programs in Visual Basic some years ago (there, I admitted it). Since then I went through C#, Java, C++, C and now finally assembly. And it is fun to watch a program die in so many innovative ways. It is helping me understand the internals of a program much better.

One of the first things I learnt about assembly programming was that I needed to use completely different syscall numbers and instructions for x86_64 as compared to i386. For example, the syscall number for exit on i386 is 1 while on x86_64 it is 60. Same goes for write -- 4 on i386 and 1 on x86_64. I spent half an our trying to figure out why my program was calling fstat on x86_64 while a similar program built with --32 would work fine.

Crossing all these hurdles, I finally wrote a slightly more complicated (but still useless) program than a hello world. This is a program that takes in an integer string through the command line, converts it to an integer, converts it back to string and prints it back out. Pretty useful huh :)

Now for the interesting part in the code. I always thought of dynamic memory allocation as something you can only do through the OS using the brk() and/or mmap() syscalls. Generally we do this indirectly through malloc() and friends. But what I ended up doing in my program is allocating memory on the stack on the fly. Here's the code snippet:

	movb $0x0a, (%rsp)
	decq %rsp
next_digit:
	movq $0, %rdx
	divq %rdi
	addq $0x30, %rdx

	# Hack since we cannot 'push' a byte
	movb %dl, (%rsp)
	decq %rsp

The complete code along with the makefile is at the end of this post. You can build it if you have an x86_64 installation. What I do above is simply:

  1. Read a digit from the number
  2. Move the stack pointer ahead to make room for a byte
  3. Store the ascii representation of that number into that byte

I could not use the push instruction itself, since it can only push 16, 32 or 64 bit stuff on to the stack (with pushw, pushl, pushq). If you push a single byte value, it will be stored in one of the above sizes, not in just 1 byte. What I wanted was to create a string on the fly without limiting myself to a fixed size array, so this seemed to be the only approach. While this works, I still need to find out a few more things about this:

  1. Is it safe?
  2. If it is safe, then is there a similar way to do this in C without embedding assembly code? This would be really cool, especially in usage scenarios such as the above. Admitted that the above scenario is pretty useless in itself, but I'm sure there must be similar examples out there that are at least a little more useful.

The code:

.section .data
usage:
	.ascii "Usage: printnum-64 <the number>\n"
	usagelen = . - usage

.section .text
.globl _start

# Convert a string representation of an integer into an int
.type _get_num, @function
_get_num:
	push %rbp
	movq %rsp, %rbp
	movq 0x10(%rbp), %rdx
	mov $0x0, %rcx
	mov $0x0, %rax
nextchar:
	# Iterate through the string
	movb (%rdx), %cl
	cmp $0x0, %rcx
	je call_done

	subq $0x30, %rcx
	imulq $0xa, %rax
	addq %rcx, %rax
	incq %rdx
	jmp nextchar

# Convert a number into a printable string
.type _print_num, @function
_print_num:
	push %rbp
	movq %rsp, %rbp
	movq 0x10(%rbp), %rax
	movq $0x0a, %rdi

	# Hack since we cannot 'push' a byte and increment
	# %rsp by only 1. push will push whatever it has as
	# a 16, 32 or 64 bit value (pushw, pushl, pushq)
	movb $0x0a, (%rsp)
	decq %rsp
next_digit:
	movq $0, %rdx
	divq %rdi
	addq $0x30, %rdx

	# Hack since we cannot 'push' a byte
	movb %dl, (%rsp)
	decq %rsp

	cmp $0x0, %rax
	jne next_digit

	movq %rsp, %rbx
	addq $0x1, %rbx
	movq %rbp, %rcx
	subq %rsp, %rcx

	push %rcx
	push %rbx
	push $0x01
	call _write
	jmp call_done

# Wrap around the write system call
.type _write, @function
_write:
	push %rbp
	movq %rsp, %rbp
	movq 0x10(%rbp), %rdi
	movq 0x18(%rbp), %rsi
	movq 0x20(%rbp), %rdx
	movq $0x01, %rax
	syscall
	jmp call_done

# I always do this when I am done with a function call
call_done:
	movq %rbp, %rsp
	pop %rbp
	ret

#Program Entry point
_start:
	# Command line arguments:
	# The parameter list is:
	# argc: The number of arguments
	# argv: The addresses of all arguments one after the other
	#       They can be popped out one by one
	pop %rax
	cmp $0x2, %rax
	jne error

	# Pop out the first arg since it is the program name, but
	# keep the second so that it can be fed into the next function
	pop %rax

	call _get_num
	push %rax
	call _print_num
	jmp exit
error:
	push $usagelen
	push $usage
	push $0x2
	call _write
	movq $0xff, %rax
exit:
	movq %rax, %rdi
	movq $60, %rax
	syscall

The makefile:

32:
	as --32		$(target).s	-o $(target).o
	ld -melf_i386	$(target).o	-o $(target)

64:
	as $(target).s	-o $(target).o
	ld $(target).o	-o $(target)

If you save the source as foo.s, you can build it with:

make target=foo 64

Tags: assembly

Posted: 2010-07-19 16:44:29

Write by: Siddhesh Poyarekar


Install Mono on Windows XP.

To install Mono 2.6.4 with gtk # 2.12.10 softwares, you must download this software from here.

In the next image we see all the platforms... We chose the Windows platform.

mono tutorial

The next image will show you how I installed Mono software"

mono tutorial

This is all for today.

Tags: Mono

Posted: 2010-07-03 17:55:12

Write by: Catalin


Installing and configuring the Eclipse IDE - Google Plugin for Eclipse

Installing and configuring the Eclipse IDE is easy. Write this command in the console:

#yum search eclipse

You will see the Eclipse IDE and related packages. First we will install Eclipse IDE:

#yum install eclipse-platform.i386

Start Eclipse IDE from menu Application - Programming - Eclipse. You will see the following image:

Eclipse

(Click on images to see a better resolution.)

Eclipse IDE starts with a start page Welcome as shown below:

Eclipse install

There are five icons each opening anything. The first is about Overview. See image bellow:

Eclipse install

Next icon leads to What's new?

Eclipse install

We can see Samples.

Eclipse install

We can learn from Tutorials.

Eclipse install

Last icon leads us Workbench.

Eclipse install

The next picture we see how we can configure plugins. From the top menu choose Help, then Software Updates and clik on Find and Install.

Eclipse install

A new window appears. Choose Search for new features to install. See next picture:

Eclipse install

Click on Next and we'll see another window. In this window, we add new plugins. Click the New Remote Site.

Eclipse install

Add the following data:

Name: Google Plugin for Eclipse 3.3 (Europa)
URL: http://dl.google.com/eclipse/plugin/3.3

... press Ok button.

Eclipse install

This new window shows that we added a new plugin on a remote site. Click Next to be loaded this plugin. See image:

Eclipse install

We have to accept limits and licenses.

Eclipse install

We'll see what plugins will load. Click Finish to complete the installation.

Eclipse install

Wait until the download plugins.

Eclipse install

A window will tell us what plugins have been downloaded. Click Install All to complete the process.

Eclipse install

Wait until it installs on your computer.

Eclipse install

You will need to restart the Eclipse IDE. Click the Yes button.

Eclipse install

When we open a new project will see that we can use google plugin applications. See screenshot below:

Eclipse install

I hope this tutorial will be useful.

Tags: Eclipse, Google

Posted: 2010-06-27 14:48:25

Write by: Catalin


How to set up an external webrowser on Eclipse IDE

This tutorial is made for version 3.3.2 of the Eclipse IDE. I will show how to set up an external webrowser. First start Eclipse program. Go to the main menu to Windows. See the image below:

tutorial Eclipse image

Click on the General to display options. See next image:

tutorial Eclipse image

You will find below Web Browser. It is set to Default system Web browser. See picture below:

tutorial Eclipse image

Click New to add a new web browser. A window will appear as shown below:

tutorial Eclipse image

In the next picture you can see the path and name of my Web browser.

tutorial Eclipse image

In the next picture you can see the path and name of my Web browser. Put all necessary data to your Web browser and press the OK button. We see as my web browser added.

tutorial Eclipse image

Go back to the Windows menu. Then go on to Web Browser and click on your external web browser. Here you can set your web browser working. See picture below:

tutorial Eclipse image

That is all.

Tags: Eclipse, tutorial

Posted: 2010-06-26 10:32:58

Write by: Catalin


Fedora - Install Skype

You can install Skype from repository.

Go on :

#cd /etc/yum.repos.d/

First create a file named

skype.repo

Put this code on this file :

[skype]
name=Skype Repository
baseurl=http://download.skype.com/linux/repos/fedora/updates/i586/
gpgkey=http://www.skype.com/products/skype/linux/rpm-public-key.asc

Save the file.

Use :

#yum install skype

This is all.

Tags: Linux,Fedora,Skype

Posted: 2010-06-15 18:51:34

Write by: Catalin


Geany and regular expressions - tutorial number two

As we told in another tutorial about Geany editor, we can use regular expresions to change

text or source code.

In this example Geany uses regular expressions ( keys Ctr + h) to remove

the rows with numbers. I use this [0-9\. ]*$ sintax.

Please see in the image below:

tutorial regular expression

Tags: geany, regular expression, editors

Posted: 2010-06-02 19:45:15

Write by: Catalin


Modifying shortcuts keys on Bluefish 1.0.7

Bluefish is a good software to edit web page. The linux user has need keyboard shortcuts

Open a new Untitle 0 Bluefish 1.0.7 document.

First move the mouse over a menu entry.For example use :

Tags - Format by context - Sample 

See image bellow:

free tutorial bluefish editor

To remove a shortcut, hit twice the backspace key.

First you will see text BackSpace this mean is assign the backspace key.

When you press the backspace key a second time you will not have any assigned key.

Now we need to save the shortcut key combinations. To make this use from menu software tag.

Edit - Save Shortcut Keys
bluefish editor

If you want to restore the default combinations simply stop Bluefish and remove this file from :

~/.bluefish/menudump_2

Now we will restart the Bluefish software.

Tags: Software,HTML,Web,Custom

Posted: 2010-06-01 20:12:41

Write by: Catalin


Fedora - How we can get movies from youtube.

The easy way to download movies from youtube on linux, is :youtube-dl

# yum install youtube-dl.noarch 

Use this command to show help options of this script.

$ youtube-dl --help
Usage: youtube-dl [options] video_url

Options:
  -h, --help            print this help text and exit
  -v, --version         print program version and exit
  -u USERNAME, --username=USERNAME
                        account username
  -p PASSWORD, --password=PASSWORD
                        account password
  -o FILE, --output=FILE
                        output video file name
  -q, --quiet           activates quiet mode
  -s, --simulate        do not download video
  -t, --title           use title in file name
  -l, --literal         use literal title in file name
  -n, --netrc           use .netrc authentication data
  -g, --get-url         print final video URL only
  -2, --title-too       used with -g, print title too

To download a movie from youtube, just write command:

$ youtube-dl http://www.youtube.com/watch?v=NNFYOX3oNvw 
Retrieving video webpage... done.
Extracting URL "t" parameter... done.
Requesting video file... done.
Video data found at http://v9.lscache6.c.youtube.com/videoplayback?ip=0.0.0.0&sparams
=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWSlJPVF9FSkN
NNl9KSVhB&fexp=900808%2C904000&algorithm=throttle-factor&itag=5&ipbits=0&burst=40&sver
=3&expire=1275246000&key=yt1&signature=D54C2822EABFE0A6633436510740C66DBB213329.3F4B6F
7093E92C20FF9E708B4181F04A913B0A16&factor=1.25&id=34d158397de836fc
Retrieving video data: 100.0% (  97.93k of 97.93k) at    3.37M/s ETA 00:00 done.
Video data saved to NNFYOX3oNvw.flv

Try it's a good script.

Tags: Linux,Fedora,youtube

Posted: 2010-05-30 14:34:38

Write by: Catalin


Windows 7 and Counter Strike 1.6

How to make run Counter Strike 1.6 on Windows 7

Click on the Start button.

Use right-click Computer and then select Properties.

Click on to the Advanced System Settings.

Open the Performance Settings button, then click on to the Data Execution Prevention tab.

Check now the box named Turn on DEP for all the Programs and Services except those I select.

Now click Add and add game Counter Strike 1.6 in the list of exceptions.

See bellow on image this option :

windows 7

Tags: windows 7

Posted: 2010-05-29 18:46:45

Write by: Catalin


BASH shell scripting tips - part 1 : Working with shell variables.

As we know , we used following syntax will to create a default script bash.

First line: signifies that is the bash script:

#!/bin/bash

Every line and everything after the # is treated as comment:

# this is a comment 

A shell variable may be assigned using following syntax:

variable=value_of_variable

Example:

$ a=10 
$ echo $a
10

Try this command:

$man bash 
We'll see:
...
   Shell Variables
       The following variables are set by the shell:

       BASH   Expands to the full file name used to invoke  this  instance  of
              bash.
       BASH_ARGC
... and more 

Let's try a simple script. First we created file test.sh with this code:

#!/bin/bash
var1=$1
var2=$2
echo var1 $var1
echo var2 $var2

Let's see the some outputs:

$ sh test.sh 
var1
var2
$ sh test.sh 11
var1 11
var2
$ sh test.sh 11 12
var1 11
var2 12
$ sh test.sh none 11
var1 none
var2 11
$ sh test.sh '' 11
var1
var2 11

We'll see how we work with "Shell Variables"

$ echo $SHELL
/bin/bash
$ echo $USER
Cata
$ echo $PATH 
/usr/local/bin:/usr/bin:/bin:/usr/games

Good. Let's set one.

TMOUT  If  set  to  a  value greater than zero, TMOUT is treated as the
              default timeout for the read builtin.  The select command termi-
              nates if input does not arrive after TMOUT seconds when input is
              coming from a terminal.  In an interactive shell, the  value  is
              interpreted  as  the  number  of seconds to wait for input after
              issuing the primary prompt.  Bash terminates after  waiting  for
              that number of seconds if input does not arrive.

How set this variable ?

First of all, the value of TMOUT...

$ echo TMOUT
TMOUT

Now we will set this value to 10

$ export TMOUT=10 

It is 10 ? Let's see:

$ echo $TMOUT
10

Now the terminal will close in 10 seconds of inactivity.

This is the first part of the tutorial.

Tags: Linux,bash

Posted: 2010-05-11 20:11:57

Write by: Catalin


Parsing files and rename ...

Sometimes you have to rename files. This can be tiring when we do it manually. Command "se" may be helpful in this case. I'll take a simple example. I will create a working directory called "work."

We have to create files with the command:


for (( i=1; i<10; i++ )); do echo data$i > data[$i]x[$i].txt;done

The result should be :


$ ls
data[1]x[1].txt  data[3]x[3].txt  data[5]x[5].txt  data[7]x[7].txt  data[9]x[9].txt
data[2]x[2].txt  data[4]x[4].txt  data[6]x[6].txt  data[8]x[8].txt

Try these commands to parse and rename files:


$ for i in  *[]x[]*; do mv -v "$i" "$(echo $i | sed 's/[]x[]//')"; done
`data[1]x[1].txt' -> `data1]x[1].txt'
`data[2]x[2].txt' -> `data2]x[2].txt'
`data[3]x[3].txt' -> `data3]x[3].txt'
`data[4]x[4].txt' -> `data4]x[4].txt'
`data[5]x[5].txt' -> `data5]x[5].txt'
`data[6]x[6].txt' -> `data6]x[6].txt'
`data[7]x[7].txt' -> `data7]x[7].txt'
`data[8]x[8].txt' -> `data8]x[8].txt'
`data[9]x[9].txt' -> `data9]x[9].txt'
[work@test work]$ for i in  *[]x[]*; do mv -v "$i" "$(echo $i | sed 's/[]x[]//')"; done
`data1]x[1].txt' -> `data1x[1].txt'
`data2]x[2].txt' -> `data2x[2].txt'
`data3]x[3].txt' -> `data3x[3].txt'
`data4]x[4].txt' -> `data4x[4].txt'
`data5]x[5].txt' -> `data5x[5].txt'
`data6]x[6].txt' -> `data6x[6].txt'
`data7]x[7].txt' -> `data7x[7].txt'
`data8]x[8].txt' -> `data8x[8].txt'
`data9]x[9].txt' -> `data9x[9].txt'
[work@test work]$ for i in  *[]x[]*; do mv -v "$i" "$(echo $i | sed 's/[]x[]//')"; done
`data1x[1].txt' -> `data1[1].txt'
`data2x[2].txt' -> `data2[2].txt'
`data3x[3].txt' -> `data3[3].txt'
`data4x[4].txt' -> `data4[4].txt'
`data5x[5].txt' -> `data5[5].txt'
`data6x[6].txt' -> `data6[6].txt'
`data7x[7].txt' -> `data7[7].txt'
`data8x[8].txt' -> `data8[8].txt'
`data9x[9].txt' -> `data9[9].txt'
[work@test work]$ for i in  *[]x[]*; do mv -v "$i" "$(echo $i | sed 's/[]x[]//')"; done
`data1[1].txt' -> `data11].txt'
`data2[2].txt' -> `data22].txt'
`data3[3].txt' -> `data33].txt'
`data4[4].txt' -> `data44].txt'
`data5[5].txt' -> `data55].txt'
`data6[6].txt' -> `data66].txt'
`data7[7].txt' -> `data77].txt'
`data8[8].txt' -> `data88].txt'
`data9[9].txt' -> `data99].txt'
[work@test work]$ for i in  *[]x[]*; do mv -v "$i" "$(echo $i | sed 's/[]x[]//')"; done
`data11].txt' -> `data11.txt'
`data22].txt' -> `data22.txt'
`data33].txt' -> `data33.txt'
`data44].txt' -> `data44.txt'
`data55].txt' -> `data55.txt'
`data66].txt' -> `data66.txt'
`data77].txt' -> `data77.txt'
`data88].txt' -> `data88.txt'
`data99].txt' -> `data99.txt'

This is just a simple example ...

Tags: Linux,bash

Posted: 2010-04-13 17:36:13

Write by: Catalin


Python and OpenOffice - Start OpenOffice.

Simple python script to start the OpenOffice software. This script starts OpenOfice software. The script uses the following modules:

import os
import sys
import time
import uno
import subprocess

Now we define the arguments for each software OpenOffice:

NoConnectionException = uno.getClass("com.sun.star.connection.NoConnectException")
ooffice = 'ooffice "-accept=socket,host=localhost,port=8100;urp;"'
oocalc = 'oocalc "-accept=socket,host=localhost,port=8100;urp;"'
ooimpress = 'ooimpress "-accept=socket,host=localhost,port=8100;urp;"'
oowriter = 'oowriter "-accept=socket,host=localhost,port=8100;urp;"'

The next step, we define a function that will start OpenOffice software. See below:


def OOo(soft):
    ''' start ooo software '''
    # using fork 
    if os.fork():
        return

    # Start OpenOffice.org and report any errors that
    # occur.
    try:
        retcode = subprocess.call(soft, shell=True)
        if retcode < 0:
            print >>sys.stderr,"retcode is ",-retcode
        elif retcode > 0:
            print >>sys.stderr,"retcode is ",retcode
    except OSError, e:
        print >>sys.stderr, "Error is :", err
    raise SystemExit()

We use a variable to set the mode.

In this case it is set to "False" and print some options:


OOo_ok = False
print "Use command =s bellow to start OOo features :"
print "oocalc     ooffice    ooimpress  oowriter  "
print "Do not use spaces, we will receive errors "

Read from the keyboard software OpenOffice name to be started.

Then check if it is not already running.


startooo=raw_input("What Ooo need to use > ")
if not OOo_ok:
	OOo_ok = True
	OOo(startooo)

Awaiting 5 seconds. During this time the software starts.


time.sleep(5)
print "OOo started now"
This is all you need.

Tags: OpenOffice,OOo

Posted: 2010-04-13 17:35:02

Write by: Catalin


Fedora 12 - How can we run one script when system startup?

Open one xterm or console.

Use command cd /etc/init.d/ .

You are now on /etc/init.d/ directory.

Create file named my_filename.

Add your script to this file with the following lines at the top:

#!/bin/bash
# chkconfig: 345 85 15
# some description for your file

Enter this in the shell:

chkconfig --add my_filename

Use command chmod u+x my_filename to make this script executable.

Type command:ntsysv

You will see a GUI.

Your startup script should now be in the list.

Use space key to set your script.

Tags: Linux,Fedora-12

Posted: 2010-03-29 18:49:40

Write by: Catalin


Linux Text-To-Speech Tutorial

In this tutorial we show you how to do text-to-speech under Linux with the Festival application.

First you need to install it on your system . On my Fedora 12 I used this:

#yum install festival

Try this command to see if it will allow you to use festival:

$which festival 
/usr/bin/festival

Now you can use "festival" to synthesis it into speech. Try this example:

$echo "This is a test " | festival --tts

Another beautiful software is "text2wave". You can save text like a sound file.

$echo "This is a test " | text2wave  -o test.wav

Both commands has more options, you can see this by using the "man" command.

Tags: Linux

Posted: 2010-03-09 12:17:23

Write by: Catalin


Irrlicht - 3D Engine - Part 1

What is Irrlicht Engine ?

The Irrlicht Engine is an open source 3D engine. This engine is written and usable in C++ and also available for .NET. The engine is completely cross-platform using D3D and OpenGL.

How works ?

Download the irrlicht from http://irrlicht.sourceforge.net. I will show how this working on Linux. I use Fedora 12. In this tutorial I will show how to used Irrlicht 1.6 . The new version - irrlicht 1.7 is used in same manner. First i install libs of OpenGL and g++. See bellow , i used yum command in super user mode:

#yum install ghc-OpenGL-devel.i686
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ghc-OpenGL-devel.i686 0:2.2.1.1-1.fc12 set to be updated
--> Processing Dependency: ghc = 6.10.4 for package: ghc-OpenGL-devel-2.2.1.1-1.fc12.i686
--> Processing Dependency: ghc = 6.10.4 for package: ghc-OpenGL-devel-2.2.1.1-1.fc12.i686
--> Processing Dependency: mesa-libGL-devel for package: ghc-OpenGL-devel-2.2.1.1-1.fc12.i686
--> Processing Dependency: mesa-libGLU-devel for package: ghc-OpenGL-devel-2.2.1.1-1.fc12.i686
--> Running transaction check
---> Package ghc.i686 0:6.10.4-2.fc12 set to be updated
--> Processing Dependency: gmp-devel for package: ghc-6.10.4-2.fc12.i686
---> Package mesa-libGL-devel.i686 0:7.6-0.13.fc12 set to be updated
--> Processing Dependency: pkgconfig(libdrm) >= 2.4.3 for package: mesa-libGL-devel-7.6-0.13.fc12.i686
--> Processing Dependency: pkgconfig(xdamage) for package: mesa-libGL-devel-7.6-0.13.fc12.i686
--> Processing Dependency: pkgconfig(xxf86vm) for package: mesa-libGL-devel-7.6-0.13.fc12.i686
---> Package mesa-libGLU-devel.i686 0:7.6-0.13.fc12 set to be updated
--> Running transaction check
---> Package gmp-devel.i686 0:4.3.1-5.fc12 set to be updated
---> Package libXdamage-devel.i686 0:1.1.2-1.fc12 set to be updated
---> Package libXxf86vm-devel.i686 0:1.1.0-1.fc12 set to be updated
---> Package libdrm-devel.i686 0:2.4.15-8.fc12 set to be updated
--> Processing Dependency: libdrm = 2.4.15-8.fc12 for package: libdrm-devel-2.4.15-8.fc12.i686
--> Running transaction check
---> Package libdrm.i686 0:2.4.15-8.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                           Arch                  Version                           Repository                 Size
===================================================================================================================================
Installing:
 ghc-OpenGL-devel                  i686                2.2.1.1-1.fc12                      fedora                      1.2 M
Installing for dependencies:
 ghc                               i686                6.10.4-2.fc12                       fedora                       23 M
 gmp-devel                         i686                4.3.1-5.fc12                        fedora                      168 k
 libXdamage-devel                  i686                1.1.2-1.fc12                        fedora                      8.7 k
 libXxf86vm-devel                  i686                1.1.0-1.fc12                        fedora                       17 k
 libdrm-devel                      i686                2.4.15-8.fc12                       updates                      71 k
 mesa-libGL-devel                  i686                7.6-0.13.fc12                       fedora                      459 k
 mesa-libGLU-devel                 i686                7.6-0.13.fc12                       fedora                      108 k
Updating for dependencies:
 libdrm                            i686                2.4.15-8.fc12                       updates                      60 k

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

Total download size: 25 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Download delta size: 20 k
libdrm-2.4.15-4.fc12_2.4.15-8.fc12.i686.drpm                                            |  20 kB     00:00     
Finishing rebuild of rpms, from deltarpms											    |  60 kB     00:01     
Presto reduced the update size by 66% (from 60 k to 20 k).
Package(s) data still to download: 25 M
(1/8): ghc-6.10.4-2.fc12.i686.rpm                                                        |  23 MB     00:05     
(2/8): ghc-OpenGL-devel-2.2.1.1-1.fc12.i686.rpm                                          | 1.2 MB     00:00     
(3/8): gmp-devel-4.3.1-5.fc12.i686.rpm                                                   | 168 kB     00:00     
(4/8): libXdamage-devel-1.1.2-1.fc12.i686.rpm                                            | 8.7 kB     00:00     
(5/8): libXxf86vm-devel-1.1.0-1.fc12.i686.rpm                                            |  17 kB     00:00     
(6/8): libdrm-devel-2.4.15-8.fc12.i686.rpm                                               |  71 kB     00:00     
(7/8): mesa-libGL-devel-7.6-0.13.fc12.i686.rpm                                           | 459 kB     00:00     
(8/8): mesa-libGLU-devel-7.6-0.13.fc12.i686.rpm                                          | 108 kB     00:00     
--------------------------------------------------------------------------------------------------------------
Total                                                                                      4.0 MB/s |  25 MB     00:06     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : libXdamage-devel-1.1.2-1.fc12.i686                                      1/10 
  Installing     : gmp-devel-4.3.1-5.fc12.i686                                             2/10 
  Installing     : libXxf86vm-devel-1.1.0-1.fc12.i686                                      3/10 
  Updating       : libdrm-2.4.15-8.fc12.i686                                               4/10 
  Installing     : ghc-6.10.4-2.fc12.i686                                                  5/10 
  Installing     : libdrm-devel-2.4.15-8.fc12.i686                                         6/10 
  Installing     : mesa-libGL-devel-7.6-0.13.fc12.i686                                     7/10 
  Installing     : mesa-libGLU-devel-7.6-0.13.fc12.i686                                    8/10 
  Installing     : ghc-OpenGL-devel-2.2.1.1-1.fc12.i686                                    9/10 
  Cleanup        : libdrm-2.4.15-4.fc12.i686                                               10/10 

Installed:
  ghc-OpenGL-devel.i686 0:2.2.1.1-1.fc12                        

Dependency Installed:
  ghc.i686 0:6.10.4-2.fc12            gmp-devel.i686 0:4.3.1-5.fc12           libXdamage-devel.i686 0:1.1.2-1.fc12     
  libXxf86vm-devel.i686 0:1.1.0-1.fc12       
  libdrm-devel.i686 0:2.4.15-8.fc12   mesa-libGL-devel.i686 0:7.6-0.13.fc12   mesa-libGLU-devel.i686 0:7.6-0.13.fc12       

Dependency Updated:     
  libdrm.i686 0:2.4.15-8.fc12                                                                                                                               

Complete!

Now in same manner,you will install g++:

#yum -y install gcc-c++

First, i downloaded both arhives of irrlicht--1.6.1 and irrlicht--1.7.1, see this command:

$ls irr*
irrlicht-1.6.1:
bin  changes.txt  doc  examples  include  lib  media  readme.txt  source  tools

irrlicht-1.7.1:
bin  changes.txt  doc  examples  include  lib  media  readme.txt  source  tools

Now, go and write on console this commands :

$cd irrlicht-1.6.1/
$cd source/
$cd Irrlicht/
$make

You will see something like this:

g++ -I../../include -Izlib -Ijpeglib -Ilibpng -DIRRLICHT_EXPORTS=1 -MM -MF CGUITreeView.d CGUITreeView.cpp
g++ -I../../include -Izlib -Ijpeglib -Ilibpng -DIRRLICHT_EXPORTS=1 -MM -MF CGUIImageList.d CGUIImageList.cpp
g++ -I../../include -Izlib -Ijpeglib -Ilibpng -DIRRLICHT_EXPORTS=1 -MM -MF CGUISpriteBank.d CGUISpriteBank.cpp

This will take a time...


$cd ..
$cd ..
$ls
bin  changes.txt  doc  examples  include  lib  media  readme.txt  source  tools
$cd examples/
$ls
01.HelloWorld       09.Meshviewer        17.HelloWorld_Mobile     BuildAllExamples_v8.sln
02.Quake3Map        10.Shaders           18.SplitScreen           BuildAllExamples_v9.sln
03.CustomSceneNode  11.PerPixelLighting  19.MouseAndJoystick      BuildAllExamples.workspace
04.Movement         12.TerrainRendering  20.ManagedLights         Demo
05.UserInterface    13.RenderToTexture   21.Quake3Explorer        Makefile
06.2DGraphics       14.Win32Window       BuildAllExamples.MacOSX  whereAreTheBinaries.txt
07.Collision        15.LoadIrrFile       buildAllExamples.sh
08.SpecialFX        16.Quake3MapShader   BuildAllExamples_v7.sln
$sh buildAllExamples.sh
Building 01.HelloWorld
~/irrlicht-1.6.1/examples/01.HelloWorld ~/irrlicht-1.6.1/examples
Makefile:51: Cleaning...
Makefile:47: Building...
g++ -I../../include -I/usr/X11R6/include  -O3 -ffast-math main.cpp -o ../../bin/Linux/01.HelloWorld -L../../lib/Linux
 -lIrrlicht -L/usr/X11R6/lib -lGL -lXxf86vm -lXext -lX11

As you see , this will build all examples. Finally you see some errors , don't worry.


...
CDemo.cpp: In member function 'void CDemo::startIrrKlang()':
CDemo.cpp:772: error: 'irrKlang' was not declared in this scope
CDemo.cpp:772: error: 'irrklang' has not been declared
CDemo.cpp:779: error: 'irrklang' has not been declared
CDemo.cpp:779: error: 'snd' was not declared in this scope
CDemo.cpp:791: error: 'ballSound' was not declared in this scope
CDemo.cpp:792: error: 'impactSound' was not declared in this scope
make: *** [CDemo.o] Error 1
~/irrlicht-1.6.1/examples

In this moment you can run all examples (see /irrlicht-1.6.1/bin/Linux/). Let's try one:


$cd ..
$cd bin
$cd Linux/
$./01.HelloWorld 
Irrlicht Engine version 1.6.1
Linux 2.6.31.12-174.2.19.fc12.i686 #1 SMP Thu Feb 11 07:39:11 UTC 2010 i686
Creating X window...
Using plain X visual
Visual chosen: : 33
Loaded mesh: ../../media/sydney.md2
...
Irrlicht

If you will try to run all examples and you have a old graphic card not all will run properly.

Some examples run only on console because you need to select driver. You will see this message :

Please select the driver you want for this example
The tools from Irrlicht

The Irrlicht has some tools to helps users. The directories from tools folder is :


$tree -d 
|-- tools
    |-- GUIEditor
    |-- irrEdit
    |-- IrrFontTool
    |   |-- newFontTool
    |   |-- oldFontTool
    |-- MeshConverter
    |-- Meshviewer

Only GUIEditor, newFontTool and MeshConverter works on Linux.

See now how compile the GUIEditor

When you compiling GUIEditor you see some errors:


CGUIEditWorkspace.cpp:565: warning: enumeration value 'EGET_TAB_CHANGED' not handled in switch
CGUIEditWorkspace.cpp:565: warning: enumeration value 'EGET_COMBO_BOX_CHANGED' not handled in switch

But, GUIEditor running well.

./GUIEditor 
Please select the driver you want for this example:
 (a) Direct3D 9.0c
 (b) Direct3D 8.1
 (c) OpenGL 1.5
 (d) Software Renderer
 (e) Burning's Software Renderer
 (f) NullDevice
 (otherKey) exit
c
Irrlicht Engine version 1.6.1
Linux 2.6.31.12-174.2.19.fc12.i686 #1 SMP Thu Feb 11 07:39:11 UTC 2010 i686
Creating X window...
Visual chosen: : 39
Using renderer: OpenGL 2.1.2
GeForce FX 5200/AGP/SSE/3DNOW!: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 1.2
...

Irrlicht
See now how compile the newFontTool.

$cd newFontTool/
$make
Makefile:29: Building...
g++ -I../../../include -I/usr/X11R6/include -I/usr/include/freetype2/ -O3 -ffast-math CFontTool.cpp main.cpp 
-o ../../../bin/Linux/FontTool -L/usr/X11R6/lib -L../../../lib/Linux -lIrrlicht -lGL -lGLU -lXxf86vm -lXext -lX11 -lXft
main.cpp:74: warning: deprecated conversion from string constant to 'wchar_t*'
main.cpp:82: warning: deprecated conversion from string constant to 'wchar_t*'

The output file is Fontool on /bin/Linux/

Irrlicht
See now how compile the MeshConverter.

$cd MeshConverter/
$make
Makefile:29: Building...
g++ -I../../include -I/usr/X11R6/include -O3 -ffast-math -Wall main.cpp -o ../../bin/Linux/MeshConverter -L/usr/X11R6/lib
 -L../../lib/Linux -lIrrlicht -lGL -lGLU -lXxf86vm -lXext -lX11
The output file  is MeshConverter on /bin/Linux/
$./MeshConverter 
Usage: ./MeshConverter [options]  	<srcFile>  	<destFile>
  where options are
 --createTangents: convert to tangents mesh is possible.
 --format=[irrmesh|collada|stl|obj|ply]: Choose target format

The Irrlicht 1.7.1 will be installed in the same way. I tried that.

Tags: 3D Engine

Posted: 2010-02-24 14:11:58

Write by: Catalin


Loki - render farm

What is Loki software ?

If you  having several computers work together can greatly decrease the total time needed.

Loki Render is a cross-platform job queue manager for rendering 3D frames.

Loki Render distributes the rendering of Blender 3D images named frames across several computer.

How to install the software ?

You can download this software from : sourceforge.net/projects/loki-render .

Extract the zip file.

How to set Loki software ?

I try this software with a blend file created with blender 2.49.

I use two computers .First  is server on Fedora 12 and second is on XP .

On File -> Preferences ( Ctr+P ) you can set the role of rendering . I set "Master and Grunt" on Fedora 12

and "Grunt" on XP. You can set the limit of memory space .

On second tab "local grunt"  you need to set the PATH of blender ( on Fedora is /usr/bin/blender.bin) .

The same settings must be set in Windows XP. The other settings are for advanced users.

render farm

How to add job on Loki software ?

First click on "Jobs"  - >  "New"  ( Ctr + N keys) . This will be open a new window.

render farm

Press "Browser" button to add your blend file. The result will be on "Output Directory".

You can set "First Frame" and "Last Frame". The result will be set of images from first on last frame.

This is a screenshot of Loki software running:

render farm

The official site : loki-render.berlios.de/index.php/download

Tags: Blender

Posted: 2010-02-12 20:28:15

Write by: Catalin


How to resize images - python script .

Sometimes it is necessary to resize the images. The PIL module is used for image processing.The glob module takes a wildcard and returns the full path of all files and directories matching the wildcard. Here are two scripts that I made. The first is a simple example using a resize after some dimensions. In this case we used size 300x300.

from PIL import Image
import glob, os
size_file = 300,300
for f in glob.glob("*.png"):
    file, ext = os.path.splitext(f)
    img = Image.open(f)
    img.thumbnail(size_file, Image.ANTIALIAS)
    img.save("thumb_" + file, "JPEG"

In the second case I tried to do a resize with proportion preservation.

import glob
import PIL
from PIL import Image
for f in glob.glob("*.jpg"):
    img = Image.open(f)
    dim_percent=(100/float(img.size[0]))
    dim_size=int((float(img.size[1])*float(dim_percent)))
    img = img.resize((100,dim_size),PIL.Image.ANTIALIAS)
    if f[0:2] != "trumb_":
        img.save("trumb_" + f, "JPEG")

In both cases we use a renaming of files by adding the name of "thumb_". Ambele scripturi pot fi modificate asa cum vreti. Aceste scripturi demonstreaza cum sa folosim celor doua module "PIL" si "globe".

Source of tutorial "How to resize images"

Tags: python

Posted: 2010-01-30 17:09:05

Write by: Catalin


Blender and Python - First steps.

On console, you use command ./blender or blender.exe (if you use windows OS).

This is need to see the output of script.

Split your window on two . Click right on bar and select Split Area like on next image.

3D

As we see in the image below, you need to create a new file .

3D

You can use COPY and PASTE to copy some python scripts. You can create NEW scripts, SAVE or EXECUTE SCRIPT.

3D  3D

I create a simple script :

import Blender
import sys 
obj = Blender.Object.Get()
print str(obj)
sys.stdout.flush()

Use keys "ALT+P" to run this script .The result should be this :

3D

This output is from my scene ,because has Camera and Lamp objects.

You can use python script with "Controllers" . You must activate the "Enable Script Links"

3D   3D

This is just a simple tutorial how to use python script with Blender 3D.

You can create more complex scripts.
For example to process topographic data or features of Blender 3D.

Tags: Blender,Python

Posted: 2010-01-09 16:54:55

Write by: Catalin


Geany and regular expressions.

As we see in the image below, Geany uses regular expressions to modify the source code.

I used regular expression: ["\# >>>"]*(.*) to replace the # >>> with nothing.

regular expresion

More about regular expresions on >Wikipedia

Tags: Editor

Posted: 2010-01-09 12:55:50

Write by: Catalin


Linux , C and GTK

The best way to start learning a programming language is by writing a program.
How edit and compile the program ?
That depends on the compiler you are using.
First of all you should write a simple program using C language.
This is a simple program:

#include <gtk/gtk.h>
#include <string.h>


int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show (window);
    gtk_main ();
    return 0;
}


Now about the compilers:
gcc is the "GNU" C Compiler
g++ is the "GNU C++ compiler
cc  is the "Sun" C Compiler
CC is the "Sun" C++ compiler

I will use gcc because is a C program.
When it contains Xlib graphics routines the command is :
gcc myprogramc -o myprogram -lX11
( see -l = link and X11 is Xlib).
What is pkg-config ?
This is a helper tool .
It helps you insert the correct compiler options on the command line.
Your application can use  something like this :
gcc -o test test.c `pkg-config --libs --cflags glib-2.0`.
How it works ?
When a library is installed a .pc file should be included.
This file tells us that libraries can be found in /usr/local/lib and headers in /usr/local/include.
But first of all you must install the libs .
On my example i need this gtk2-devel.i686, so i use :
yum search gtk2-devel
Loaded plugins: presto, refresh-packagekit
============= Matched: gtk2-devel =================
gtk2-devel.i686 : Development files for GTK+

And i compile with this :
$gcc `pkg-config --cflags --libs gtk+-2.0` -o app app.c
  And result is:
gtk tutorial

Tags: GTK

Posted: 2010-01-09 11:57:04

Write by: Catalin


Blender < 2.5 and MakeHuman - not finish

For this we need two softwares Blender 3d and Makehuman.
The first step will open "makehuman" determines his character and settings (see image below):

mh
Then saves the object collada. In this case "name_of_file":

mh_col

The next step will load the object through the blender scripts. More specifically through File -> Import -> COLLADA 1.4.
3D


The script will run and we will select these settings:

3D

We will choose the path where we makehuman saved file (see "mesh.dae") and the result will be:

3D

The script automatically insert more scenes.

3D
Select the row to see where is our character.
We will remove this scene with this button.

3D

And rename with "CG_Girl" like on this image:

3D

Now, we set the object so that we more easily.
First we separate the object depending on the materials.

3D
Select all object from collada with key "A" and use key "Tab" to select "Edit Mode".

Now select all with see this :

3D

Use key "P" ( on "Edit Mode") and you see Separate feature. Select "By Material" .

If you change on from "3D View" to "Outliner" will see this :

3D

We apply a few small settings for the object to look better and easier to handle.

Use key "Tab" to change it on "Object Mode". Than use key "A" to select all object:

Use this settings "Set Smoth" and "Double Sided" like on this images.

3D

3D

The result is much better.

3D

Because our subject has a skeletal. We move in different layer.

On "Object Mode" select the head mesh. Now use the key "M" and select the layer.

3D

We will do the same for others meshs.

3D    3D

3D3D

Now select layer where we moved and we find that our model has no eyes. 3D   Now select layer where we moved and we find that our model has no eyes.
We will do the following trick. Get back to the skeleton layer, then select the mesh eye (is two). 3D
Use the keys "Ctr + D to duplicate.
Press "M" and moving them on the other layer. 3D If you move on the second layer you will see the result: 3D

You have to put the teeth, tongue and skeletal in a Vertex Group.
In Object Mode select them all using the key combination of keys Shift.Use Ctr + J to create a single object. See next picture.

3D

We call this selection "skelet", see picture.

3D
Outliner show the new name "skelet".

3D

To create an animation should take the following steps:
1. Rename each bone;
2. To give the same names for each Vertex Group of each bone. If the head bone is called "head" then Vertex Group will be called "head";
3. Armature to assign to the object;
4. To establish the character moves.
How make this ? Follow the next steps.

1. Rename each bone with your options .

Select "Armature" and use Edit Mode to select each bone. Select   bone of skull .

3D

Rename this on Armature Bones tabs (see BO:head from image):

3D

We will do the same for each bone.

2. We will do the same for each bone.
It will be called "head". Select one vertex with right click in Edit Mode and then press Alt + L. In the next picture you can see the result of selection.

Select the entire head with skull, tongue, eye.
3D

In the tab "Link and Materials" create a new Vertex Group called "head" and click Assign.

We will do the same for the neck and other parts of the body.

3D

See the tab on the right "Modifiers" but this is the next step .

3D

3. Armature to assign to the object;

The next picture shows us how to add modifier. Write on Ob: the name of armature . In this case "Armature"

3D

This tutorial is under construction and will not be finish in the future because is a new Blender in town .

Tags: Blender

Posted: 2009-11-09 17:22:06

Write by: Catalin


Simple effect in Blender 3D: Depth of Field (DOF)

www.free-tutorials.org

The concept of DOF (depth-of-field)  is to use information about Z values, and use it to blur objects.

The more out of depth they are, the more they are blurred. This is a simple example :

I used a cube. Then I multiplied by the modifier array.
It can use other objects. I selected "Node Editor.
I enabled "Composite Node", see image below:

www.free-tutorials.org

Add and these "converter-> Color Ramp.
Then add the Add-> Filter-> Blur "and" Add-> Vector-> Map Value ".
Then connect them this way.

I marked in red areas to be modified with numbers from 1 to 3.
Change the numbers 1 and 2 so you get a result of the final image (see 3).

As you can see "Color Ramp" is directly linked with the "Composite".

3D

Do it again , but like  the picture below:

www.free-tutorials.org

The result will be that:

www.free-tutorials.org

Tags: Blender

Posted: 2009-10-11 15:07:52

Write by: Catalin


How to change "Paragraph Style: Heading" in OpenOffice.

Sometimes the use of copy and paste results in loading the document with a "heading" inappropriate.
We have two way solving this problem. We may use the button in the image below:

www.free-tutorials.org

It opens the following window. Use right click and have two options:

www.free-tutorials.org

Now , use "Modify..." . The next frame is :

www.free-tutorials.org

I change the font from "Liberation Sans " in "URW Chancery L". See old "Paragraph Style: Heading 3":

www.free-tutorials.org

Now the entire document will change automatically. It is useful when we want to reduce the size of a document.

www.free-tutorials.org

Another method is to use right click on the text and then modify its properties:

www.free-tutorials.org

Now the settings window will appear "Paragraph Style: Heading 3".

Please make all changes and click "ok" button .

Tags: openoffice

Posted: 2009-10-09 15:09:24

Write by: Catalin


Set default template on OpenOffice Writer

Create default template and edit old template

First you need to have OpenOffice. To create a default template should follow the following steps:

file_new_ooo

template_save

rename_templ

t4

t3

t5

Tags: openoffice

Posted: 2009-09-02 15:22:03

Write by: Catalin


Yumex on Fedora

Yumex - best GUI to install packages on Fedora

You need to use this commands to start "yumex":

[mypc@home ~]$ su
Password:
[root@home mypc]# yumex

On this image you see Yumex GUI and how install packages

yumex install

Tags: Linux

Posted: 2009-07-30 15:15:01

Write by: Catalin


Assign keys on Linux

Setting special keys on linux !

I use "Fedora 9". Use "System" -> "Preferences" -> "Personal" -> "Keyboard Shortcuts" .

key_assign

You will see this dialog :

key_assign2

You have this options:

"Sound", "Desktop", "Window Manager"

I select "Desktop" for example :

key_assign3

How configure one key ?

Use left click mouse button on old key from right .

See on next picture "New shortcut..." and now press the key you want to assign.

key_assign

This is all i want to show !

 

Tags: Linux

Posted: 2009-07-24 14:17:45

Write by: Catalin


Python - simple language scripting.

The official site www.python.org say :

Python is a dynamic object-oriented programming language that can be used for many kinds of software development.

It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days.

Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code. http://www.python.org/

How is python ?

Next you see some few python script code:

import os
import sys
from os import *
print "Hello !"

The output is :

Hello

Is pretty simple .

More usefull scriptyou see on this site: python-catalin.blogspot.com .

On this site pygame-catalin.blogspot.com you see some many scrips with pygme module. Now the python logo is this:

 

Tags: python

Posted: 2009-07-23 15:16:27

Write by: Catalin


Valid HTML 4.01 Transitional Valid CSS!

© 2006 Catalin Festila. All Rights Reserved.