<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PKSoftware Blog</title>
	<atom:link href="http://pksoftware.de/software-blog/feed" rel="self" type="application/rss+xml" />
	<link>http://pksoftware.de/software-blog</link>
	<description>Artikel und Tutorials über praktische Software Entwicklung</description>
	<lastBuildDate>Tue, 08 May 2012 18:22:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Global JavaScript function for confirmation dialogs with Twitter Bootstrap</title>
		<link>http://pksoftware.de/software-blog/articles/global-javascript-function-for-confirmation-dialogs-with-twitter-bootstrap</link>
		<comments>http://pksoftware.de/software-blog/articles/global-javascript-function-for-confirmation-dialogs-with-twitter-bootstrap#comments</comments>
		<pubDate>Tue, 08 May 2012 12:06:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML(5) & WebGL]]></category>
		<category><![CDATA[JavaScript & JQuery]]></category>

		<guid isPermaLink="false">http://pksoftware.de/software-blog/?p=102</guid>
		<description><![CDATA[Creating a default Twitter Bootstrap modal dialog is very easy. Just add the markup for a modal to your document and set the trigger element: Modal markup &#60;div class="modal hide fade" id="myModal"&#62; &#60;div class="modal-header"&#62; &#60;button class="close" data-dismiss="modal"&#62;×&#60;/button&#62; &#60;h3&#62;Modal header&#60;/h3&#62; &#60;/div&#62; &#8230; <a href="http://pksoftware.de/software-blog/articles/global-javascript-function-for-confirmation-dialogs-with-twitter-bootstrap">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Creating a default Twitter Bootstrap modal dialog is very easy. Just add the markup for a modal to your document and set the trigger element:
</p>
<h4>Modal markup</h4>
<pre class="prettyprint">
&lt;div class="modal hide fade" id="myModal"&gt;
    &lt;div class="modal-header"&gt;
        &lt;button class="close" data-dismiss="modal"&gt;×&lt;/button&gt;
        &lt;h3&gt;Modal header&lt;/h3&gt;
    &lt;/div&gt;
    &lt;div class="modal-body"&gt;
        &lt;p&gt;One fine body…&lt;/p&gt;
    &lt;/div&gt;
    &lt;div class="modal-footer"&gt;
        &lt;a href="#" class="btn"&gt;Close&lt;/a&gt;
        &lt;a href="#" class="btn btn-primary"&gt;Save changes&lt;/a&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre>
<h4>Trigger</h4>
<pre class="prettyprint">
&lt;a class="btn" data-toggle="modal" href="#myModal" &gt;Launch Modal&lt;/a&gt;
</pre>
<p>If you click now the trigger element, the modal will show. This is very useful for creating confirmation dialogs, e.g. if you want to protect delete actions against accidental clicks. Since you may need confirmation dialogs on different places on your site, it&#8217;s useful to put it into a global JavaScript file:</p>
<pre class="prettyprint">
var MyDialogs={
    loadConfirmationModal:function(modalId, confirmURL, caption, body){
			var $modal=jQuery('#'+modalId);
			if($modal.size() === 0){

				var modalString='&lt;div id="'+modalId+'" class="modal hide fade"&gt;'+
					'&lt;div class="modal-header"&gt;'+
						'&lt;button class="close" data-dismiss="modal"&gt;×&lt;/button&gt;'+
						'&lt;h3&gt;'+caption+'&lt;/h3&gt;'+
					'&lt;/div&gt;'+
					'&lt;div class="modal-body"&gt;'+body+
						'&lt;/div&gt;'+
						'&lt;div class="modal-footer"&gt;'+
							'&lt;button id="cancel" class="btn" data-dismiss="modal" type="button" name="cancel"&gt;Cancel&lt;/button&gt;'+
							'&lt;a id="submit" class="btn btn-danger" href="'+confirmURL+'"&gt;Delete&lt;/a&gt;'+
						'&lt;/div&gt;'+
				'&lt;/div&gt;';

				$modal=jQuery(modalString);

			}

			$modal.modal('show');
                        return false;
		}

};
</pre>
<p>
Consider that you have a link on your site that is ought to delete a post or similar. The link has an URL like <i>http://somedomain.com/post/5/delete</i>. Without confirmation, it would look like this:
</p>
<pre class="prettyprint">
    &lt;a class="btn" href="http://somedomain.com/post/5/delete"&gt;delete&lt;/a&gt;
</pre>
<p>
To use a confirmation dialog, you just need to add the following:
</p>
<pre class="prettyprint">
    &lt;a class="btn" href="#" onclick="return MyDialogs.loadConfirmationModal('my_modal_id', 'http://somedomain.com/post/5/delete', 'This is the caption of the confirmation dialog', 'This is the text of the confirmation dialog');"&gt;delete&lt;/a&gt;
</pre>
<p>
Without adding the markup to each single page, you can use confirmation modal dialogs everywhere on your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://pksoftware.de/software-blog/articles/global-javascript-function-for-confirmation-dialogs-with-twitter-bootstrap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Twitter Bootstrap together with Zend Forms</title>
		<link>http://pksoftware.de/software-blog/articles/using-twitter-bootstrap-together-with-zend-forms</link>
		<comments>http://pksoftware.de/software-blog/articles/using-twitter-bootstrap-together-with-zend-forms#comments</comments>
		<pubDate>Tue, 08 May 2012 11:14:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Zend Framework & PHP]]></category>

		<guid isPermaLink="false">http://pksoftware.de/software-blog/?p=94</guid>
		<description><![CDATA[Using Twitter Bootstrap is rather straightforward: you don&#8217;t need to do more than adding the css and js files to your HTML document, and pasting the markup of its components. It also works pretty well with the Zend Framework, except &#8230; <a href="http://pksoftware.de/software-blog/articles/using-twitter-bootstrap-together-with-zend-forms">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Using Twitter Bootstrap is rather straightforward: you don&#8217;t need to do more than adding the css and js files to your HTML document, and pasting the markup of its components. It also works pretty well with the Zend Framework, except when using the Zend Form engine.
</p>
<p>
Zend Forms create an own markup when they are rendered &#8211; and the default markup that is created by Zend Forms is not compatible with the Twitter Boostrap markup for forms. Zend Forms is using so-called decorators to define the markup of the form, finally decorators describe how the form elements are rendered. There are many standard decorators shipped with Zend &#8211; and there are plenty ways to customize them to make them more and less compatible with the Bootrap markup.
</p>
<p>
After trying around with the standard decorators, i realized that especially the nesting of elements inside forms, like error messages, descriptions and labels, create trouble. That&#8217;s why i decided to create an own decorator for Zend Form to use with Twitter Bootstrap.
</p>
<ol>
<li>Create a new PHP file called <i>Bootstrap.php</i> at <i>/application/forms/decorator/</i></li>
<li>Paste the code below into the new file</li>
<li>Add the decorator to your form definition inside the Zend Form class</li>
</ol>
<h4>Bootstrap.php</h4>
<pre class="prettyprint">
&lt;?php
    class Application_Form_Decorator_Bootstrap extends Zend_Form_Decorator_Abstract
    {
    public function buildLabel()
    {
        $element = $this-&gt;getElement();
        $label = $element-&gt;getLabel();
        if ($translator = $element-&gt;getTranslator()) {
            $label = $translator-&gt;translate($label);
        }
        if ($element-&gt;isRequired()) {
       //     $label .= '*';
        }
       // $label .= ':';
        return $element-&gt;getView()
                       -&gt;formLabel($element-&gt;getName(), $label, array('class'=&gt;'control-label'));
    }

    public function buildInput()
    {
        $element = $this-&gt;getElement();
        $helper  = $element-&gt;helper;
        return $element-&gt;getView()-&gt;$helper(
            $element-&gt;getName(),
            $element-&gt;getValue(),
            $element-&gt;getAttribs(),
            $element-&gt;options
        );
    }

    public function buildErrors()
    {
        $element  = $this-&gt;getElement();
        $messages = $element-&gt;getMessages();
        if (empty($messages)) {
            return '';
        }var_dump($messages);
        return '&lt;div class="help-block"&gt;' .
               $element-&gt;getView()-&gt;formErrors($messages) . '&lt;/div&gt;';
    }

    public function buildDescription()
    {
        $element = $this-&gt;getElement();
        $desc    = $element-&gt;getDescription();
        if (empty($desc)) {
            return '';
        }
        return '&lt;div class="help-block"&gt;' . $desc . '&lt;/div&gt;';
    }

    	public function render($content)
        {
        	$element  = $this-&gt;getElement();

        	if (!$element instanceof Zend_Form_Element) {
	            return $content;
	        }
	        if (null === $element-&gt;getView()) {
	            return $content;
	        }

	        $separator = $this-&gt;getSeparator();
	        $placement = $this-&gt;getPlacement();
	        $label     = $this-&gt;buildLabel();
	        $input     = $this-&gt;buildInput();
	        $errors    = $this-&gt;buildErrors();
	        $desc      = $this-&gt;buildDescription(); 

        	$messages = $element-&gt;getMessages();

        	$elementClasses='control-group';
	        if(!empty($messages)){
	        	$elementClasses.=' error';
	        }
        	return '&lt;div class="'.$elementClasses.'"&gt;'.$label.'&lt;div class="controls"&gt;'.$input.$desc.$errors.'&lt;/div&gt;&lt;/div&gt;';
        }
    }
 ?&gt;
</pre>
<p>
Using the custom decorator inside a Zend form could look like this:
</p>
<h4>MyForm.php</h4>
<pre class="prettyprint">
&lt;?php
class Application_Form_MyForm extends Zend_Form
{
    public function init()
    {
    	$this-&gt;setAttrib('class', 'form-inline');
$this-&gt;addElement('text', 'username', array(
            'filters'    =&gt; array('StringTrim', 'StringToLower'),
            'validators' =&gt; array(
                'Alpha',
                array('StringLength', false, array(3, 20)),
            ),
            'required'   =&gt; true,
            'placeholder'=&gt; 'Username',
            'decorators' =&gt; array( new Application_Form_Decorator_Bootstrap() ),
        ));

        $this-&gt;addElement('password', 'password', array(
            'filters'    =&gt; array('StringTrim'),
            'validators' =&gt; array(
                'Alnum',
                array('StringLength', false, array(6, 20)),
            ),
            'required'   =&gt; true,
            'placeholder'=&gt; 'Password',
            'decorators' =&gt; array( new Application_Form_Decorator_Bootstrap() ),
        ));

        //Submit Button
        $submit = new Zend_Form_Element_Button('submit');
		$submit -&gt;setlabel('Anmelden')
         		-&gt;setAttrib('type', 'submit')
         		-&gt;setAttrib('class', 'btn btn-primary');
		// buttons do not need labels
		$submit-&gt;setDecorators(array(
   			array('ViewHelper'),
   			array('Description'),
   			array('HtmlTag', array('tag' =&gt; 'div', 'class'=&gt;'control-group')),
		));

		$this-&gt;addElement($submit);

		$this-&gt;addDisplayGroup(array('username', 'password', 'submit'), 'groups',
								array("legend" =&gt; "LOGIN",

								"decorators" =&gt; array('FormElements',  'Fieldset')

								));

        // We want to display a 'failed authentication' message if necessary;
        // we'll do that with the form 'description', so we need to add that
        // decorator.
        $this-&gt;setDecorators(array(
            'FormElements',
             array('Description', array('placement' =&gt; 'prepend')),

            'Form'
        ));

    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://pksoftware.de/software-blog/articles/using-twitter-bootstrap-together-with-zend-forms/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Star Wars like opening crawl text with WebGL and Three.js</title>
		<link>http://pksoftware.de/software-blog/articles/star-wars-like-opening-crawl-text-with-webgl-and-three-js</link>
		<comments>http://pksoftware.de/software-blog/articles/star-wars-like-opening-crawl-text-with-webgl-and-three-js#comments</comments>
		<pubDate>Sun, 04 Mar 2012 08:51:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML(5) & WebGL]]></category>

		<guid isPermaLink="false">http://pksoftware.de/software-blog/?p=85</guid>
		<description><![CDATA[This example also shows you how to render longer text in WebGL. Therefore you simply need to split the text into single lines and add it into a container. First add the requireds scripts to your document: &#60;script src="jquery-1.4.2.min.js"&#62;&#60;/script&#62; &#60;script &#8230; <a href="http://pksoftware.de/software-blog/articles/star-wars-like-opening-crawl-text-with-webgl-and-three-js">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This example also shows you how to render longer text in WebGL. Therefore you simply need to split the text into single lines and add it into a container.</p>
<p>First add the requireds scripts to your document:</p>
<pre class="prettyprint">&lt;script src="jquery-1.4.2.min.js"&gt;&lt;/script&gt;
&lt;script src="Three.js"&gt;&lt;/script&gt;
&lt;script src="helvetiker_regular.typeface.js"&gt;&lt;/script&gt;</pre>
<pre class="prettyprint">var texts = null;
var container;

var camera, scene, renderer;

var text, plane;

textOffsetY=-190;
var maxLineLength = 32;

var canvasWidth = window.innerWidth;
var canvasHeight = window.innerHeight;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var textMaterial;
var nr = 0;

jQuery.ajax({
    url: 'text.txt',
    success: function(result){
       texts = loadText(result);
       init();
       animate();
    }
});

function init(){
                container = document.createElement('div');
                document.getElementById('canvas_container').appendChild(container);

                camera = new THREE.PerspectiveCamera(32, canvasWidth / canvasHeight, 0.1, 1500);
                camera.position.y = 0;
                camera.position.z = 550;

                scene = new THREE.Scene();

                textMaterial = new THREE.MeshBasicMaterial({
                    color: 0x8A6F17,
                    overdraw: true
                });

                var worldImage=     new THREE.MeshLambertMaterial({
                       map: THREE.ImageUtils.loadTexture("./symbol.png")
                });

                var cube = new THREE.Mesh(new THREE.CubeGeometry(120, 120, 0.1), worldImage);
                cube.overdraw = true;

                parent = new THREE.Object3D();
                for (var i = 0; i &lt; texts.length; i++) {
                    addTextLine(parent, texts[i], textOffsetY);
                }
                cube.position.y = textOffsetY - nr * 24 - 60
                parent.add(cube);

                parent.rotation.x = -Math.PI / 3;
                parent.position.y = 0;
                scene.add(parent);
                var ambientLight = new THREE.AmbientLight(0x555555);
                scene.add(ambientLight);

                // add directional light source
                var directionalLight = new THREE.DirectionalLight(0xffffff);
                directionalLight.position.set(1, 1, 1).normalize();
                scene.add(directionalLight);
                renderer = new THREE.WebGLRenderer({
                    antialias: true
                });
                renderer.setSize(canvasWidth, canvasHeight);

                container.appendChild(renderer.domElement);
            }

            function loadText(source){
                var texts = new Array();
                source = source.replace("n", " n ");
                var words = source.split(' ');
                var i = 0;
                var currentLine = '';

                while (words.length &gt; 0) {
                    if (currentLine.length &lt; maxLineLength) {
                        var theWord = words.shift();
                        if (theWord == "n") {
                            if (currentLine != '')
                                texts.push(currentLine);
                            currentLine = '';
                            texts.push('');
                        }
                        else
                            currentLine += ('' !== currentLine ? ' ' : '') + theWord.trim();
                    }
                    else {
                        texts.push(currentLine);
                        currentLine = '';
                    }
                }
                if (currentLine != '')
                    texts.push(currentLine);
                return texts;
            }

            function addTextLine(parent, textLine, offset){
                if (textLine == '') {
                    nr++;
                    return;
                }
                var text3d = new THREE.TextGeometry(textLine, {

                    size: 12,
                    height: 1,
                    curveSegments: 2,
                    font: "helvetiker"

                });

                text3d.computeBoundingBox();
                var centerOffset = -0.5 * (text3d.boundingBox.max.x - text3d.boundingBox.min.x);

                var text = new THREE.Mesh(text3d, textMaterial);

                text.doubleSided = false;

                text.position.x = centerOffset;
                text.position.y = offset - nr * 24;
                text.position.z = 0;

                text.rotation.x = 0; //0;
                text.rotation.y = Math.PI * 2;
                text.rotation.z = 0; //Math.PI / 2;
                parent.add(text);
                nr++;
            }

            function animate(){
                requestAnimationFrame(animate);
                render();
            }

            function render(){
                parent.position.y += 0.073;
                parent.position.z -= 0.125;
                renderer.render(scene, camera);
            }</pre>
<p><iframe src="http://pksoftware.de/wordpress/wp-content/themes/pksoftware/js/articles/webgl_outro/webgl_outro.html" width="640" height="480"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://pksoftware.de/software-blog/articles/star-wars-like-opening-crawl-text-with-webgl-and-three-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple faders and slideshow instances with JQuery and mf__multifader</title>
		<link>http://pksoftware.de/software-blog/articles/multiple-faders-and-slideshow-instances-with-jquery-and-mf__multifader</link>
		<comments>http://pksoftware.de/software-blog/articles/multiple-faders-and-slideshow-instances-with-jquery-and-mf__multifader#comments</comments>
		<pubDate>Sat, 10 Dec 2011 14:47:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript & JQuery]]></category>

		<guid isPermaLink="false">http://pksoftware.de/software-blog/?p=69</guid>
		<description><![CDATA[Download mf__multifader Now include JQuery 1.4.2+ and the mf__multifader JavaScript and CSS to the &#60;head&#62; section of your HTML page. &#60;script type="text/JavaScript" src="jquery-1.4.2.min.js"&#62;&#60;/script&#62; &#60;script type="text/JavaScript" src="mf__multifader_1_0.js"&#62;&#60;/script&#62; &#60;link rel="stylesheet" href="mf__multifader.css" type="text/css" /&#62; Add some faders to the &#60;body&#62; section of your &#8230; <a href="http://pksoftware.de/software-blog/articles/multiple-faders-and-slideshow-instances-with-jquery-and-mf__multifader">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
<a href="www.pksoftware.de/software/mf__multifader">Download mf__multifader</a>
</p>
<p>
Now include JQuery 1.4.2+ and the mf__multifader JavaScript and CSS to the &lt;head&gt;<br />
section of your HTML page.
</p>
<pre class="prettyprint">
&lt;script type="text/JavaScript" src="jquery-1.4.2.min.js"&gt;&lt;/script&gt;
&lt;script type="text/JavaScript" src="mf__multifader_1_0.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="mf__multifader.css" type="text/css" /&gt;
</pre>
<p>
Add some faders to the &lt;body&gt; section of your HTML page. Each fader<br />
must be a div of the CSS class mf__fader and must contain at least one<br />
div of CSS class mf__frame. Finally add a div of class mf__controls if you<br />
want to use controls in the fader instance.
</p>
<pre class="prettyprint">
&lt;div id="any_fader_id_1" class="mf__fader"&gt;
    &lt;div class="mf__frame frame_1"&gt;&lt;div&gt;Fader 1 Frame 1&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__frame frame_2"&gt;&lt;div&gt;Fader 1 Frame 2&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__frame frame_3"&gt;&lt;div&gt;Fader 1 Frame 3&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__frame frame_4"&gt;&lt;div&gt;Fader 1 Frame 4&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__controls"&gt;&lt;/div&gt;
&lt;/div&gt;

........

&lt;div id="any_fader_id_6" class="mf__fader"&gt;
    &lt;div class="mf__frame frame_1"&gt;&lt;div&gt;Fader 4 Frame 1&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__frame frame_2"&gt;&lt;div&gt;Fader 4 Frame 2&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__frame frame_3"&gt;&lt;div&gt;Fader 4 Frame 3&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__frame frame_4"&gt;&lt;div&gt;Fader 4 Frame 4&lt;/div&gt;&lt;/div&gt;
    &lt;div class="mf__controls"&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Initialise the faders:</p>
<pre class="prettyprint">
jQuery(document).ready(function() {
    var fader1=mf__create_fader('any_fader_id_1', 8500, 500, true, true);
    fader1.init();
    fader1.startStop();
    mf__create_fader('any_fader_id_2', 2500, 600, true, true).init();
    mf__create_fader('any_fader_id_3', 6500, 350, false, false).init();
    mf__create_fader('any_fader_id_4', 3000, 900, false, false).init();
    mf__create_fader('any_fader_id_5', 500, 200, true, false).init();
    mf__create_fader('any_fader_id_6', 1000, 100, false, false).init();
});</pre>
<p>This is how it looks:</p>
<p><iframe src="http://pksoftware.de/wordpress/wp-content/themes/pksoftware/js/articles/mf__multifader/mf__multifader_demo.html" width="100%" height="560"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://pksoftware.de/software-blog/articles/multiple-faders-and-slideshow-instances-with-jquery-and-mf__multifader/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Einführung in die WebGL Programmierung mit Three.js</title>
		<link>http://pksoftware.de/software-blog/articles/webgl-programmierung-mit-three-js</link>
		<comments>http://pksoftware.de/software-blog/articles/webgl-programmierung-mit-three-js#comments</comments>
		<pubDate>Thu, 08 Dec 2011 19:42:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML(5) & WebGL]]></category>

		<guid isPermaLink="false">http://pksoftware.de/software-blog/?p=25</guid>
		<description><![CDATA[Zunächst muss das Three.js Framework von Mr.Doob heruntergeladen werden. Das ca. 64 MB grosse Archiv enthält die JavaScript Libraries, Beispiele, sowie 3D Modelle und Grafiken. Im folgenden Beispiel gehe ich davon aus, dass das Archiv in einen Ordner namens three_js &#8230; <a href="http://pksoftware.de/software-blog/articles/webgl-programmierung-mit-three-js">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Zunächst muss das <a href="https://github.com/mrdoob/three.js/" target="_blank">Three.js Framework</a> von Mr.Doob heruntergeladen werden. Das ca. 64 MB grosse Archiv enthält die JavaScript Libraries, Beispiele, sowie 3D Modelle und Grafiken.
</p>
<p>
Im folgenden Beispiel gehe ich davon aus, dass das Archiv in einen Ordner namens three_js extrahiert wurde.
</p>
<p>
Für das einfache Beispiel müssen nur 2 JavaScript Dateien in den &lt;head&gt; Bereich der HTML Datei einbgebunden werden:
</p>
<pre class="prettyprint">
&lt;script src="three_js/build/Three.js"&gt;&lt;/script&gt;
&lt;script src="three_js/examples/js/RequestAnimationFrame.js"&gt;&lt;/script&gt;
</pre>
<p>Das eigentliche Script zum Erzeugen der 3d Szene muss in den &lt;body&gt; Bereich der HTML Datei eingefügt werden. Wir springen nun direkt in das Skript:</p>
<pre class="prettyprint">&lt;script&gt;
    //Variablen inititalisieren
    var camera, scene, renderer,
    geometry, material, mesh;

    //Daten initialisieren und Animation starten
    init();
    animate();

    function init() {
        //Erzeugen einer Szene. Die Szene ist sozusagen die Bühne die
        //alle dargestellten Elemente enthält
        scene = new THREE.Scene();

        //Erzeugen einer Kamera. Die Kamera sorgt für die perspektivische
        //Darstellung der Szene. Man benötigt mindestens eine Kamera.
        camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.z = 1000;

        //Hinzufügen der Kamera zur Szene
        scene.add( camera );

        //Erzeugung der Gemotrie des Würfels
        geometry = new THREE.CubeGeometry( 200, 200, 200 );
        //Erzeugung des Materials/Oberfläche des Würfels
        material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );

        //Erzeugung des Würfels aus Geometrie und Material
        mesh = new THREE.Mesh( geometry, material );
        //Hinzufügen des Würfels zur Szene
        scene.add( mesh );

        //Erzeugung eines Renderers. Der Renderer produziert letztendlich alles
        //sichtbare. Hier wird ein CanvasRenderer verwendet, der ein canvas element
        //zur Darstellung verwendet.
        renderer = new THREE.CanvasRenderer();
        //Grösse des Renderers auf die Fenstergrösse des Browsers setzen
        renderer.setSize( window.innerWidth, window.innerHeight );

        //Erzeugtes Canvas Element in den body einfügen.
        document.body.appendChild( renderer.domElement );

    }

    function animate() {

        // Include examples/js/RequestAnimationFrame.js for cross-browser compatibility.

        //Wir wollen einen Loop erzeugen, daher rufen wir die Funktion
        //requestAnimationFrame auf. Dadurch wird für jedes Frame erneut die Funktion
        //animate aufgerufen, die dann die Funktion render aufruft.
        requestAnimationFrame( animate );
        render();

    }

    function render() {
        //Wir ändern für jedes Frame die Drehung des Würfels ein wenig
        mesh.rotation.x += 0.01;
        mesh.rotation.y += 0.02;
        //Aktuelle Frame berechnen
        renderer.render( scene, camera );

    }

&lt;/script&gt;</pre>
<p>
Das Script erzeugt einen 3 dimensionalen, sich drehenden Würfel. Wenn Sie diesen Artikel in einem WebGL fähigen browser betrachten, sollten Sie den Würfel in dem blauen Kasten sehen können:
</p>
<div id="webgl_container">
</div>
<script>
    var camera, scene, renderer,
    geometry, material, mesh;

    init();
    animate();

    function init() {

        scene = new THREE.Scene();

        camera = new THREE.PerspectiveCamera( 75, 1, 1, 10000 );
        camera.position.z = 1000;
        scene.add( camera );

        geometry = new THREE.CubeGeometry( 200, 200, 200 );
        material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );

        mesh = new THREE.Mesh( geometry, material );
        scene.add( mesh );

        renderer = new THREE.CanvasRenderer();
        renderer.setSize( 525, 525 );

        document.getElementById('webgl_container').appendChild( renderer.domElement );

    }

    function animate() {

        // Include examples/js/RequestAnimationFrame.js for cross-browser compatibility.
        requestAnimationFrame( animate );
        render();

    }

    function render() {

        mesh.rotation.x += 0.01;
        mesh.rotation.y += 0.02;

        renderer.render( scene, camera );

    }
</script>
]]></content:encoded>
			<wfw:commentRss>http://pksoftware.de/software-blog/articles/webgl-programmierung-mit-three-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Grundgerüst</title>
		<link>http://pksoftware.de/software-blog/articles/html5-grundgerust</link>
		<comments>http://pksoftware.de/software-blog/articles/html5-grundgerust#comments</comments>
		<pubDate>Thu, 08 Dec 2011 19:13:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML(5) & WebGL]]></category>

		<guid isPermaLink="false">http://pksoftware.de/software-blog/?p=14</guid>
		<description><![CDATA[&#60;!doctype html&#62; &#60;html lang="en"&#62; &#60;head&#62; &#60;meta charset="utf-8"&#62; &#60;title&#62;HTML5 Template&#60;/title&#62; &#60;meta name="description" content="Ein einfaches HTML5 Template"&#62; &#60;meta name="author" content="PKSoftware"&#62; &#60;link rel="stylesheet" href="style.css"&#62; &#60;!--[if lt IE 9]&#62; &#60;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&#62;&#60;/script&#62; &#60;![endif]--&#62; &#60;/head&#62; &#60;body&#62; &#60;p&#62;Ein Textparagraph.&#60;/p&#62; &#60;script src="js/script.js"&#62;&#60;/script&#62; &#60;/body&#62; &#60;/html&#62;]]></description>
			<content:encoded><![CDATA[<pre class="prettyprint lang-html">
&lt;!doctype html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8"&gt;
        &lt;title&gt;HTML5 Template&lt;/title&gt;
        &lt;meta name="description" content="Ein einfaches HTML5 Template"&gt;
        &lt;meta name="author" content="PKSoftware"&gt;
        &lt;link rel="stylesheet" href="style.css"&gt;
        &lt;!--[if lt IE 9]&gt;
            &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
        &lt;![endif]--&gt;
    &lt;/head&gt;
    &lt;body&gt;

        &lt;p&gt;Ein Textparagraph.&lt;/p&gt;

        &lt;script src="js/script.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://pksoftware.de/software-blog/articles/html5-grundgerust/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

