2011年6月30日星期四

Stay Hungary. Stay Foolish~


"Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: “Stay Hungry. Stay Foolish.” It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.

Stay Hungry. Stay Foolish.

Thank you all very much."

- from Steve Jobs’ 2005 Stanford Commencement Address


虽然我是一個Android人, 但不知不覺間竟被敎主折服了~
而且要做到Stay Hungry, Stay Foolish 真係一點都不易~~
共勉之~

2011年6月17日星期五

3D rendering Engine - Irrlicht (Part 1)

These days I would like to start a new journey for game development - 3D engine: Irrlicht.
So, we need to setup an IDE for the following game dev. Here is the setup guide. We base on Eclipse IDE for C/C++.

1. Using mingw32 gcc compilier.
- Download the installer at (http://sourceforge.net/projects/mingw/) and install it.
- Set the environment variable "PATH" with "C:\MinGW\bin\;" and "C:\MinGW\libexec\gcc\mingw32\3.4.5\. The version number for the latter path should be the most update one, for e.g. if you download 4.2.3, the path should be C:\MinGW\libexec\gcc\mingw32\4.2.3.

2. Download and install Eclipse C/C++ developers IDE. http://www.eclipse.org/downloads/
3. Download Irrlicht SDK and extract whereever you want locally. The latest release is 1.7.2 : http://downloads.sourceforge.net/irrlicht/irrlicht-1.7.2.zip.

4. Build a 3D demo
To create an irrlicht-ready project in eclipse:
- create a new C++ project and name it: File > New > C++ Project (to have it setup folders and a source file for you choose: Executable > Hello World C++ Project)
- go to: Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Directories
- add the irrlicht inlude path: C:\irrlicht\irrlicht-1.4\include
- go to: Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Libraries
- add "C:\irrlicht\irrlicht-1.4\lib\Win32-gcc" to the Library search paths
- add "Irrlicht" to the Libraries (this will point to the gcc library file "libIrrlicht.a")
- copy Irrlicht.dll from C:\irrlicht\irrlicht-1.4\bin\Win32-gcc\ to same dir as your project exe (e.g. ...\workspace\project\debug\)

5. Paste in some irrlicht sample code "main.c" (e.g. ..\irrlicht-1.7.2\examples\01.HelloWorld) but comment out the #pragma comment(lib, "Irrlicht.lib") line. GCC doesn't like it for some reason and the irrlicht library is already set to be linked.

6. Select Project > Build Project.

7. Finally, select Run > Run.
The snapshot shown below is the first helloWorld demo from Irrlicht SDK's example package.

2011年6月3日星期五

My first Android demo apps! OpenGL demo!

I just built an Open GL apps for demonstrating the use of graphics display on Android. My device is HTC Desire. Both screenshot and code snippet are attached here. I'm going to post further dev. code snippets and reviews afterwards. Enjoy!


package com.example.cubeOpenGL;

import android.app.Activity;
import android.os.Bundle;
//package com.example.android.apis.graphics;

import android.content.Context;
import android.graphics.*;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.*;
import android.view.*;

public class androidCubeActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}

private static class SampleView extends View {
private ShapeDrawable[] mDrawables;

private static Shader makeSweep() {
return new SweepGradient(150, 25,
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFF0000 },
null);
}

private static Shader makeLinear() {
return new LinearGradient(0, 0, 50, 50,
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF },
null, Shader.TileMode.MIRROR);
}

private static Shader makeTiling() {
int[] pixels = new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0};
Bitmap bm = Bitmap.createBitmap(pixels, 2, 2,
Bitmap.Config.ARGB_8888);

return new BitmapShader(bm, Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
}

private static class MyShapeDrawable extends ShapeDrawable {
private Paint mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);

public MyShapeDrawable(Shape s) {
super(s);
mStrokePaint.setStyle(Paint.Style.STROKE);
}

public Paint getStrokePaint() {
return mStrokePaint;
}

@Override protected void onDraw(Shape s, Canvas c, Paint p) {
s.draw(c, p);
s.draw(c, mStrokePaint);
}
}

public SampleView(Context context) {
super(context);
setFocusable(true);

float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
RectF inset = new RectF(6, 6, 6, 6);
float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };

Path path = new Path();
path.moveTo(50, 0);
path.lineTo(0, 50);
path.lineTo(50, 100);
path.lineTo(100, 50);
path.close();

mDrawables = new ShapeDrawable[7];
mDrawables[0] = new ShapeDrawable(new RectShape());
mDrawables[1] = new ShapeDrawable(new OvalShape());
mDrawables[2] = new ShapeDrawable(new RoundRectShape(outerR, null,
null));
mDrawables[3] = new ShapeDrawable(new RoundRectShape(outerR, inset,
null));
mDrawables[4] = new ShapeDrawable(new RoundRectShape(outerR, inset,
innerR));
mDrawables[5] = new ShapeDrawable(new PathShape(path, 100, 100));
mDrawables[6] = new MyShapeDrawable(new ArcShape(45, -270));

mDrawables[0].getPaint().setColor(0xFFFF0000);
mDrawables[1].getPaint().setColor(0xFF00FF00);
mDrawables[2].getPaint().setColor(0xFF0000FF);
mDrawables[3].getPaint().setShader(makeSweep());
mDrawables[4].getPaint().setShader(makeLinear());
mDrawables[5].getPaint().setShader(makeTiling());
mDrawables[6].getPaint().setColor(0x88FF8844);

PathEffect pe = new DiscretePathEffect(10, 4);
PathEffect pe2 = new CornerPathEffect(4);
mDrawables[3].getPaint().setPathEffect(
new ComposePathEffect(pe2, pe));

MyShapeDrawable msd = (MyShapeDrawable)mDrawables[6];
msd.getStrokePaint().setStrokeWidth(4);
}

@Override protected void onDraw(Canvas canvas) {

int x = 10;
int y = 10;
int width = 300;
int height = 50;

for (Drawable dr : mDrawables) {
dr.setBounds(x, y, x + width, y + height);
dr.draw(canvas);
y += height + 5;
}
}
}
}