8/18/2009

Creating 3d data values for drawing ground


To create 3d data values for drawing ground have to calculate from center (0f, 0f, 0f). The left picture shows the four parts which are divided by center.
Every x and y values are increased and decreased by 1.0 or -1.0 except z values. The increase and decrease values have a same pattern. According many OpenGL examples from Internet, we can draw rectangle with 4 vertex points. Each vertex point has x, y and z value. Therefore, the program has to generate rectangle points’ value. Of course, the generated file has also color values.

int main(int argc, char **argv)
{
int nwidth = atoi(argv[1]);
int nheight = atoi(argv[2]);

fnCVertextFile(nheight, nwidth);
}

Example) program 8 8
When the program was executed like an example, then the vector values will be generated 16 * 16 sizes.

typedef struct {
float x, y, z;
} M3DPoint;

typedef struct {
M3DPoint left, top, right, bottom;
} M3DRect;

// the function writes structure values and string values to file.
void fprintfex(FILE *fvfile, M3DRect row1, char *value)
{
fprintf(fvfile, "%f %f %f %s\n", row1.left.x, row1.left.y, row1.left.z, value);
fprintf(fvfile, "%f %f %f %s\n", row1.top.x, row1.top.y, row1.top.z, value);
fprintf(fvfile, "%f %f %f %s\n", row1.right.x, row1.right.y, row1.right.z, value);
fprintf(fvfile, "%f %f %f %s\n", row1.bottom.x, row1.bottom.y, row1.bottom.z, value);
}

void fnCVertextFile(int aRow, int aColumn)
{
M3DRect row1;

float nleft = 0.0f;
float ntop = 0.0f;

char value1[] = {"0.3 0.3 0.3"};
char value2[] = {"0.5 0.5 0.5"};
char *value;
bool toggle = false;

FILE *fvfile = fopen("vector.dat", "w");
if(fvfile == NULL) {
printf("file cannot open!\n");
exit(-1);
}

// count of vertex
fprintf(fvfile, "%d\n", aRow * aColumn * 4 * 4);

for(int j = 0; j < aRow; j++)
{
for(int i = 0; i < aColumn; i++)
{
row1.left.x = nleft; row1.left.y = ntop; row1.left.z = 1.5f;
row1.top.x = nleft+1.0f; row1.top.y = ntop; row1.top.z = 1.5f;
row1.right.x = nleft+1.0f; row1.right.y = ntop+1.0f; row1.right.z = 1.5f;
row1.bottom.x = nleft; row1.bottom.y = ntop+1.0f; row1.bottom.z = 1.5f;
value = (toggle) ? value1 : value2;
fprintfex(fvfile, row1, value);
toggle = !toggle;
nleft += 1.0f;
}
ntop += 1.0f;
nleft = 0.0f;
toggle = !toggle;
}

// was ommited below section of source

7/02/2009

Now, my second app was included some MIDI sounds.

Until I get Android test device, The second app will be like this.

6/27/2009

Qt4.5.2-tower


Recently, Nokia published the new version of Qt4.5.2-tower which can be operated in many platforms. Previously, I installed the Qt4.5.0-garden for s60 and windows platforms. A couple of days ago, I tried to install S60 5th edition SDK and s60 3rd Feature pack II. I already had N97 0.5 version SDK. The S60 5th edition emulator provided a couple of resolution of mobile screen. So, I uninstalled 3rd edition and N97 edition SDK. Yesterday, I downloaded the Qt4.5.2-tower and I did install process into my old laptop notebook. The install required many things to install the Qt4.5.2-tower. I completed the install process yesterday night due to what I got. I like 2d graphics API. It easily use and so powerful. I am not sure now how an application install into real device. Since I like the emulator and I can launch my testing application into the emulator.

6/21/2009

Qt4.5.0-Garden



For Nokia Application developers, Now They have a little strong development toolkit. ‘Qt4.5.0-garden’ which supports library for s60 mobile makes low a barrier then before. It means S60 mobile application developers can develop application more easy. For me, I was trying to learn about Carbide C++ and S60 library but it gave to me very complex. But Qt garden takes away some complex. To launch an application under S60 emulator, it is very simple. The picture shows my first trying of tutorial which was presented from qt garden prereleased web site. At the moment, I only use text editor called Notepad++, Dos command for building tutorial C++ code and emulator. Of course, there are some things should installed before use Qt garden.

6/19/2009

Translation bitmap image



Bitmap image contains BitmapHeader, pixels data and palette. The palette only need less than 16 bit color bitmap image, so This article will not include. Microsoft Visual studio has BitmapHeader structure in some header files. It also provides some functions which often give developer difficult to understand. Anyone who may has basic knowledge of c++ and the structure of bitmap file will has no problem with this article. The aritcle will touch only Device Independent Bitmap and pixels data are not compressed.

Code begining here // ->>
#include <stdio.h>
#include <stdlib.h>

#pragma pack(1) // get the structure size 54 not 56

typedef struct {
unsigned char bfType1; // fixed 'B'
unsigned char bfType2; // fixed 'M'
unsigned int bfSize; // Size of File. Zero is acceptable
unsigned short bfReserved1; // Zero
unsigned short bfReserved2; // Zero
unsigned int bfOffBits; // Offset to beginning of bitmap
unsigned int biSize; // Number of Bytes in Structure
unsigned int biWidth; // width of bitmap in pixels
unsigned int biHeight; // height of bitmap in pixels
unsigned short biPlanes; // Planes in target device = 1
unsigned short biBitCount; // Bits per Pixel 1, 4, 8, 16, 24, 32
unsigned int biCompression; // BI_RGB = 0, BI_RLE8, BI_RLE4
unsigned int biSizeImage; // Size of Image Part (often ignored)
unsigned int biXPelsPerMeter; // Always Zero
unsigned int biYPelsPerMeter; // Always Zero
unsigned int biClrUsed; // Number of Colors used in Palette
unsigned int biClrImportant; // Number of Colors that are Important
} TBmpHeader;
<<- // Code end here

The pixels data fills the end of bitmap file after bitmap header. The 1 point pixel data consists of red, green and blue color value each. The each color value has the size of 8 bit.

This is a structure for 24 bit color.

Code begining here // ->>
typedef struct {
unsigned char rgbBlue; //intensity of blue in the color
unsigned char rgbGreen; //intensity of green in the color
unsigned char rgbRed; //intensity of red in the color
} TRGB;
<<- // Code end here

32 bit color adds alpha color value which sometimes use calcuration for mixing two images.

Code begining here // ->>
typedef struct {
unsigned char rgbBlue; //intensity of blue in the color
unsigned char rgbGreen; //intensity of green in the color
unsigned char rgbRed; //intensity of red in the color
unsigned char rgbAlpha; //intensity of Alpha in the color
} TRGBA;
<<- // Code end here

This routine fills bitmapheader structure by using width, height and color bit. The third argument is color type. It can use with 16, 24 and 32 value.

Code begin here // ->>
TBmpHeader FillBitmapHeader(unsigned int width, unsigned int height,
unsigned short bitmapType)
{
TBmpHeader MyBitmapHeader;

MyBitmapHeader.bfType1 = 0x42;
MyBitmapHeader.bfType2 = 0x4D;
MyBitmapHeader.bfSize = 0x00000000;
MyBitmapHeader.bfReserved1 = 0x0000;
MyBitmapHeader.bfReserved2 = 0x0000;
MyBitmapHeader.bfOffBits = 0x36; // the location of bitmap data
MyBitmapHeader.biSize = 0x28; // Size of the BItmapHeader

MyBitmapHeader.biWidth = width;
MyBitmapHeader.biHeight = height;
MyBitmapHeader.biPlanes = 0x0001; // Plane target device 1

MyBitmapHeader.biBitCount = bitmapType; // Bits per Pixel 1, 4, 8, 16, 24, 32
MyBitmapHeader.biCompression = 0x00000000; // BI_RGB = 0, BI_RLE8, BI_RLE4

MyBitmapHeader.biSizeImage = 0x00000000;
MyBitmapHeader.biXPelsPerMeter = 0x00000000;
MyBitmapHeader.biYPelsPerMeter = 0x00000000;
MyBitmapHeader.biClrUsed = 0x00000000;
MyBitmapHeader.biClrImportant = 0x00000000;

return MyBitmapHeader;
}
<<- // Code end here

16 bit color can consist 32 bit color but each RGBA color has to decrease there own size half. Therefore, the result image can not avoid color loss.

Code begin here // ->>
void ConvertBmp32to16(const char *srcfname, const char *dstfname)
{
TBmpHeader MyBitmapHeader;
FILE *finput = fopen(srcfname, “rb”);
if(finput == NULL) return;
fread(&MyBitmapHeader, sizeof(TBmpHeader), 1, finput);
TRGBA * rgbdata;
unsigned short *rgbdata16;

int SSize = MyBitmapHeader.biWidth * MyBitmapHeader.biHeight;
int Size = SSize * 4;

rgbdata = (TRGBA *)malloc(Size);

fread(rgbdata, Size, 1, finput);
fclose(finput);

rgbdata16 = (unsigned short *)malloc(SSize*2);

unsigned short r, g, b, a;
for(int i=0; i < SSize; i++) {
b = rgbdata[i].rgbBlue >> 4;
g = rgbdata[i].rgbGreen >> 4;
r = rgbdata[i].rgbRed >> 4;
a = rgbdata[i].rgbAlpha >> 4;
rgbdata16[i] = (r << 12) + (g << 8) + (b << 4) + a;
}

MyBitmapHeader = FillBitmapHeader(MyBitmapHeader.biWidth, MyBitmapHeader.biHeight, 16);

FILE *fpout = fopen(dstfname, “wb”);
if(fpout == NULL) return;
fwrite(&MyBitmapHeader, sizeof(TBmpHeader), 1, fpout);
fwrite(rgbdata16, SSize*2, 1, fpout);
fclose(fpout);
free(rgbdata);
free(rgbdata16);
}
<<- // Code End here

After execute the ConvertBmp32to16() routine, a bitmap image will be generated. The aim of this routine is for keeping alpha value after translation. So, you don't have to confirm the generated image.

Code begin here // ->>
void ConvertBmp16to32(const char *srcfname, const char *dstfname)
{
TBmpHeader MyBitmapHeader;
FILE *finput = fopen(srcfname, “rb”);
if(finput == NULL) return;
fread(&MyBitmapHeader, sizeof(TBmpHeader), 1, finput);
TRGBA * rgbdata;
unsigned short *rgbdata16;

int SSize = MyBitmapHeader.biWidth * MyBitmapHeader.biHeight;
int Size = SSize * 2;

rgbdata16 = (unsigned short *)malloc(Size);

fread(rgbdata16, Size, 1, finput);
fclose(finput);

rgbdata = (TRGBA *)malloc(SSize*4);

unsigned short r, g, b, a;
for(int i=0; i < SSize; i++) {
b = (rgbdata16[i] >> 4) & 0x0f;
g = (rgbdata16[i] >> 8) & 0x0f;
r = (rgbdata16[i] >> 12) & 0x0f;
a = rgbdata16[i] & 0x0f;
rgbdata[i].rgbBlue = b << 4;
rgbdata[i].rgbGreen = g << 4;
rgbdata[i].rgbRed = r << 4;
rgbdata[i].rgbAlpha = a << 4;
}

MyBitmapHeader = FillBitmapHeader(MyBitmapHeader.biWidth, MyBitmapHeader.biHeight, 32);

FILE *fpout = fopen(dstfname, “wb”);
if(fpout == NULL) return;
fwrite(&MyBitmapHeader, sizeof(TBmpHeader), 1, fpout);
fwrite(rgbdata, SSize*4, 1, fpout);
fclose(fpout);
free(rgbdata);
free(rgbdata16);
}
<<- // Code end here

After execute the ConvertBmp16to32() routine, a bitmap image will also be generated. The image color shows
some color loss.

The shown below routine is translation routine which converts 24 bit color into 16 bit color bitmap.

Code begin here // ->>
void ConvertBmp24to16_555(const char *srcfname, const char *dstfname)
{
TBmpHeader MyBitmapHeader;
FILE *finput = fopen(srcfname, “rb”);
if(finput == NULL) return;
fread(&MyBitmapHeader, sizeof(TBmpHeader), 1, finput);
TRGB * rgbdata;
unsigned short *rgbdata16;

int SSize = MyBitmapHeader.biWidth * MyBitmapHeader.biHeight;
int Size = SSize * 3;

rgbdata = (TRGB *)malloc(Size);

fread(rgbdata, Size, 1, finput);
fclose(finput);

rgbdata16 = (unsigned short *)malloc(SSize*2);

unsigned short r, g, b, a;
for(int i=0; i < SSize; i++) {
b = rgbdata[i].rgbBlue >> 3;
g = rgbdata[i].rgbGreen >> 3;
r = rgbdata[i].rgbRed >> 3;
rgbdata16[i] = (r << 10) + (g << 5) + b;
}

MyBitmapHeader = FillBitmapHeader(MyBitmapHeader.biWidth, MyBitmapHeader.biHeight, 16);

FILE *fpout = fopen(dstfname, “wb&rdquo);
if(fpout == NULL) return;
fwrite(&MyBitmapHeader, sizeof(TBmpHeader), 1, fpout);
fwrite(rgbdata16, SSize*2, 1, fpout);
fclose(fpout);
free(rgbdata);
free(rgbdata16);
}
<<- // Code end here

Code begin here // ->>
int main(int argc, char **argv)
{
ConvertBmp32to16(“bitmap32.bmp”, “bitmap16r1.bmp”);
ConvertBmp16to32(“bitmap16r1.bmp”, “bitmap32r1.bmp”);
ConvertBmp24to16_555(“bitmap24.bmp”, “bitmap16r2.bmp”);
return 0;
}
<<- // Code end here

6/17/2009

This will be my second Android game application...

Since, I am trying to complete this application. The application still miss some routines but the routines will be made soon.

6/09/2009

Sphere on my Android emulator...



Both 'setModel()' and 'setModelEX()' methods work with making points of sphere surface. Now I get my drawing sphere routine. I recommend a URL which provides some glut functions that can be used under Android. akjava-android-project

class GLBall {
private int VertexCount, mallocCount;
private FloatBuffer mVertexBuffer;
private FloatBuffer mNormalBuffer;
public float z_angle;
private int slices, stacks;

public GLBall()
{
mVertexBuffer = null;
mNormalBuffer = null;
}

public void setModel(double radius, int lats, int longs)
{
double lat0, z0, zr0, lat1, z1, zr1, lng, x, y;
float normal[];
float vertices[];

int mindex = 0, nindex=0;

VertexCount = (lats+1) * (longs+1) * 2;
mallocCount = VertexCount * 3;

normal = new float[mallocCount];
vertices = new float[mallocCount];

stacks = lats+1;
slices = longs+1;

for(int i = 0; i <= lats; i++) {
lat0 = (double)Math.PI * (-0.5 + (i - 1) / (double)lats);
z0 = (double)Math.sin(lat0) * radius;
zr0 = (double)Math.cos(lat0) * radius;

lat1 = (double)Math.PI * (-0.5 + i / (double)lats);
z1 = (double)Math.sin(lat1) * radius;
zr1 = (double)Math.cos(lat1) * radius;
for(int j = 0; j <= longs; j++) {
lng = 2 * Math.PI * (j - 1) /(double)longs;
x = Math.cos(lng);
y = Math.sin(lng);
normal[nindex++] = vertices[mindex++] = (float)(x * zr0);
normal[nindex++] = vertices[mindex++] = (float)(y * zr0);
normal[nindex++] = vertices[mindex++] = (float)z0;
normal[nindex++] = vertices[mindex++] = (float)(x * zr1);
normal[nindex++] = vertices[mindex++] = (float)(y * zr1);
normal[nindex++] = vertices[mindex++] = (float)z1;
}
}
mVertexBuffer = FloatBuffer.wrap(vertices);
mNormalBuffer = FloatBuffer.wrap(normal);
z_angle = 0.0f;
}

public void setModelEX(float radius, int astacks, int aslices)
{
int i, j, vindex = 0, nindex = 0;
float slicestep, stackstep;

stackstep = ((float)Math.PI) / astacks;
slicestep = 2.0f * ((float)Math.PI) / aslices;

VertexCount = astacks * (aslices+1) * 2;
mallocCount = VertexCount * 3;

float normal[] = new float[mallocCount];
float vertices[] = new float[mallocCount];

for (i = 0; i < astacks; i++)
{
float a = i * stackstep;
float b = a + stackstep;

float s0 = (float)Math.sin(a);
float s1 = (float)Math.sin(b);

float c0 = (float)Math.cos(a);
float c1 = (float)Math.cos(b);

float nv;
for (j = 0; j <= aslices; j++)
{
float c = j * slicestep;
float x = (float)Math.cos(c);
float y = (float)Math.sin(c);

nv=x * s0;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=y * s0;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=c0;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=x * s1;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=y * s1;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=c1;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;
}
}
mVertexBuffer = FloatBuffer.wrap(vertices);
mNormalBuffer = FloatBuffer.wrap(normal);
z_angle = 0.0f;

this.stacks = astacks;
this.slices = aslices+1;
}

public void draw(GL10 gl) {
int triangles;
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glNormalPointer(GL10.GL_FLOAT, 0, mNormalBuffer);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

triangles = slices * 2;
for(int i=0; i < stacks; i++)
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*triangles, triangles);

gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnable(GL10.GL_TEXTURE_2D);
}
}

6/06/2009

Drawing sphere again


With Mingw I can use OpenGL function within main.cpp. I tried to use OPenGL function in my sphere.cpp but link error occured When i compiled and linked. So, I moved draw() function into my main.cpp. Once sphere
object is made, then the object will can share and will draw many with different color and angle.

main.cpp>

void drawSphere(TSphere sphere)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, sphere.modelvalue);
glNormalPointer(GL_FLOAT, 0, sphere.normalvalue);
glDrawArrays(GL_QUAD_STRIP, 0, sphere.VertexCount);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}

sphere.h>

#ifndef __SPHERE_H__
#define __SPHERE_H__

#include
#include
#include

typedef struct {
float x, y, z;
} Vertex3D;

class TSphere {
public:
TSphere();
void SetModelValue(float radius, int slices, int stacks);
public:
int VertexCount;
Vertex3D *modelvalue;
Vertex3D *normalvalue;
};

#endif

sphere.cpp>

#include "sphere.h"

TSphere::TSphere()
{
//
}

void TSphere::SetModelValue(float radius, int slices, int stacks)
{
float lat0, z0, zr0, lat1, z1, zr1, x, y, lng;
int index = 0;

VertexCount = (slices+1) * (stacks+1) * 2;
modelvalue = new Vertex3D[VertexCount];
normalvalue = new Vertex3D[VertexCount];

for(int i = 0; i <= slices; i++) {
lat0 = M_PI * (-0.5 + (i - 1) / (float)slices);
z0 = sin(lat0) * radius;
zr0 = cos(lat0) * radius;

lat1 = M_PI * (-0.5 + i / (float)slices);
z1 = sin(lat1) * radius;
zr1 = cos(lat1) * radius;

for(int j = 0; j <= stacks; j++) {
lng = 2 * M_PI * (j - 1) / stacks;
x = cos(lng);
y = sin(lng);
modelvalue[index].x = x * zr0;
modelvalue[index].y = y * zr0;
modelvalue[index].z = z0;
normalvalue[index].x = x * zr0;
normalvalue[index].y = y * zr0;
normalvalue[index].z = z0;
index++;
modelvalue[index].x = x * zr1;
modelvalue[index].y = y * zr1;
modelvalue[index].z = z1;
normalvalue[index].x = x * zr1;
normalvalue[index].y = y * zr1;
normalvalue[index].z = z1;
index++;
}
}
}

Drawing sphere without glut...


Finally, I got a picture which is about drawing sphere. The routine does not contain glut function and neither glBegin() function. It is very simple to use. I would like to appreciate to http://ozark.hendrix.edu/~burch/cs/490/sched/feb8/. You can get c source code by visiting the url but u can see little bit different.

Probably, I will change this routine to c code and Android Java code ...

For example)

SPhere1 := TSPhere.Create;
SPhere1.SetModelValue(0.75, 8, 8);

in my render() routine...
begin
...
glLoadIdentity;
glTranslatef(-1.5, 0.0, -3.0);
glRotatef(Angle, 1.0, 1.0, -1.0);
glColor3f(0.9, 0.9, 0.9);
SPhere1.Draw();
glColor3f(1.0, 1.0, 1.0);
...
end;

type
TXCustomVertex = packed Record
fX, fY, fZ : single;
end;

TSphere = class
public
Constructor Create;
Procedure Draw();
procedure SetModelValue(r: single; lats, longs : Integer);
protected
private
clats, clongs, vertexCount : Integer;
ModelValue : Array of TXCustomVertex;
NormalValue : Array of TXCustomVertex;
end;

Constructor TSphere.Create;
Begin
//
end;

procedure TSphere.SetModelValue(r: single; lats, longs : Integer);
var
i, j, index : Integer;
lat0, z0, zr0, lat1,z1, zr1, lng, x, y : Single;
begin
clats := lats;
clongs := longs;
vertexCount := (lats+1) * (longs+1) * 2;

SetLength(ModelValue, (lats+1) * (longs+1) * 2);
SetLength(NormalValue, (lats+1) * (longs+1) * 2);

index := 0;
for i := 0 to lats do begin
lat0 := PI * (-0.5 + (i - 1) / lats);
z0 := sin(lat0) * r;
zr0 := cos(lat0) * r;

lat1 := PI * (-0.5 + i / lats);
z1 := sin(lat1) * r;
zr1 := cos(lat1) * r;

for j := 0 to longs do begin
lng := 2 * PI * (j - 1) / longs;
x := cos(lng);
y := sin(lng);
ModelValue[index].fX := x * zr0;
ModelValue[index].fY := y * zr0;
ModelValue[index].fZ := z0;
NormalValue[index].fX := x * zr0;
NormalValue[index].fY := y * zr0;
NormalValue[index].fZ := z0;
index := index + 1;
ModelValue[index].fX := x * zr1;
ModelValue[index].fY := y * zr1;
ModelValue[index].fZ := z1;
NormalValue[index].fX := x * zr1;
NormalValue[index].fY := y * zr1;
NormalValue[index].fZ := z1;
index := index + 1;
end;
end;
end;

Procedure TSphere.Draw();
Begin
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_Float, 0, ModelValue);
glNormalPointer(GL_Float, 0, NormalValue);

glDrawArrays(GL_QUAD_STRIP, 0, vertexCount);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
End;

5/27/2009

My Mog Roulette game likes this...

Probably, it will be completed in the future or may not.

5/26/2009

GNUstep


GNUstep is a way of using with Objective-C under Window or other Platform. Probably many know or not that the language can support same functionality as other languages do. The language is being used with "Cocoa" for building an application for IPhone. The language is quit interesting for learning. There are two installation files should download and install. Before install it, Mingw should install first. Open a new tab this link , get gnustep-system-0.9.1-setup.exe and gnustep-core-0.9.2-setup.exe. After that, install it by order. GNUstep Renaissance will give some special things. go and get it . Probably need its source because should compile and install. Unzip it to MSYS working folder. The working folder will be created by clicking at MSYS shell of GNUstep at first time. The above shown picture shows an execution figure of simple application.

5/14/2009

Clear screen shot of roulette under OpenGL


One of Nehe's OpenGL tutorials gives me an example how to use. The roulette machine will smoothly spin with OpenGL. but since, this picture means alpha valued image works with OpenGL.

To apply for alpha value


To get a proper alpha valued image, some tasks should be included in the previous list. Thank you for Paul Nicholls, I found FloodFill() routine which can be used with TBitmap32.
The above shown picture is alpha valued image. When the generated image is opened by Gimp, it will be the same as the shown above picture. I include its source.

Click -> available download

5/13/2009

Make my own Roulette image...


Making roulette game will have not an easy task. Probably, the task should be included some mathematic routines. I don't know yet what sort of mathematic should be needed for....
At the moment, I will introduce one method how can make roulette image by Delphi 6 and Graphics32. Of course, there are many ways we can make it by using other development tools. To make an executable file with this source, Delphi 6 Standard and Graphics32 Component should be needed.

Uses
  ..., Math, GR32_Image, GR32; // Add this in Uses

// Conversion double rgb color value to TColor value
Function MakeColor(b, g, r: Double): Integer;
begin
    result := Trunc(r * 255) shl 16 + Trunc(b * 255) shl 8 + Trunc(g * 255);
end;

// In order to display text by angle
procedure TextRotate(bitmap: TBitmap32; x, y, angle: integer; atext: string;afont: TFont);
var
    lf:LogFont;
begin
    //Please Change with your country font, test with a different font to get better result...
    Bitmap.Font.Name := '궁서체';
    Bitmap.Font.Size := 12;
    Windows.GetObject(Bitmap.Font.Handle, sizeof(LOGFONT), @lf);
    lf.lfEscapement := angle * 10;
    lf.lfOrientation := angle * 10;
    Bitmap.Font.Handle := CreateFontIndirect(lf);
    Bitmap.Canvas.Brush.Style := bsClear;
    Bitmap.Textout(x, y, atext);
end;

// Button event for drawing roulette Image
procedure TForm1.BitBtn1Click(Sender: TObject);
{ Draw 1 pixcel width line }
procedure DrawLine(X1, Y1, X2, Y2 : Integer; vBitmap: TBitmap32);
Begin
    { Fill area by drawing lines }
    vBitmap.Canvas.MoveTo(X1,Y1);
    vBitmap.Canvas.LineTo(X2,Y2);
End;

const
    DEG2RAD : double = (3.14159/180);
var
    vBitmap : TBitmap32;
    dAngle, degInRad, dAngleX : Double;
    x1, y1, i, centerx, centery : Integer;
    Color0, Color1, Color2 : Integer;
    Angle, X, Y, H, H2, W, X3 : Integer;
    Step : Real;
    ValueT : Array of String;
begin
    vBitmap := TBitmap32.Create;
    vBitmap.Width := 256;
    vBitmap.Height := 256;
    centerx := 128;
    centery := 128;
    vBitmap.Canvas.Pen.Width := 2;
    vBitmap.Canvas.Pen.Color := MakeColor(0.66, 0.82, 0.82);
    vBitmap.Canvas.Ellipse(10, 10, vBitmap.Width-10, vBitmap.Height-10);
    dAngleX := 360 / 37;
    for i := 0 to 36 do begin
        dAngle := dAngleX * i;
        degInRad := dAngle * DEG2RAD;
        x1 := centerx - trunc(cos(degInRad) * (centerx-10));
        Y1 := centery - trunc(sin(degInRad) * (centery-10));
        vBitmap.Canvas.MoveTo(centerx, centery);
        vBitmap.Canvas.LineTo(X1, Y1);
    end;
    vBitmap.Canvas.Ellipse(40, 40, vBitmap.Width-40, vBitmap.Height-40);

    Color0 := MakeColor(1.0, 0.0, 0.0);
    Color1 := MakeColor(0.0, 1.0, 0.0);
    Color2 := MakeColor(0.0, 0.0, 0.0);
    for i := 0 to 36 do begin
        dAngle := dAngleX * i + 5;
        degInRad := dAngle * DEG2RAD;
        if(i = 0) then
            vBitmap.Canvas.Brush.Color := Color0
        else begin
            if(i mod 2 = 1) then vBitmap.Canvas.Brush.Color := Color1
            else vBitmap.Canvas.Brush.Color := Color2;
        end;
        x1 := centerx - trunc(cos(degInRad) * 110);
        Y1 := centery - trunc(sin(degInRad) * 110);
        vBitmap.Canvas.FloodFill(x1, y1, vBitmap.Canvas.Pen.Color, fsBorder);
    end;
    { Get form size }
    H:=vBitmap.Height;
    W:=vBitmap.Width;

    Angle := 0;
    vBitmap.Canvas.Pen.Color := clBlue;
    while (Angle<360) do begin
        X := centerx - Round(cos(Angle*DEG2RAD) * 88);
        Y := centery - Round(sin(Angle*DEG2RAD) * 88);
        vBitmap.Canvas.Pen.Color:=RGB(255, 255,abs(255-Angle));
        DrawLine(centerx, centery, X, Y, vBitmap);
        Inc(Angle);
    end;

    Angle := 0;
    vBitmap.Canvas.Pen.Color := clBlue;
    while (Angle<360) do begin
        X := centerx - Round(cos(Angle*DEG2RAD) * 48);
        Y := centery - Round(sin(Angle*DEG2RAD) * 48);
        vBitmap.Canvas.Pen.Color:=RGB(abs(255-Angle),abs(255-Angle),abs(255-Angle));
        DrawLine(centerx, centery, X, Y, vBitmap);
        Inc(Angle);
    end;

    vBitmap.Canvas.Brush.Color := RGB($DC, $B4, $8C);
    vBitmap.Canvas.Pen.Color := RGB($DC, $B4, $8C);

    vBitmap.Canvas.Rectangle(126, 128-62, 130, 128+62);
    vBitmap.Canvas.Rectangle(128-62, 126, 128+62, 130);

    vBitmap.Canvas.Rectangle(124, 128-62, 132, 128-22);
    vBitmap.Canvas.Rectangle(124, 128+22, 132, 128+62);
    vBitmap.Canvas.Rectangle(128-62, 124, 128-22, 132);
    vBitmap.Canvas.Rectangle(128+22, 124, 128+62, 132);
    vBitmap.Font.Color := RGB($FF, $FF, $FF);
    vBitmap.Canvas.Brush.Style := bsClear;
    Angle := 90;

    Setlength(ValueT, 37);
    ValueT[0] := '0'; ValueT[1] := '32'; ValueT[2] := '15'; ValueT[3] := '19';
    ValueT[4] := '4'; ValueT[5] := '21'; ValueT[6] := '2'; ValueT[7] := '25';
    ValueT[8] := '17'; ValueT[9] := '34'; ValueT[10] := '6'; ValueT[11] := '27';
    ValueT[12] := '13'; ValueT[13] := '36'; ValueT[14] := '11'; ValueT[15] := '30';
    ValueT[16] := '8'; ValueT[17] := '23'; ValueT[18] := '10'; ValueT[19] := '5';
    ValueT[20] := '24'; ValueT[21] := '16'; ValueT[22] := '33'; ValueT[23] := '1';
    ValueT[24] := '20'; ValueT[25] := '14'; ValueT[26] := '31'; ValueT[27] := '9';
    ValueT[28] := '22'; ValueT[29] := '18'; ValueT[30] := '29'; ValueT[31] := '7';
    ValueT[32] := '28'; ValueT[33] := '12'; ValueT[34] := '35'; ValueT[35] := '5';
    ValueT[36] := '26';
    for i := 0 to 36 do begin
        if(length(ValueT[i]) = 1) Then
            dAngle := dAngleX * i + 3
        else
            dAngle := dAngleX * i;
        degInRad := dAngle * DEG2RAD;
        x1 := centerx - trunc(cos(degInRad) * 110);
        Y1 := centery - trunc(sin(degInRad) * 110);
        TextRotate(vbitmap, x1, y1, Angle, ValueT[i], vBitmap.Font);

        Angle := Angle - 10;
        if(Angle = 0) then Angle := 360;
    end;

    PaintBox01.Canvas.CopyRect(Bounds(0, 0, vBitmap.Width, vBitmap.Height), vBitmap.Canvas,
Bounds(0, 0, vBitmap.Width, vBitmap.Height));
    vBitmap.SaveToFile('image.bmp');
    vBitmap.Free;
end;

5/10/2009

News - 11/05/2009

I am happy to introduce my first free Android application - Mog Poker. Mog Poker is a sort of card game, it is easy to play. Just download it by following the direct link. The game will work on 320 * 320, 320 * 480 and 480 * 320 screen size. If you have a smaller size screen than this, please try not to install it into your mobile. The application does not pay anything to me. I spend months to learn and make this application. Testing this application under emulator, it seemingly doesn't make any problem. Please forgive me about try not to test with a real mobile phone. if you do not meet any problem, please enjoy the game. Before trying it, you can see a couple of demo screen which was made by flash format. You can see the demo screen in the previous list. If you have a problem with viewing the demo screen, please avoid Internet Explorer. No problem with both Google Chrome and Opera.
download 1--> Mog Poker(large size cards)
download 2--> Mog Poker(small size cards)
Important :
The package was complied with Android version 1.5 and the target was Android 1.1.

5/07/2009

Optimise on a smaller screen.

There is no such a screen size (320 * 320) in Android real mobile phone. However, I want to see my application, how it can be optimized on this small screen. I changed each card size, simply redesign cards. Probably, I have to find out different technique, if I want to operate my application on a smaller screen than this screen size.

4/29/2009

Since, I am doing something with ...


Sometimes, People can understand easily by seeing a picture.

4/28/2009

Installing SDL (Simple DirectMedia Layer), GLUT (OpenGL Utility Kit) under Mingw


All information can be found through their presented web site. Therefore candidates can directly visit by clicking this link. Candidates will find the appreciated library under the "Download" / "SDL 1.2" section. The library contains many files, however candidates do not need copy all of it. Copy inside files of bin, include and lib folders into your Mingw folder.
Compile method 1)
$ g++ “sourcefile.extension” –o “launching program name”-lsdl
Compile method 2 – include OpenGL lib)
$ g++ “sourcefile.extension” –o “launching program name”-lsdl –lglu32 –lglut32 –lopengl32
If candidates want to use glut library, please visit here . And will look appreciate method through the web site. Please check the shown above picture.

4/22/2009

Installation Mingw, MSYS and GTKmm on Windows XP


For a long time, I would install some softwares on my old laptop. Three weeks ago, I bought a 40giga hdd, then tried to install into my labtop computer. But, there had some problem and I spent some days to fix it. Finally I get a 30 giga hdd. It was good thing to me because previously I had a 10 giga hdd.
By the way, to install Mingw is quite simple. Candidates can find automated installation setup file from here . Please candidate version choose when you install. Next, candidates can find MSYS automated installation setup file from same URL . The default installation path of Mingw is “C:\Mingw” and MSYS is “C:\Mingw\Msys”. Give a path “C:/Mingw” when MSYS installer asks where Mingw was installed. After the Installation, Please add “C:\Mingw\bin;” to the environment variable called “Path”. There has some works should do under the MSys shell. Before doing it, let install the GTKmm which is stand for Graphic Tool kit … something like that. Go there , find and download the automated setup file for windows. Next, give a path “C:\Gtk” When Installer asks where does install you want. The setup will add something on your environment variable. So please relax instead of doing something. Under MSys shell, I could compile and execute any examples of GTKmm with `pkg-config`. Before compile with g++ and gcc, execute the MSys shell. If the MSys shell window is displayed, then go to root directory use “cd” instruction ([ex]cd ..). You can check your current folder by using “pwd” instruction. If you are in root folder, the “pwd” instruction will return “/”. Check file and directory by using “ls” instruction. If you can not see the “gtk” folder, make “gtk” folder by using “mkdir” instruction ([ex]mkdir gtk). Next, Candidate can link this path by editing ‘fstab’ file which is located in “/etc” folder. When you open it, you will know how to do it. Add like “c:/gtk /gtk”. To edit file under MSys shell, use vi editor. You can find a manual by searching Internet. Now close the MSys shell and execute again. Go to “/gtk” directory and check file and directory. If you have some files and directories, you get “gtk” under MSys shell. Now go to your working folder by “cd” instruction ([ex]cd). Make example file for compiling. Here is compiling example. Ex) $ gcc tutorial1.cc –o tutorial `pkg-config --cflags --libs gtkmm-2.4`.

4/19/2009

It's a tunning point to make my game application.


Presently, I challenge to make my game application which would be operated under the Android platform. To complete the application I think many days will go. Thank to Nokia forum that I could find a good card resource from them...

4/12/2009

Introduction of Android skin


I think many people already knew this article, however for some people's ignorance I would like to introduce one thing which is about the android skin, it can be downloaded through the suggested URL in this picture. I appreciate to the creator of those skins. The above shown picture is my favorite skin.

안드로이드 스킨 소개


이미 안드로이드를 알고 계시는 분은 이미 알고 계시리라 생각되지만 혹시나 아직 모르시는 분을 위하여 이렇게 보기좋은 에뮬레이터 스킨을 올립니다. 그림에 제시되어진 주소를 찾아 가셔서 입맛에 맞는 스킨을 사용해 보시십요. 올려진 그림은 제가 좋아하는 에뮬레이터 스킨입니다.

3/26/2009

이클립스 그리고 두달이란 시간동안...


이클립스를 접하게 된것은 아마도 두달전으로 거슬러 올라갑니다. 처음엔 이클립스에 그냥 자바 스탠다드 플랫폼을 이용하여 일반 데이타베이스 클라이언트 응용프로그램을 진행하다가 어느날 문득 모바일에서 돌아가는 응용 프로그램을 만들어 보고 싶다는 생각에 그날 부터 인터넷을 찾아보며 진행을 했습니다. Net bean도 설치해 사용해 보았지만 역시 본인에게는 이클립스가 더 좋네요. Nokia의 Carbide C++은 한번 시도해 보고 싶은데 가지고 있는 노트북이 저사양이고 제대로 사용할려면 상당히 많은 양을 SDK를 필요로 하기 때문에 일단 뒤로 미루고, 이전에 올린 게시물의 지식을 얻기 위하여 여기 저기 인터넷을 많이 돌아 다녔습니다. 그리고 이쪽분야의 지식을 알기 위해서 전화도 해보고 사람도 만나보고 첫번째 에뮬레이터에서 돌아가는 응용프로그램 스크린샷을 함께 올립니다. 이미 국내에 삼성과 LG에 제가 구상한 응용프로그램이 탑재되 있기에 의미가 없지만 역시 그래도 배움이 있었기에...

이클립스에 구글안드로이드 플랫폼 붙이기 두번째


그림에서 보듯이 Window > Preferences 메뉴를 클릭한 후 왼쪽의 Android 항목을 클릭합니다. 그리고 나서 안드로이드 SDK가 설치된 경로를 (예: C:\android-sdk-windows-1.1_r1) 설정합니다. 나머지 설정은 그냥 디폴트로 두시면 됩니다. 이클립스에 Android Project 메뉴 추가를 위하여 Windows > Customize Perspective... 를 클릭하셔서 나타나는 다이알로그에서 Android와 관련된 항목을 선택하시면 Android Project를 시작하실수 있습니다. 이렇게 함으로써 이클립스와 자바를 이용하여 모바일에서 실행되어질 수 있는 게임개발에 한발짝 다가갈 수 있습니다.

3/25/2009

이클립스에 구글안드로이드 플랫폼 붙이기 첫번째

구글 안드로이드 SDK는 여기로 가셔서 받을실 수 있습니다. 다운 받으신 파일은 C:\에 압축을 풀면 됩니다. 이클립스 유로파나 가니메데 버전에서 돌아가며 OS는 윈도우의 경우 Windows XP (32-bit) or Vista (32- or 64-bit) 가 필요합니다. 마찬가지고 이클립스 플러그(일명 ADT)인이 필요하며 이클립스 가니메데 버전의 경우 아래와 같은 방법으로 설치합니다.

1. 이클립스를 실행하시하신후, Help> Software Updates... 순으로 메뉴를 클릭합니다.
2. 나타나는 다이알로그 안에서, Avaiable Software tab을 클릭합니다.
3. Add Site...를 클릭하여 plugin 내려받을 사이트를 설정합니다.
4. 다음과 같이 URL을 입력합니다. "http://dl-ssl.google.com/android/eclipse/"
5. Android Devlopment Tools, Android Editors를 클릭하신 후 Install 버튼을 클릭합니다.

설치가 완료되면 Eclipse를 재구동합니다. ADT와 관련된 설정은 두번째를 참고 하십시요. 아래 동영상은 보다폰에 안드로이드 플랫폼이 탑재된 동영상 입니다.

이클립스에 SK-VM 플랫폼 적용하기 세번째


이젠 Windows -> Customize Perspective... 메뉴를 이용하여 XVM Project 항목과 관련된 1개 메뉴를 추가함으로써 개발자는 SK-VM에 실행되어지는 프로젝트를 쉽게 시작할 수 있습니다.

이클립스에 SK-VM 플랫폼 적용하기 두번째


SK-VM을 설치하신후 마찬가지로 설정이 필요합니다. Eclipse의 Windows > Preferences 를 클릭하신후 왼쪽은 새롭게 나타난 XVM을 선택합니다. 에뮬레이터의 실행파일 위치와 에뮬레이터 장치(스킨)을 설정합니다. 메모리 양을 512 또는 1024라고 입력하신 후 설정을 마칩니다. 그림을 참고 하십시요...

이클립스에 SK-VM 플랫폼 적용하기 첫번째


SK-VM은 SK Telecom에서 clean room 기반으로 자체 개발한 J2ME(Java 2 Micro Eidtion) 자바 실행 환경으로 가상머신 및 단말 확장 UI, 네트워크, IO를 포함하는 클래스 라이브러리로 구성되어 있으며, 무선이동단말기에서 응용프로그램을 다운로드 및 실행시킬 수 있는 환경을 제공한다.(SK Telecom, XCE)

SK-VM은 http://developer.xce.co.kr /로 가셔서 회원가입을 하신후에 여기서 다운을 받고 설치하시면 됩니다. 설치가 완료되신 후 이클립스의 메뉴부분을 확인하십시요.


참고

1. SK Telecom, XCE, 2009.03.25,
view http://www.javastudy.co.kr/docs/lec_j2me/mobilejava/n-top/2.htm

MTJ설정후 Eclipse 추가적으로 할일들...


MTJ와 Antenna 가 설치가 완료되어 졌다면 이클립스로 우리는 핸드폰용 게임 또는 응용 프로그램 개발(일명 CLDC, MIDP)을 시작할 수 있으며 Windows -> Customize Perspective... 메뉴를 이용하여 Java ME 항목과 관련된 두개의 메뉴를 추가함으로써 Eclipse 사용자들은 Midlet 프로젝트를 쉽게 시작할 수 있습니다. 이제 이클립스에서 자바를 이용하여 모바일 게임을 시작할 수 있습니다. 단 외국모바일 폰에 한에서...

Antenna와 MTJ...


Antenna나는 아팟치의 Ant의 확장이라고 합니다. Ant는 순수한 자바 툴이며, GNU make 보다 단순하고 쉽게 사용할 수 있다고 하네요. 어쨌거나 설치는 antenna-bin-1.0.2.jar 파일은 여기서 받으힌 후 antenna-bin-1.0.2.jar 파일을 편의상 eclipse의 plugin 폴더에 복사 합니다. 설정은 마찬가지로 eclipse를 구동하신 후 Window -> Preferences 를 클릭한 후 왼쪽의 Java ME 항목을 선택하신 후 C:\eclipse\plugins\antenna-bin-1.0.2.jar라고 Antenna jar 경로를 설정합니다. Java ME 항목 > Preprocessor > Symbol Set Definitions이 추가됐네요... MTJ 사용자들은 Antenna 형식에 맞게 이미 정의되어진 심볼을 임포트 할 수 있다고 합니다.

이클립스에 MTJ를 붙이기...

여기서 MTJ는 Mobile Tools for Java라고 표기 되어질 수 있으며 이클립스에서 자바 모바일 응용 프로그램을 좀더 쉽게 개발할 수 있도록 해주는 플러그인 입니다. MTJ의 Misssion Statement는 아래와 같습니다.

The goal of the Mobile Tools for JavaTM (MTJ) project is to extend existing Eclipse frameworks to support mobile device Java application development.

자 마찬가지로 다운로드를 받으러 가야됩니다. 경로는 여기로 가셔서 Latest Release를 받으시면 됩니다. zip format의 압축 파일은 풀면 features 폴더와 plugins인 폴더로 나우어져 있는데 설치된 eclipse 폴더 안에 이미 존재 합니다. 그러므로 덮어쓰기 형태로 풀면 플러그인이 설치되며 eclipse가 구동중이라면 재 구동을 통하여 플러그인이 제대로 설치되었는지 여부를 가늠할 수 있습니다.

일단 MTJ를 설치한 후 MTJ가 제대로 작동하기 위하여 설정이 필요합니다. eclipse를 구동하시면 아주 잘 만들어진 IDE가 보일 것입니다. 메뉴는 File, Edit, Navigate 등등이 있는데 이중에서 설정을 하기 위하여 Windows 메뉴를 클릭합니다. 여러개의 Submenu중에 Preferences를 클릭하시면 Preferences 타이틀을 가진 다이얼로그가 화면에 나타납니다. 윈쪽의 항목에서 Java ME를 클릭하신후 WTK Root 경로를 잡아줘야 합니다. WTK는 Wireless Tookit for CLDC라고 표기 되어질 수 있으며 이미 앞에서 설치하였으므로 경로가 어디인지는 아실겁니다. 일반적으로 C:\WTK2.5.2_01 이곳에 설치됩니다. 다음은 Java ME의 항목안에 Device Management를 선택한 후 Import 버튼을 클릭하여 마찬가지로 C:\WTK2.5.2_01 경로를 선택합니다. Device Management는 에뮬레이터 스킨이라고 할 수 있으며 이클립스에 새 프로젝트를 만들때마다 여기서 선택한 디폴트 디바이스(MediaControlSkin)가 선택됩니다. 프로젝트를 만들고 난 이후에도 결과 실행시 에뮬레이터 스킨은 변경이 가능합니다. 다음으로 Antenna를 설정해야 합니다

이클립스 설치는 이렇게 ...


이클립스 구동의 최소 충분 조건으로 자바 런타임 모듈 최신버전이 필요 합니다. JRE 최신버전은 Sun 에서 JRE 6 바이너리 설치 모듈을 다운받아서 설치하시면 됩니다. 자바 런타임 모듈 설치가 완료되면 제어판에서 확인이 가능하며 이클립스 내부에 따로 JRE 폴더와 파일이 존재 하지만 이는 정상적으로 설정되지 않으므로 직접 JRE를 설치하는 것이 좋습니다.

자바 런타임 모듈 설치외에 자바 개발 툴 (일명 JDK) 설치도 상황에 따라 필요한데 예를 들자면 구글에서 최근에 개발 중인 안드로이드 플랫폼을 구동하고 싶다면 JDK 또한 Sun 에서 다운 받아서 설치 합니다.  설치는 인스톨러가 제시하는 데로 진행하면 됩니다.

다음은 이클립스와 자바 마이크로 에디션을 이용하여 모바일 응용프로그램을 개발할 수 있도록 Sun 에서 제공하는 Wireless Toolkit을 설치해야 합니다.  현재 3.0 버전과  2.5.2 버전 두가지중 필자는 가지고 있는 노트북이 저사양이기 때문에 2.5.2 버전을 사용합니다.  다운로드가 가능한 URL은 여기로 가서 다운 받으시면 됩니다.

이렇게 하여 이클립스를 구동하기 위한 필요 충분 조건이 갖추어졌으므로 이제 이클립스를 다운받으러 가야 겠지요 다운로드가 가능한 주소는 여기로 가셔서 원하는 파일을 다운받으시면 됩니다. 다운로드는 국내의 경우 다음을 통하여 받으므로 상당히 빠릅니다. 설치는 그냥 압축을 C:\에 풀면 c:\eclipse 경로에 풀리게 됩니다. 이제 윈도우 탐색기를 이용하여 C:\eclipse\eclipse.exe 파일을 실행하시면 우리의 이클립스는 멋지게 실행이 됩니다. 실행시에는 작업경로를 설정하여야 합니다.