Chess Gaming and Graphics Using Open Source Tools
Chess Gaming and Graphics Using Open Source Tools
Tong Lai Yu
California State University
Department of Computer Science and Engineering
San Bernardino,
CA 92407
254
der a 3DS model using the 3dslib library and OpenGL. quite straightforward. It uses the two OpenGL utility com-
------------------------------------------------------- mands, gluPerspective() and gluLookAt() and the cam-
struct Vertex { era information saved in the 3DS file to specify the view of
float x, y, z;
}; the graphics model. It also makes use of the information of
textures, material properties, normals and triangular meshes
void display_meshes ( Lib3dsFile *f )
{ saved in the file to render the 3D model. The only crucial
struct Vertex *vs, v; feature that is not shown is the use of lighting information
Lib3dsMesh *mesh;
contained in the 3DS file. Once a 3DS file is parsed, we can
Lib3dsMaterial *mat=0; //mesh materials apply any affine transformation to the image objects; we can
init_texture(); //initialize texture features
rotate, translate or zoom the chess board or any chess piece.
glEnable( GL_CULL_FACE ); The texture of an object can be easily changed with cus-
glCullFace ( GL_BACK );
Lib3dsNode *node; //3DS node tomized texture images. Lighting and cameras can be ad-
justed according to needs. Moreover, shadows and special
for ( int k = 0; k < f->nmeshes; ++k ) {
mesh = f->meshes[k]; shading effects can be added to the model using OpenGL
vs = getVertices(f->meshes[k]);//get a vertice of mesh Shading Language ( GLSL )[19], which basically has the
//calculate normal same syntax as C/C++ and has become a very popular tool
float (*normals)[3] = (float (*)[3]) in video game development.
malloc (3*3*sizeof(float) * mesh->nfaces);
lib3ds_mesh_calculate_face_normals ( mesh, normals ); This is a very good method of creating 3D interactive
for ( int i = 0; i < mesh->nfaces; ++i ) { graphics for a chess program if the program runs in a pow-
if (mat) { //set material properties
float s; erful computer. However, a realistic 3DS model created
glMaterialfv(GL_FRONT, GL_AMBIENT, mat->ambient ); by Blender usually consists of a numerous number of poly-
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat->specular); gon meshes and it is computing-intensive to process a large
s = pow(2, 10.0*mat->shininess); number of meshes. Such a model may not be appropriate
if (s>128.0)
s=128.0; to be run in slower devices like embedded systems. For
glMaterialf(GL_FRONT, GL_SHININESS, s); slower systems, a better method to generate 3D chess pieces
} //if ( mat )
//display the mesh is to create them using the technique of ”Surface of Revolu-
glBegin ( GL_TRIANGLES ); tion”[20], in which a 3D object is produced by first drawing
for ( int j = 0; j < 3; ++ j ) {
glNormal3fv(normals[3*i+j]); a profile and then rotating the profile about an axis in dis-
int ii = mesh->faces[i].index[j]; crete steps. In our project, we used B-spline curves to gener-
v = vs[ii];
if ( mesh->texcos ) //texture coordinates ate profiles that can efficiently generate 3D chess piece im-
glTexCoord2f(mesh->texcos[ii][0], ages and by revolving the profiles around the z-coordinate
mesh->texcos[ii][1]);
glVertex3fv( ( float*)&v ); axis.
} A B-spline curve with n control points and n blending
glEnd();
} //for i functions Nk,m (t) of order m is described by the following
free ( normals ); equation:
} //for k
n−1
free ( vs ); X
} P (u) = Pk Nk,m (u)
k=0
void display()
{ where P0 , ..., Pn−1 are the control points and the blending
Lib3dsCamera *camera;
Lib3dsFile *f = get3dsFile ( (char *) filename ); functions can be calculated recursively:
if ( f->ncameras > 0 ) {
camera = f->cameras[0];
u − uk
Nk,m (u) = Nk,m−1 (u)
glMatrixMode ( GL_PROJECTION ); uk+m−1 − uk
glLoadIdentity();
gluPerspective ( camera->fov, 1.0, uk+m − u
camera->near_range, camera->far_range ); + Nk+1,m−1 (u)
glMatrixMode ( GL_MODELVIEW ); uk+m − uk+1
glLoadIdentity();
gluLookAt(camera->position[0], camera->position[1],
camera->position[2], camera->target[0], 1 if uk < u ≤ uk+1
camera->target[1], camera->target[2], 0, 1, 0 ); Nk,1 (u) =
}
0 otherwise
display_meshes ( f );
glFlush(); for k = 0, 1, ...., n - 1. In the above formulas,
glutSwapBuffers(); (u0 , u1 , ...., un+m−1 ) is a knot vector, which can be cal-
}
------------------------------------------------------- culated according to the following rules[20]:
One can see from the code that the rendering process is 1. There are totally n + m knots, denoted as
255
u0 , ..., un+m−1 very valuable resources for education institutions like some
2. First m knots, u0 , ..., um−1 all have value 0 campuses of California State University that have curricula
3. Knots um , ..., un−1 increases in increments of teaching video games, graphics and image processing. Re-
value 1, from 1 to n - m. lying on open source tools enables students to affordably
4. The final m knots, un , ..., un+m−1 are all equal to undertake development of video game software and other
n - m + 1. related multimedia projects for profit, which can fuel their
interest and hope even if the profit is insignificantly small.
Figure 3 shows a pawn that was generated using this
method; the pink squared dots are the control points used
Acknowledgments
to produce the profile and the pawn object is obtained by
revolving the profile around the z-axis. By adjusting the This research is supported by the CSUSB 2008 Summer
control points, one can easily adjust the shape of the object. POD funding. The author thanks Dr. David Turner for in-
Also, display-lists[20] can be used to speed up the render- troducing the 3DS and collada 3D file formats.
ing of these kind of objects. Generating image objects using
surface revolution also makes the program a lot more flexi- References
ble when it is run in a wide range of platforms. More slices
and steps can be used when it is run in a fast system to give [1] Colin Frayn and Carlos Justiniano, ” The ChessBrain Project
higher quality images. In embedded systems where the pro- Massively Distributed Chess Tree Search” in Advanced Intelligent
cessor speed is much slower, the number of slices and steps Paradigms in Computer Games, Springer Berlin / Heidelberg, p.92
used can be significantly reduced. - 115, 2007.
[2] Colin M. Frayn, Carlos Justiniano, Kevin Lew, ”ChessBrain
II A Hierarchical Infrastructure for Distributed Inhomogeneous
Speed-Critical Computation”, IEEE Symposium on Computa-
tional Intelligence and Games , Reno NV, May 2006.
[3] http://www.frayn.net/beowulf
[4] http://www.frayn.net/beowulf/theory.html
[5] http://www.blender.org
[6] http://www.lib3ds.org, http://www.collada.org
[7] http://www.libsdl.org
[8] http://www.mesa3d.org
[9] J. Pearl, Heuristics: Intelligent Search Strategies for Computer
Problem Solving, Addison-Wesley, 1984.
[10] N. J. Nilsson, Artificial Intelligence: A New Synthesis, Mor-
gan Kaufmann Publishers, Inc. 1998.
[11] Knuth, D. E., and Moore, R. W., ”An Analysis of Alpha-Beta
Pruning”. Artificial Intelligence Vol. 6, No. 4: 293 - 326, 1975.
[12] http://www.openal.org
[13] John R. Hall, Programming Linux Games, Linux Journal
Press, 2001.
Figure 3. Pawn generated by Surface Revolu- [14] http://www.gimp.org
tion. [15] A.N. Sloss, D. Symes, and C. Wright, ARM System Devel-
oper’s Guide, Elsevier Inc., 2004.
[16] T.L. Yu, ”Implementing a 16-bit Embedded Ogg Vorbis De-
coder”, Proceedings of ICCSA 2006, San Diego, June, 2006.
[17] T.L. Yu, ”Implementation of Video Player for Embedded Sys-
4. Conclusions tems”, Proceedings of IASTED on Signal and Image Processing,
p. 25-30, Honolulu, Hawaii, August 20-22, 2007.
In conclusion, one can utilize open-source resources to [18] http://the-labs.com/Blender/3DS-details.html
[19] R.J. Rost, OpenGL Shading Language, Second Edition, Ad-
develop a high-quality multimedia 3D graphics game like
dison Wesley, 2006.
chess which can run in different platforms including em- [20] F.S. Hill, and S.M. Kelly, Computer Graphics Using OpenGL,
bedded systems. The use of open-source tools significantly 3rd Edition, Prentice Hall, 2007.
shorten the development time and reduce the development [21] T.L. Yu, ”A Framework for Very High Performance Com-
cost to a minimum. The learning of the tools is a valuable pression of Table Tennis Video Clips”, Proceedings of IASTED on
education experience for a developer; the skill can be reused Signal and Image Processing, P.167-172, Kailua-Kona, Hawaii,
again to develop different types of video games or image August 18-20, 2008.
processing applications[21]. Therefore, these tools are also
256