Visual Studio 2008 e Irrlicth 3d Motoru Kurulumu

1. Irrlicth in son sürümünü aşağıdaki adresten indiriyoruz.

http://irrlicht.sourceforge.net/downloads.html

2. Zip dosyasını açıyoruz.

3. Irrlicth-x.x/include un altındaki header dosyalarının hepsini C:\Program Files\Microsoft Visual Studio 9.0\VC\include klasörüne kopyal?yoruz.

4.   Visual Studio 2008 de Tool->Options->Project and Solutions->VC++ Directories kısmına aşağıdaki iki satırı ekliyoruz.

…/Irrlicth-x.x/include

…/Irrlicth-x.x/lib/Win32-visualstudio

 

image

 

5. Visual Studio 2008 de Project->Options->Configuration Properties->Linker->Input->Additional Dependecies kısmına aşağıdaki satırı ekliyoruz.

Irrlicht.lib

image

 

6. Yeni bir proje oluşturuyoruz.

 

image

 

7. Irrlicth in header dosyalarını projemizin header kısmına ekliyoruz.

 

image

 

…\irrlicht-x.x\include altındaki bütün dosyaları ekliyoruz.

image

 

8. Source folder ina yeni bir cpp dosyası ekleyip aşağıdaki kodu ekliyoruz.

 

#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
// ask user for driver

video::E_DRIVER_TYPE driverType;

printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");

char i;
std::cin >> i;

switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL;   break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL;     break;
default: return 1;
}

// create device and exit if creation failed

IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(640, 480));

if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addZipFileArchive("C:/Users/Ugur/Desktop/irrlicht-1.6/media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
//              node = smgr->addMeshSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
int lastFPS = -1;

while(device->run())
{
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,200,200,200));
smgr->drawAll();
driver->endScene();

int fps = driver->getFPS();

if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
str += driver->getName();
str += "] FPS:";
str += fps;

device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
device->drop();
return 0;
}

9.  Projeyi build ettiğimz zaman Quake 3 in bir haritası açılacaktır.

image image

 

Uğur Dönmez

METU CENG

Visual Studio 2008 ile Ogre Kullanmak

1. Ogre SDK yi http://www.ogre3d.org/wiki/index.php/Installing_the_Ogre_SDK_on_Windows adresinden indiriyoruz. Ben Installing the Ogre SDK for Visual C++ 2008 & Code::Blocks paketini kurdum.

2. Ogre Application Wizard i http://www.jacmoe.dk/forum/index.php?topic=3.0 adresinden indiriyoruz.

3. Ogre SDK yi C:\OgreSDK altına kuruyoruz. Başka bir yere kurmak sorun çıkarabilir.

4. Ogre SDK ortam değişkeninin varlığını her ihtimale karşı kontrol ediyoruz. Bunun için Bilgisayarım a sağ tğklayğp Gelişmiş tabındaki ortam değişkenlerine tıklıyoruz.

image

 

5. OGRE AppWizard i unzip edip

 

image

 

VC9_Setup u çalıştırıyoruz.

image

 

6. Visual Studio 2008 den yeni proje oluşturuyoruz.

 

 

image

 

Ogre SDK Application u seçiyoruz.

 

image

 

OGRE SDK Application Wizard u takip ediyoruz.

 

image

 

image

 

Finish dedikten sonra örnek projemiz oluşuyor.

image

 

7. Oluşturduğumuz projeyi build ediyoruz.

 

image

 

8. Build ettiğimiz proje OgreSDK/bin/debug klasörünün altında yer almaktadır.

 

image

 

Kaynak : http://www.ogre3d.org

Microsoft Visual Studio 2008 ile OpenGl Kullanmak

Öncelikle gerekli binary dosyaları aşağıdaki adreslerden indiriyoruz.

freeglut 2.4.0

GLUT win32 binaries


Daha sonra indirdiğimiz dosyaları doğru klasörlere yerleştirmemiz gerekiyor.

    freeglut.h i dosyasını ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne ( GL klasörünü yaratmanız gerekmektedir.  )
    freeglut_ext.h dosyasını ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne,
    freeglut_std.h dosyasını ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne,
    freeglut.lib dosyasını ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\’ klasörüne,
    freeglut.dll dosyasını ‘C:\WINDOWS\system32\’ klasörüne,
    glut32.dll dosyasını ‘C:\WINDOWS\system32\’ klasörüne,
    glut32.lib dosyasını‘C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\’ klasörüne,
    glut.h dosyasını ‘C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\’ klasörüne kopyalıyoruz. </LI>

Daha sonra oluşturacağımız C++ projesine freeglut kütüphanesini tanıtmamız gerekiyor.


1. Visual Studio da yeni bir C++ Console Application oluşturuyoruz.




1a. Win32 Application Wizard da ‘Empty Project’ i seçiyoruz.

image




2. Projeye yeni bir cpp dosyası ekliyoruz. İçine aşağıdaki örnek kodu yazıyoruz.



1
2
3
4
5
#include &lt;freeglut.h&gt;
int main ()
{
return 0;
}





3. Debug etmeye çalışırsak Visual Studio hata verecektir çünkü freeglut header dosyalarını projeye henüz tanıtmadık.




3a. Menu bar dan Project->Project Properties i açıyoruz.




3b.  Linker->Input ta Additional Dependencies yazan yere aşagıdaki satırı kopyalıyoruz.




opengl32.lib glu32.lib glut32.lib




image



4. Derlemeye çalışırsak hala hata verebilir çünkü header ve library lerin klasörünü projenin directories ine eklememiz gerekmektedir.




4a. Tools –> Options altındaki Project and Solutions menüsünde VC++ Directories i seçiyoruz.




4b. C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL satırını ekliyoruz.




image




5. Proje artık derlenmektedir.

Eclipse Ogre4j 3d Motoru Kurulumu

1. Eclipsi başlatıp yeni bir java projesi oluşturun. Boş HelloWorld class ı oluşturun.

2. Ogre4j yi aşağıdaki adresten indirin.

http://ogre4j.sourceforge.net/

ogre4j-1.6.2-beta6-bin-win32.tar.bz2 dosyasının inmiş olması gerekmektedir.

3. OGRE yi www.ogre3d.org adresinden indirin. İndirmek için aşağıdaki dosyayı seçin.

downloads -> SDK -> OGRE 1.6.2 SDK for Visual C++ .Net 2005 (8.0) SP1

4. OGRE SDK yi kurun.

5. SWT nin son versiyonunu http://www.eclipse.org/swt/ adresinden indirin. Dosya adı swt-x.x-win32-win32-x86.zip olmalıdı r.

6. http://ogre4j.sourceforge.net/webstart/lib/media.jar dosyasını indirin.

7. dll ve jar dosyalarını ogre4j-1.6.2-beta6-bin-win32.tar.bz2 klasöründe çıkarıp projeniniz root klasörüne ekleyin. (c:\users\ugur\workspace\OgreHelloWorld)

8. OGRE SDK daki dll dosyalarını projenizin root klasörüne ekleyin. (C:\OgreSDK_1.6.2\bin\release\*.dll)

9. Projenizin root klasöründe ‘media’ adlo bir klasör oluşturun. media.jar dosyasının ismini media.zip yapıp içindeki zuh.mesh ve zuh.material dosyalarını oluşturduğunuz media klasörüne kopyalayın.

10. swt.jar dosyasını swt-x.x-win32-win32-x86.zip dosyasından çıkararak projenizin root klasörüne kopyalayın.

11. Eclipse projenizi seçip f5 e basarak klasörlerin yenilenmesini sa?lay?n.

12. Projenize sağ tıklayıp "Build path"->"Configure build path->libraries->Add jars” e gelerek bütün jar dosyalarını ekleyin(swt.jar ve ogre4j.jar).

13. http://ogre4j.svn.sourceforge.net/viewvc/ogre4j/trunk/org.ogre4j.examples.swt/src/org/ogre4j/examples/swt/HelloWorld.java?view=markup linkindeki içeriği HelloWorld classı na ekleyerek çalıştırın.

Java: Scanner nextInt() hasNextInt() Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Vector;

public class ScannerExample {

    public static void main(String[] args) {
        Vector vector = new Vector();
        Scanner scanner;
        try {
            scanner = new Scanner(new File("map.txt"));
            Integer i;
            while (scanner.hasNextInt()) {
                i = scanner.nextInt();
                vector.addElement(i);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("the elements of vector: " + vector);
        System.out.println(vector.size());
    }
}




Java Vector Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Random;
import java.util.Vector;

public class VectorDeneme {

    public static void main(String[] args) {
        Vector vector = new Vector();
        Random generator = new Random();

        int randomInteger;
        for (int i = 0; i < 10; i++) {
            randomInteger = generator.nextInt(100);
            vector.add(randomInteger);
        }

        System.out.println("the elements of vector: " + vector);
        System.out.println("The size of vector are: " + vector.size());
        System.out.println("The elements at position 2 is: " + vector.elementAt(2));
        System.out.println("The first element of vector is: " + vector.firstElement());
        System.out.println("The last element of vector is: " + vector.lastElement());

        vector.removeElementAt(2);
        vector.removeElementAt(8);

        System.out.println("the elements of vector: " + vector);
    }
}

Possible Output:
the elements of vector: [51, 72, 88, 70, 17, 73, 28, 61, 70, 62]
The size of vector are: 10
The elements at position 2 is: 88
The first element of vector is: 51
The last element of vector is: 62
the elements of vector: [51, 72, 70, 17, 73, 28, 61, 70]

Java Deserialization:Reading an Object Stream

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.*;
public class UnserializeBoolean {

    public UnserializeBoolean() {
        Boolean booleanData = null;
        try {
            FileInputStream fis = new FileInputStream("boolean.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            booleanData = (Boolean) ois.readObject();
            ois.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Unserialized boolen from " + "boolean.ser");
        System.out.println("Boolean data: " + booleanData);
        System.out.println("Compare data with true: " + booleanData.equals(new Boolean("true")));
    }
    public static void main(String [] args) {
        UnserializeBoolean uab = new UnserializeBoolean();
    }
}

Java Serialization: Writing an Object Stream

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.io.*;
public class SerializeBoolean {
    public SerializeBoolean() {
        Boolean booleanDAta = new Boolean("true");
        try {
            FileOutputStream fos = new FileOutputStream("boolean.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(booleanDAta);
            oos.close();
        } catch (IOException ie) {
            ie.printStackTrace();
        }
    }
    public static void main(String [] args) {
        SerializeBoolean ab = new SerializeBoolean();
    }
}

Java ReentrantReadWriteLock Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.xml.crypto.Data;

public class ReadWriteMap {
    final Map m = new TreeMap();
    final ReentrantReadWriteLock rw1 = new ReentrantReadWriteLock();
    final Lock r = rw1.readLock();
    final Lock w = rw1.writeLock();

    public Data get(String key) {
        r.lock();
        try {
            return m.get(key);
        } finally  {
            r.unlock();
        }
    }

    public Data put(String key,Data value) {
        w.lock();
        try {
            return m.put(key, value);
        }
        finally {
            w.unlock();
        }
    }

    public void clear() {
        w.lock();
        try {
            m.clear();
        }
        finally {
            w.unlock();
        }
    }
}

Java BlockingQueue Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Producer implements Runnable {
   private final BlockingQueue queue;
   Producer(BlockingQueue q) { queue = q; }
   public void run() {
     try {
       while(true) { queue.put(produce()); }
     } catch (InterruptedException ex) { ... handle ...}
   }
   Object produce() { ... }
 }

 class Consumer implements Runnable {
   private final BlockingQueue queue;
   Consumer(BlockingQueue q) { queue = q; }
   public void run() {
     try {
       while(true) { consume(queue.take()); }
     } catch (InterruptedException ex) { ... handle ...}
   }
   void consume(Object x) { ... }
 }

 class Setup {
   void main() {
     BlockingQueue q = new SomeQueueImplementation();
     Producer p = new Producer(q);
     Consumer c1 = new Consumer(q);
     Consumer c2 = new Consumer(q);
     new Thread(p).start();
     new Thread(c1).start();
     new Thread(c2).start();
   }
 }