recent random things

| No Comments | No TrackBacks
Now that I have been in China for almost 1 month, I am glad that I bought almost all the books that I need, and I am so ready to read them all.

the crucial problem now for my next project is to create a flexible and robust structure, involving solid software engineering knowledge.

Now I found the book "game script mastery" really good for this kind of subject. cuz in order to get flexibility, I have to add script capability to my program, and this is the most important link between different subsystems, like audio,game logic, renderer, io system, etc..

at the same time, because I have already had some knowledge on OpenGL, the further direction is to learn computer graphics, and that will be accomplished by reading "Interactive Computer Graphics: a top-down approach using OpenGL", which shows pretty much what I need to know right now. It's the most suitable book I can have right now.

moreover, my C programming language skill still needs to be improved by reading "Poiners on C", then I will be able to understand how C deal with memory, the most important resource in programming.

after reading the 1st volume of "Write Great Code", I already have some basic knowledge on computer archietecture, the next thing I need to do, after reading the three books mentioned before, is to read some books on "computer archietecture", and "operating system".

John Carmack has begun the Doom Classic Iphone project, which is a very good opportunity for me to build a Doom-like engine now along with John, good timing. Link

The week before last, when I was in Beijing, I talked to my girl about making a simple CPU after reading computer architecture book, and now, one video game programmer Steve Chamberlin in the US has made that reality. Link

Looking back on my time back in China, I am really not satisfied with my low-efficiency!

I want peace, I want peaceful mind.....

I HATE!

left US, enter Korea, head China

| No Comments | No TrackBacks
Nothing special, really.

The thing is that I feel that there is no such thing as "foreign" any more. no matter where you are, as long as there are people, the rule stays, the human rules stay.

so... um....

yea, bad thing is i have to wait here for another 5 hours....

tata


work log 4/30/2009

| No Comments | No TrackBacks
dynamically manage resource can make all things more flexible

Simple Race

+ dynamically load map data
* dynamically manage game data
* texture management
* car information management
* music data management



Simple Race 1.07

| No Comments | No TrackBacks
----------------------------------------------------
Simple Race v1.07 beta @2009
----------------------------------------------------


added features:
1. added Ferrari F2008 car
2. added one ultimate map
3. added two more in-game music
4. different topspeed for different cars
5. need to find 4 ferrari logos
6. all files in one single install file, easy to use

game file:

download

email from john carmack

| No Comments | No TrackBacks
HUAIDONG WANG wrote:
> Dear John Carmack:
>
> I don't know if you can get this email or not, I have been following
> your work for a long time, but I was in China, cannot be there at
> Quakecon, now that I am in Penn State, I can come to Quakecon this year.
>
> For this quakecon, can you talk a little about how far have you been
> on the unified rendering architecture? that you mentioned in a couple
> of quakecon, you said you are close to build a architecture for
> rendering like Renderman did.
The short answer is that I backed away from that. When targeting a 60hz
game on current gen consoles, it is still necessary to think like a game
engine. You could make a commercial game with a truly general
architecture, but it wouldn't be at the AAA level currently due to the
compromises.

John Carmack




won't update regularly

| No Comments | No TrackBacks
I am in my next learning period now, probably won't update the blog unless I found something that impresses me or I make some breakthrough...

current learning content:
*deeper OpenGL
*algorithm

I watched ACM 2009 world final last night, it was amazing.

Simple Race v1.06 beta

| No Comments | No TrackBacks
Simple Race v1.06 beta

added features:
1. in game music
2. in game special sound
3. "R" key that can be used as Reset, when freezed in the wall

I used SDL_mixer as my music loader and player.
Music is from DOOM, they'r in midi format.
id software holds all the rights.

this is a non-comercial game, the music is used only in this project, and the source code is gonna be released with the game.

------------------------------------
here is the link:
download

-----------------------------------
if you have some suggestions, please leave a comment here.

work log (4/18/2009) // TWO MONTHS since OPENGL

| No Comments | No TrackBacks
now it's officially 2 months since I started to learn graphics programming, my first game is about to finish, I am happy!

celebrate a little bit.....

write a little something here:

in these two months, I really really learned a lot, I spent days and nights on my game, I can say, I now have a rough overview of what I am going to do in the future, and the computer graphics area. I learned a lot from building my own game from scratch, like, how to organize the code for a big project, how to work on codes piece by piece, how to build a good-to-use class so that it can fit into the whole project......etc, except computer graphics, I learned a lot on software engineering, and thanks to my CMPSC122, I know some basic data structures and algorithms, that course opened a gate to me, the computer programming's gate.

these two months created a boat for me, for me to surf to the deeper part of computer world. These two months is the most important months in my life, I can feel it, I can feel my future just because of the two months. I have always wanted to sail, but I didn't really started before the two months.. now I do.

I wanna really thank my professor Max, Fomitchev, he made me rethink my ability on computer programming, he made me wanna do a lot of things that I wouldn't do before, he helped me to find my potential on programming. I wanna thank him!

The journey has just begun.


here is a little plan:
*revisit C programming, take it low-level
*study deeper towards OpenGL
*study deeper towards algorithm
*computational geometry
*GLSL

at the same time, learn a little java and programming under Mac
do a little cross-platform practice by porting my game to iphone and java

-----------------------

anyway:

today's work log:

+remixed some midi from the original DOOM, will be used as the game music
+fixed some hard-coding code
+fixed texture size
+fixed some inefficient memory use

*add music module to my game
*structurize my code


Simple Race v1.05 beta test release

| No Comments | No TrackBacks

added features:

1. choose from 2 cars
2. choose from 2 maps
3. restart game
4. add openning, instruction, map choice, car choice windows.

still testing item:
*collision response

here is the link

download


Hashing......

| No Comments | No TrackBacks
Listed as one of the Five Top technics proposed by Richard Stallman.

Choosing a hashing function is just art not science

anyway, keep digging

SimpleRace v1.04 test version

| No Comments | No TrackBacks
fixed item
collision detection (needs to be tested)

features added:
1. full screen option (needs to be tested)
2. randomly place the target logo
3. high resolution and low resolution textures to choose from

Please Note:
if you want to replace the texture with low resolution, go to "Texture" folder and copy the low res ones to the "Texture" folder, reload the game.

this zip is bigger than before, because it contains high res textures

download

if you are using Windows XP and don't have opengl, you can download this
XPOpenGL

Here is the source code for this beta version, if you are interested, please take a look and give me some advice!
Source Code

welcome everybody to email me report bugs and places needed to improve to me.

Huffman tree and map

| No Comments | No TrackBacks
I was doing a little coding on my school's work, it's about Huffman code, I just think that it is very useful, and I was having a little issue of retrieving data correctly from the huffman tree. So I figure I just post the code here, in case some one else is gonna need it.

Method 1: search the Huffman Tree every time to get the code

// this function take "temp"as a temporary variable to store the code string
// aChar is char we are looking for in the tree
// tree is the Huffman tree we built
// the function will return the huffman code for this character

string findHuffCode(string temp,const char& aChar,const HuffTreeNode* tree)
{
    if (tree->IsLeaf())
    {
        if (tree->Value.Symbol==aChar)
            return temp;
        else
            return "";
    }
    else
    {
        if (findHuffCode(temp+"0",aChar,tree->Left)=="")
            return findHuffCode(temp+"1",aChar,tree->Right);
        else
            return findHuffCode(temp+"0",aChar,tree->Left);
    }
}

Method 2: using a map structure to store the Huffman code for every character

// huffMap is the map we will build
// temp is the temp string store the Huffman code
// tree is the Huffman tree we built
void buildHuffMap(map<char,string>& huffMap,string temp,const HuffTreeNode* tree)
{
    if (tree->IsLeaf())
    {
        huffMap[tree->Value.Symbol]=temp;
    }
    else
    {
        buildHuffMap(huffMap,temp+"1",tree->Right);
        buildHuffMap(huffMap,temp+"0",tree->Left);
    }
}

tree structure is the most useful data structure that I v seen, and recursion is the most magical process I v known....

plans for the next few months

| No Comments | No TrackBacks
read some books

1. write great code

2. thinking in C++

3. introduction to algorithms

4. computational geometry with c

I am not quite sure if I am gonna finish them or not, I will use all my free time to do that.

plan for v1.04

| No Comments | No TrackBacks
here is a brief plan of what I am gonna do in 1.04 version

1. I am gonna rewrite the collision code, doing the right physics calculation not those crappy approximation, I tried to do all those approximation and didn't pay off, physics is almost the core of my racing game.  (I am amazed by modern computers' capability, they allow me to do a lot of complex calculations)

2. a better software structure. I read some code from others, their programming style is so clear and neat, I am gonna improve my programming style.

3. the game play side of things, can be considered later, cuz they are the relatively easy part. the game play mode now so far is not bad.


I got a great book today, Randall Hyde's <Write Great Code> think low-level,write high-level... That's the exact thing I need right now, I need to understand more low-level stuff to fundamentally improve my programming skill.
quote John Carmack's words here:

Low-level programming is good for programmers' soul.

SimpleRace beta test version release

| No Comments | No TrackBacks

I finally got the texture loading problem solved, it was the size problem. It took me so long time to find that out.... :-( 
some card doesn't support GL_ARB_texture_non_power_of_two
here is a link on this issue: http://www.gamedev.net/community/forums/topic.asp?topic_id=460868

anyway, here is the beta test version, hopefully it's gonna run on every windows machines.

download

there is still some jittering with the physics engine, I will fix that in my next version.

collision detection 2

| No Comments | No TrackBacks

There is still some flaw with my code before, I examined the code very carefully and found that I need to store the non-collision state, and restore it after one collision.In other words, I need to find the exact colliding time. If I don't, if I use the already collided time, the behaviour is very weird.

The modification that I made, was to use a set of variables to store the non-collision state just before collision, or it can be specified as a state buffer.

the pseudcode is:


updateState()
{
      if  not colliding
       then store the state
      if colliding
        restore the state and execute the collision response
}

but there is a problem with low update rate computers, that is if the car's speed is too fast, the stored state's position might be a little far from the current state, if you restore it, there might be Temporal aliasing. which is not good....

anyway, I will continue the study on this, and update what I get.

items to complete

| No Comments | No TrackBacks
* speedometer
* race timer
* score display
* menu
* car customization tool
* include necessary dlls in the zip
* add frame rate display


beta version is likely to come next week.

2d rectangles collision detection

| No Comments | No TrackBacks

I finally figured out a proper way to achieve collision detection.

so far I have tried 4 ways of doing it, but it turns out that the last one is the most realistic one.

first let me describe what I want to do:

I want to do a decent collision detection between two rectangles (one is the car, the other is the wall). In my case ,the walls are axis-aligned. I used a 2 dimentional array to generate the wall.

since my map is generated by a 2d array, so it's easy to determine whether one point is in the wall or not.
using
             int m=(-y)/side_length_of_each_tile;
             int n=x/side_length_of_each_tile;
              if (map[m][n]=="The tile number you set as a wall")
                  then  this point is in the wall
the hard part is to determine which side of the wall is the car colliding, so that I can figure out if the car is gonna turn clockwise or counterclockwise.

before I explain,  there is one thing, my map is generated to the 2nd quadrant. that means map[0][0] is at (0,0), map[m][n] is at (MAP_W,-MAP_H)

let me go over the method that I think is the best so far:

1. vertices test
    for each collision test cycle, I test all 4 or the vertices of my car, and determine if one of them is in the wall, and then calculate this point's distance to the middle points of the four sides of the
wall tile to figure out which side is the car colliding, so that we can find out the normals, and to determine the turning direction.

let me explain here in detail:  let's say the tile is map[m][n], the the upperleft corner's coordinates is (n,-m), upperright corner's is (n+1,-m), and so on.

then calculate the mid points of all four sides, and find the smallest distance, and that one is the side that the car is colliding.

but there is one problem with this, when I was using integer m and n to find the map tile, and if I take into account the refreshing rate, it's possible that when we try to locate the point, the point is already in the wall, so there is a possibility that the smallest distance is not bewteen the point and the colliding wall.

moreover, this method requires the computer to calculate the min value every time, it's a little bit expensive.


2. improved vertices test

when I think about this problem again, I figured since all the wall tiles are axis aligned, why can't I do some optimization?

then I tried to list all the situations of collision, I thought it would be a lot, but it's not.

let's lable the upperleft corner No.1, upperright corner No.2, lowerleft corner No.3, lowerright corner No.4.

here I simplify the situation to that "if there is a collision on No.3, and No.4, the car doesn't rotate"

so , if No.1 collides:

           a) No.3 and No.4 are in the map tile map[m+1][], the normal is 270 degrees

           b) No.3 and No.4 are in the map tile map[][n+1], the normal is 180 degrees.

           c) No.3 and No.4 are in the map tile map[m-1][], the normal is 90 degrees.

           d) No.3 and No.4 are in the map tile map[][n-1], the normal is 0 degrees.

 if No.2, No.3 and No.4 collide, the situation is the same as No.1.

in this way, there is no problem of finding the min value of the distances and the error when the distances are wrong, and can find all the normals correctly.

but there is also an optimization we can do, that is , if we already know that No.1 is colliding, the car is got to be turning clockwise, we don't even have to know the normals. likewise, if No.2 is colliding, the car is gonna rotate counterclockwise. this will make life a lot simpler.

but there is another problem, this problem is still the one I raised in Method 1, when No.1 is in the wall, it's possible that No.2 is also in the wall, this will cause the car to jitter, sometimes real badly. This will lead to the next improved solution.


3. collision timer

the reason why the object jittered is that the time difference is too small, and they just go back and forth a thousands of times, that means thousands of collisions per second. So to get rid of this, I set up a timer, if the collision time is smaller than 12 millisec, no typical collision reaction.


conclusion:

for a axis aligned wall collides with a rotating rectangle situation:


1. use vertex test

2. no need to generate normals

3. setup a timer to avoid jittering.


now that the collision detection is done, the rest of the work is to simulate the bounce reaction.this will be up to you, you can do a cheesy simulation, just rotate and stuff, or you can use momentum and angluar speed and angular acceleration to do a realistic simulation, that's all up to you now.

alpha version source code

| No Comments | No TrackBacks
I am gonna put my crappy alpha version source code here.

I am gonna do a lot of change in the code, so I figure that maybe I ll just put my original one online..

----
the math code here is too crappy, I am gonna use vector math
the collision detection code is not clever
the collision reaction is incomplete.


download:
Source Code

return to programming

| No Comments | No TrackBacks
I had a aweful week with 2 exams.... so busy....

I am glad that I finished all that.

this weekend I am gonna return to my favorite graphics and one school programming work.

plan:

*Homework 3
*collision code

*data structure

race game alpha test executable

| No Comments | No TrackBacks
alpha test features:
1. 2D texture tiling map
2. vertices collision detection
3. simple event trigger
4. color key texture loader


beta features predict:
1. event sound
2. menu
3. timer
4. more event (playability)
5. improved collision reaction code (realistic collision effects)

the program may require opengl to run, but I have included the dll inside the zip file, I don't know if it will work.


download:
race game alpha demo.zip

glaux, not a good choice

| No Comments | No TrackBacks
unfortunately, my executable couldn't run on school's computer, glaux.lib i used in my picture loading class is the problem, I looked on the internet, glaux is somehow an old fasioned library, it's huge and not useful. I decide to rewrite the bitmap loading library, write the glaux part by myself, so that I can hold the control of all my code.


finish alpha test version

| No Comments | No TrackBacks
i just finished a simple collision detection code, added it to the game, now the core of the game is finished, but the core still need to be improved and optimized.

the simple collision code is using the four vertices of the quad(the car), calculate each vertex's coordinate and see if it's in the range of the wall coordinates.
it's not accurate because it only use four vertices.
I need to read some articles on collision detection to improve this.

secondly, the bouncing effect is awful, i didn't use momentum and normals of surfaces, i just used a very stupid : speed=(-speed)/3;
this part can be hugely improved.

I feel happy that this is actually my very first project, very first test version, the first completed program!!

still a long way to go, carry on!

------------------------------------------------------------------
alpha version feature:
2D texture
tiling technic in generating the map
full screen,window option
semi-complete control system: thrust, break, handbreak
scrolling map (it's done using opengl's benifit)

ScreenShot:
screenshot_1.JPG

going to finish my first demo tomorrow

| No Comments | No TrackBacks
I v been back and forth.

use external bitmap loading library->write it myself
use box2d as my physics engine->write the collision detection myself

this process cost me a lot of time, but I think it's gotta be there on the learning curve. I have learned a lot of things from it, I won't regret it.

starting working on the collision test part now... hopefully I will finish it before dawn.

sat work log (03/28/09)

| No Comments | No TrackBacks
I v been busy all day. not so much items done though...
as time goes by, I m not on that fast learning curve now, all I am doing now is to practise my skill, I think it's good for my soul, after a fast learning process, you gotta sit down and write a lot of programs just to get to know em better, I am happy about it.
learning things deeply.

items done:
+ heap sort
+ improvement on self-made vector and string classes

unsolved problems,unfinished items:

1. box2d rendering program (didn't have time work on that today)
2. destructor of C++ class , low-level problem.

keep reading thinking in c++, it's just like a breeze, I love this book.

it's time to sleep now
PS i still can hear people talking outside.... it's 4AM!!!!! what the hell...... (i m so easily irritated now.... maybe too much time sitting in front of the desk... whatever...)


glut and box2d finally work together

| No Comments | No TrackBacks
glutTimerFunc() and world.Step() works fine, thanks to Tim Chan and his demo.

link:  http://www.box2d.org/forum/viewtopic.php?f=5&t=158

there is another problem with shape and body.(when I draw using body->getposition, it works well, but when I draw using shape->getverices, works weird, but it shouldn't be like that, I mean, drawing and physics simulation don't interfere with each other)
box2d seems to work in a strange way, or is it my mistake..

I m gonna find that out.

more gap to be filled

| No Comments | No TrackBacks

I need to learn more on topics concerning frame rate.

I v been trying to make my animation showing at a constant frame rate.

resource:
http://gafferongames.com/game-physics/fix-your-timestep/
this article can explain this very well, but I still need to understand some basic human vision and framerate related stuff, the knowledge in this area is a little messy.

texture tile technics

| No Comments | No TrackBacks
this is a basic thing to do, here is the work flow

1. using 1 and 0(use more numbers if there are more textures), draw a texture tile map, 2d array
2. load texture, and bind 1 and 0 to them.
3. read the tile map array, and draw the corresponding texture to the correct dimensions and position

you just need to pay attention to the coordinates assigned to the vertices, because your array is tile[y][x], you should pay attention that the first [y] is the y axis.

I will put the source code here, since there isn't many tutorials of tiling technics have source code provided.

please note: the whd_bitmap.h (written by me, a simple library, which can do color keying) can be used and modified freely.

tile_texture.zip

thinking in C++ is fantastic

| No Comments | No TrackBacks
so useful that it explained a lot of ambiguities...

fantastic book.


too busy a week

| No Comments | No TrackBacks
just checked what I need to do this week, geez, it's whole lot of things.....

I v been too focused on my project now that I almost forgot what is going on in school.

I don't know whether I will have enough time to do my own programming stuff, but I will try my best to make my weekend available.

good luck to me!


knowledge gap

| No Comments | No TrackBacks
I have been using glut as my library for almost two months, when I was trying to get Box2d to work well with opengl/glut, I couldn't make the time step right.

I then found that I have been ignoring one important thing, the CALLBACK function, or the pointer of function. glut uses this callback function everywhere.

I am gonna take a few days off from the graphics programming, and fill the gap.

there are two items on my current list

1. function pointer
2. understand the asm work behind function call

two resources:
http://www.newty.de/fpt/index.html
http://www.drpaulcarter.com/pcasm/

like jc said: Low-level programming is good for the programmer's soul.

a trick to control frame rate under GLUT

| No Comments | No TrackBacks
while searching on the internet looking for a simple solution to control framerate in GLUT, I found this trick

only need to use glutTimerFunc()
a lot of forum threads say this function is not good to measure and control frame rate, but it works very well for me, that's exactly the simple approach I need.

code is as following:

#define FRAMEPERIOD 16 //16 millisec, that is 1/60, which means it's a 60Hz animation

void the_function_that_performs_animation(int t)
{
    glutTimerFunc(FRAMEPERIOD,the_function_that_performs_animation,0);
   
    /* your animation code*/
   
    glutPostRedisplay();
}

then in your main(), call this timer function again, before glutMainLoop().

void main(...)
{
/*  your own glut code......
......
*/
    glutTimerFunc(FRAMEPERIOD,the_function_that_performs_animation,0);
    glutMainLoop();
}


it's extremely simple, isn't it?
it may not work well for big programs, but in my case, i only need to control a few moves, so it's what i need for now...

sunday plan

| No Comments | No TrackBacks
*control framerate using timerfunc
*construct a renderer class render graphics by box2d

as the program I write getting bigger and bigger, software engineering has became a every important topic! constructing class, constructing the whole software design properly. um... long way to go, I am glad I am on the right track.

color keying code

| No Comments | No TrackBacks
I decided not to use shader program for now, I am not familiar with it yet... that will be a subject for my next stage.

I implemented a class to load bitmap, pick the key color and set its alpha value to 0, then use alpha test to clear that color out.

here I used glaux.h library to load bitmap.

code is as following content:

    //load picture and set key color alpha value to 0
    void load(const wchar_t* image,const GLubyte& r,const GLubyte& g,const GLubyte& b)
    {
        AUX_RGBImageRec *bitmap_RGB = auxDIBImageLoad(image);
        GLubyte *bitmap_RGBA = NULL;

        if (bitmap_RGB!=NULL)
        {
            int imageSize_RGB=bitmap_RGB->sizeX*bitmap_RGB->sizeY*3;
            int imageSize_RGBA=bitmap_RGB->sizeX*bitmap_RGB->sizeY*4;

            bitmap_RGBA=new GLubyte[imageSize_RGBA];

            int i,j;

            for(i=0,j=0;i<imageSize_RGB;i+=3,j+=4)
            {
                if ((bitmap_RGB->data[i]==r) // if pixel color equals to color key
                    &&(bitmap_RGB->data[i+1]==g)
                    &&(bitmap_RGB->data[i+2]==b))
                {
                    bitmap_RGBA[j+3]=0;
                }
                else
                {
                    bitmap_RGBA[j+3]=255;
                }
                bitmap_RGBA[j]=bitmap_RGB->data[i];
                bitmap_RGBA[j+1]=bitmap_RGB->data[i+1];
                bitmap_RGBA[j+2]=bitmap_RGB->data[i+2];
            }
        }
        data=bitmap_RGBA;
        width=bitmap_RGB->sizeX;
        height=bitmap_RGB->sizeY;
        delete bitmap_RGB;
    }

struct:

struct whd_bitmap
{
    int width;
    int height;
    GLubyte* data;
}

load() is a member function

one day off....

| No Comments | No TrackBacks
no work log today....

have to work in HUB twice today... er..... tired..

work log (03/19/09)

| No Comments | No TrackBacks
+bitmap loading
+2d texture
+a little blending

still got one problem: the color keying of the texture

there are two ways to solve it.
1) rewrite the bitmap loading code, examine every pixel of the bitmap file, if it's the color key, then set its alpha channel to 0.0.

2) use GLSL, write two shader program to discard the color key pixel
varying vec2 vTexCoord;
void main(void)
{
vTexCoord = gl_MultiTexCoord0.xy;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Vertex Shader Source Code

sampler2D myTexture;
varying vec2 vTexCoord;
void main (void) 
{
vec4 color = texture2D(myTexture, vTexCoord);

if (color.rgb == vec3(1.0,0.0,0.0))
discard;

gl_FragColor = color;
}
 
Fragment Shader Source Code

Now the problem becomes running the opengl program properly.
I still got LNK2001 errors while using GLEE.h
this shouldn't be a hard problem though...
I will try both ways and see how it goes.


solve two animation in one window

| No Comments | No TrackBacks
I got a response from GameDev today about my problem days ago with the multiple animation scenes displaying within one window.
he suggested me to use glScissor()

it really worked

post the code down here:

void display1()
{
    glViewport(0,0,800,800);
    glLoadIdentity();
    gluLookAt(20.0,3*K,50.0,0.0,2*K,0.0,0.0,1.0,0.0);
    drawScene();
   
    glEnable(GL_SCISSOR_TEST);
    glScissor(0,0,200,200);
    glViewport(0,0,200,200);
    glLoadIdentity();
    gluLookAt(20.0,3*K,50.0,0.0,2*K,0.0,0.0,1.0,0.0);
    drawScene();
    glDisable(GL_SCISSOR_TEST);
    glutSwapBuffers();
}

I never heard of this function before, it's very useful..

glad I got the answer to this problem.


the man page for glScissor()
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/scissor.html

work log (03/18/09)

| No Comments | No TrackBacks
+opengl lighting functions (basics)
+opengl displaylist
+opengl bitmap fonts

exsisting problems:
I posted a thread on GD asking if there is a way to use double buffered GLUT to display two animated scenes in one window. here I used two different viewport.
this idea comes from the redbook, it mentioned that we can create multiple viewports to display the same scene looking from different views, but it never mention how to make the animation smooth after all these multiple viewport thing.

still waiting for an answer from gamedev.

rambles on JC and what JC has taught me

| No Comments | No TrackBacks
I was wandering on the internet when I found one interesting interview of JC.

something he talked about "focus" impressed me much. I still remember the first time I played DOOM on my friend's computer when I was in elementary school, um... when was that... I think it was around 1997. yeah, I had my first computer in 1998, back then the only thing I could do is playing around with DOS and Windows 3.0, the only things that I had seen on computer is that Teris game on my DOS system. DOOM really impressed me much.
I am aware that this interview was taken in 2000, just 2 years after I had my computer, I knew nothing about programming and stuff...haha~~ wow~speaking of that time....
i think I went too far... anyway, when I read this interview of him today, I can't help thinking about the things JC has taught me and the most important one among them is "Focus!"

here I wanna quote a couple of lines from the interview::

"FS: You have a special focus, an inspiration - how you can improve an algorithm or something. How often do these epiphanies come to you?

John: Well, I think a lot of people put too much emphasis on the epiphanies. Epiphanies are there, you do get them where you see clearly into something and all that. But it really is true that most great works aren't a result of epiphanies, they're the result of lots of hard labor. That is a trap that a lot of people fall into where you think that the epiphany is the important thing. Sometimes it is, but in 95% of cases it's just a matter of smooth, calm integration of everything you know.

It's not the one brilliant decision, it's the 500 smart decisions that really make things good. It's more a matter of being able to keep making smart decisions. Making one brilliant decision and a whole bunch of mediocre ones isn't as good as making a whole bunch of generally smart decisions throughout the whole process. And there's so many of them that have to be made.

Even at the end of Quake 3, I had a to-do list of a thousand things that could potentially be improved on. So it's a matter of going through and knowing all these things that could be done, and prioritizing what the "sweet spots" are. Like "This amount of effort would get this batch of things done and it would have this side effect." Or "it would take all day to do this thing but it would probably destablize something else, so I'm not going to do it."

I definitely enjoy the epiphanies when they come - when I can be working on something and just realize that there's a much better way of doing it. That's very rewarding but I can't say that those happen every day. To a lesser degree, there's some insight where I can actually come home and tell Anna, "I figured something new out today!" That happens fairly often, and that's good.

"


plus something Abrash wrote about him:

"When I left work one Friday, John was preparing to try to get the direct-BSP approach working properly over the weekend. When I came in on Monday, John had the look of a man who had broken through to the other side--and also the look of a man who hadn't had much sleep. He had worked all weekend on the direct-BSP approach, and had gotten it working reasonably well, with insights into how to finish it off. At 3:30 AM Monday morning, as he lay in bed, thinking about portals, he thought of precalculating and storing in each leaf a list of all leaves visible from that leaf, and then at runtime just drawing the visible leaves back-to-front for whatever leaf the viewpoint happens to be in, ignoring all other leaves entirely. "

yes, epiphanies are not coming from some kind of genius nature of someone, they come from hard work, days, months even years of hard work. which leads to the second most important thing JC taught me, "hard-working".

not only should we be passionate about and focus on the things we are interested in, also, we should work hard on it. instead of just walking casually on the surface, we should dig into the earth, into the core. That's what makes him JC.

I am far from perfection, but I am on the right track, I can be focused, I can work hard.

Work log (3/17/09)

| No Comments | No TrackBacks
this morning I reviewed all the matrix transformation and translation features of opengl, did a little programming to perfect my skill of the basic stuff.

I printed Michael Abrash's articles on the technology behind Quake. They dealt with visible surface determination and stuff. This reminded me of my early programming on Bresenham's line drawing algorithm. I alway have thought that JC must use some, i don't know, higher programming method or approach or some well designed, not known by me, libraries, never those seemed-basic concepts. now i learned that optimized gaming program requires looking into the very basic part of every detail, including line drawing and antialiasing algorithms. These are the most important things.

I don't know if I still want to use darkgdk anymore, but I will keep up the learning pace on opengl and glut.

I think I can use darkgdk with box2d now, but still I got one problem which is darkgdk doesn't allow me to set the Sprite's position after it's initialized, this makes it harder to use box2d as a background physics engine. on this level, I prefer opengl.

say no more, i still got a lot of school work to do this week. let's hope for the best that I finish some code on opengl using texture this week. (that's all I need for the game for now)

I wanna thank my baby for cheering me up

| No Comments | No TrackBacks
Thank you, my baby, I will try my best, do my best!
Thank you for cheering me up!

Love you

registered for Quakecon

| No Comments | No TrackBacks
I am excited to be part of Quakecon this year, it's been held for years, finally I got the chance to see it in person.

"You registered for QuakeCon on March 16, 2009, 12:44 pm. You were # 4043 to sign up for QuakeCon!"

August 13-16

hopefully I am gonna bring something with me to show everybody, I have my finger crossed for that. Fight on, Joey.

box2d library seems to solve collision nicely

| No Comments | No TrackBacks
I will come up with a test code within this week

a little thought

| No Comments | No TrackBacks
//decent way
box2D- physics
opengl- general rendering
freeglut- window handling, input, output etc..
FreeType- font handling
openIL(DevIL)- handle image input
SDL- handle audio input and output

//time saving way
darkGDK


right now, for darkGDK, i have to deal with the linking problem when using Box2D with it. (Solved//031609,5:56am)

rewrote the code using DarkGDK

| No Comments | No TrackBacks
after some trials and errors, I rewrote the core game code using DarkGDK, it saves some effort of learning how to load images in OpenGL and dealing with fonts, the only problem now is the collision detection part.

I am not sure "Sprite" is the right way to build walls in the game for collision detection. It seems that the "dbSpriteCollision()" function is a little tricky. I am thinking about write my own code for collision detection.

the previous problem can lead to the question of "what is the structure of the level map".

Right now, I am thinking rebuild the map using texture and terrain functions in DarkGDK, maybe using the matrix feature of it. Still, I am not positive about this. Still needs to try.

Of course, I am not gonna stick to this dev kit, once I gain deeper understanding of Opengl, i will rewrite the code in my own way. Using the code others build for you is convienient and nice, but it's hard to optimize the game, cuz the dev kit is already designed.

more progress will be updated.

finish physic core code

| No Comments | No TrackBacks
when I was on the plane, I finished the physic core code, acceleration effects for my car racing game.

a few places need to be improved.
        1. it may be easier to use opengl matrix to do the rotation and translation
        2. if I can control the FPS, that ll be better

1st version code: (physics part)
    // key reaction
    if (keyPress['w']==1) //thrust
    {
        if (aCar.speed<aCar.topspeed)
            aCar.speed+=aCar.acceleration;
        aCar.cY+=aCar.speed*sin(aCar.angle);
        aCar.cX+=aCar.speed*cos(aCar.angle);
    }
   
    if (keyPress['s']==1) //if press break
    {
        if (int(aCar.speed>0))
        {
            aCar.speed-=aCar.deceleration;
            aCar.cY+=aCar.speed*sin(aCar.angle);
            aCar.cX+=aCar.speed*cos(aCar.angle);
        }
    }
    else
    {
    if (keyPress['w']==0) //when there is no thrust,no break
    {
        if (int(aCar.speed>0))
        {
            aCar.speed+=deceleration_ground;
            aCar.cY+=aCar.speed*sin(aCar.angle);
            aCar.cX+=aCar.speed*cos(aCar.angle);
        }
        }
    }

    if (keyPress['a']==1) //turn left
        aCar.angle+=0.001;

    if (keyPress['d']==1) //turn right
        aCar.angle-=0.001;


for the second part, I found some code using just GLUT can do the FPS thing, I will look into that later.

work log (3/5/2009)

| No Comments | No TrackBacks
+ GLUT keyboard functions
+ OpenGL viewing functions

P.S: physics 213 exam tonight, wish myself good luck...

I am so Stupid!

| No Comments | No TrackBacks
Matrix is not vectors!

Man, I wish I realize this earlier.

decide to skip the rest of Chap 2

| No Comments | No TrackBacks
It really bugs me that I cannot view my model correctly.
I should learn Chapter 3 first.

PS. it's good that my toothache is getting better now...

my own notes on vertex array

| No Comments | No TrackBacks
I did a little vertex array summary:

As in the work flow of coding:

I. Enable Feature
   glEnableClientState()

   e.g glEnableClientState(GL_VERTEX_ARRAY);
         glEnableClientState(GL_COLOR_ARRAY);

II. Specify Data for Arrays
    (1) separate the data in different arrays
         e.g   //enable GL_COLOR_ARRAY and GL_VERTEX_ARRAY first 
                 static GLint vertices={x,x,x,
                                                x,x,x,
                                                x,x,x}; // 3 points vertex data
                 static GLfloat clors[]={x,x,x,
                                                 x,x,x,
                                                 x,x,x}; // 3 points color data
                 glColorPointer(3,GL_FLOAT,0/*stride*/,colors);
                 glVertexPointer(3,GL_INT,0,vertices);

    (2) all data in ONE array   //get use of stride
         e.g.  static GLfloat interwined={x,x,x,y,y,y,
                                                      x,x,x,y,y,y,
                                                      x,x,x,y,y,y,}; // all the x are vertex data, y are color data
               glColorPointer(3,GL_FLOAT,6*Sizeof(GLfloat),&interwined[3]); //color starts at [3]
               glVertexPointer(3,GL_FLOAT,6*Sizeof(GLfloat),&interwined[0]); //vertex starts at [0]

III. Dereferencing and Rendering
    (1)  dereference SINGLE element
          e.g // use [2],[3],[6] the 3 data to draw a triangle
               glBegin(GL_TRIANGLES);
                  glArrayElement(2);
                  glArrayElement(3);
                  glArrayElement(6);
               glEnd();

    (2) dereferencing a SEQUENCE elements (sequentially)
        
         1) glDrawArrays()
         e.g // use [0] [1] [2] to draw a triangle
               glDrawArrays(GL_TRIANGLES,0,3);
              
         EQUALS TO:  glBegin(GL_TRIANGLES)
                                     for (i=0;i<count;i++)
                                          glArrayElement(i);
                               glEnd();
          2) glMultiDrawArrays() //combine several glDrawArrays() into ONE function
          e.g // use [0]~[2], [3]~[5],[6]~[8] to draw three triangles
               GLint first[]={0,3,6};
               GLsizei count[]={3,3,3};
              
                glMultiDrawArrays(GL_TRIANGLES,first,count,3/*draw 3 triangles*/);
   
   (3) dereferencing elements NON-SEQUENTIAL ("hopping arround" as metioned in redbook)
       
         1) glDrawElements()
         e.g // use [2],[3],[5] to draw a triangle
              GLubyte indices[]={2,3,5,0,0,0}  //the datatype can also be GLuint,GLushort
              glDrawElements (GL_TRIANGLES,3/*read 3 data*/, GL_UNSIGNED_BYTE,indices);
         2) glMultiDrawElements() //combine several glDrawElements() into ONE function
         e.g // draw two polygons out of data1[] (take 5 data out),data2[](take 6 data out)
              // data1[] and data2[] are of Glubyte type in this example
              GLsizei count[]={5,6,0,0};
              GLvoid* indice[]={data1,data2}; //array of POINTERS
              glMultiDrawElements(GL_POLYGON,count,GL_UNSIGNED_BYTE,indice,2/*read 2 times*/);
        3) glDrawrangeElements() //Specify range to PreFetch
            /*
               I didn't look carefully into this function, because I didn't get the advantage of this
               function, I looked arround on the Internet, found something, I ll just put the link here
               for future reference
            */
            http://www.gamedev.net/community/forums/topic.asp?topic_id=192659


Work log (2/28/2009)

| No Comments | No TrackBacks
* OpenGL Stipple Line
* OpenGL Stipple Polygon
* OpenGL Polygon details, functions, experiement

* Email Checker 2.0 (CMPSC122 HW)

PS. I am hungry! only had one miso soup today.... damn toothache...
finally got FL Studio working, turns out it's caused by Windows' Data Execution Prevention(DEP)...

it's late ,time to sleep.. :-)

Shoot, sickness....

| No Comments | No TrackBacks
I felt really bad today, a bump on my gum, fever, a bad cold.....

I only had one miso soup in that Chinese Restraunt....

so hungry now,, but I cannot eat, because of my toothache...


I was planning to finish stippled line today..but didn't... I hate I cannot finish my plan...

The good news is, after a whole day of rest, I feel better now, if I don't close my mouth make the teeth meet, I won't feel the pain in my mouth....

Gotta sleep now, I have to finish stippled line and stippled polygons tomorrow!!


two slack days

| No Comments | No TrackBacks
These two days, i v been working on school work, really didn't arrange time to do graphics programming.... uh.... not an excuse....

I am now reading stuff related to geometric primitives in opengl, this weekend, i ll do some programming around this topic...

I have chosen my final project of this semester as glKeen, a remade of Commander Keen using opengl, it's a bit challenging for a freshman.... I ll try my best....good thing is i won't be working on curves, which I think is tedious to work on.

I ll keep updating entries...

happy about wireless network in the early morning

| No Comments | No TrackBacks
Perhaps I ll just get up early, maybe adjust my time schedual?

In order to drive myself forward on this learning path, I plan to record my everyday work done in "work log" category. too much time has been wasted before.


dreamed of John Carmack

| No Comments | No TrackBacks
I duno whether it's because I am too into graphics these days or he just jump into my dream to answer my question.
Last night, he appeared in my dream, for the first time. I remember asking him "how do you know your next direction in technology, how do you know if you can finish your goal or not, you are a pioneer, i mean", he might think it's a  ridiculous question, smile and answer, "when you are there, you know, right away"

I may have wondered about the answer to this question, but I never thought this through. But it's just right there in my dream, the answer came from myself. Have I already known the answer?

Dream is a magical thing, maybe I already knew that subconsciously, I just didn't know that I knew.

weird thing.

opengl data types

| No Comments | No TrackBacks
OpenGL
Data Type
Minimum
Precision
Description
GLboolean 1 bit Boolean value
GLbyte 8 bits Signed 2's complement binary integer
GLubyte 8 bits Unsigned binary integer
GLshort 16 bits Signed 2's complement binary integer
GLushort 16 bits Unsigned binary integer
GLsizei 32 bits Non-negative binary integer size
GLbitfield 32 bits Bitmask value
GLfloat 32 bits Floating-point value
GLclampf 32 bits Floating-point value clamped to [0.0, 1.0]
GLint 32 bits Signed 2's complement binary integer
GLuint 32 bits Unsigned binary integer
GLenum 32 bits Enumerated type
GLdouble 64 bits Floating-point value
GLclampd 64 bits Floating-point value clamped to [0.0, 1.0]

Just a reminder

First good taste of Macro in C++

| No Comments | No TrackBacks
Today, I wrote a circle generating program, I have to draw all those symmetrical points many times, but the code is the same.. First thing come to my mind is to write a drawing function, then there is the problem of using variables, scope things, and so on....  then it turns out using the macro feature in C++, is the best way.

#define drawpoint \
    {\
        glVertex2i(x+xc,y+yc);\
        glVertex2i(y+xc,x+yc);\
        glVertex2i(y+xc,-x+yc);\
        glVertex2i(x+xc,-y+yc);\
        glVertex2i(-x+xc,-y+yc);\
        glVertex2i(-y+xc,-x+yc);\
        glVertex2i(-y+xc,x+yc);\
        glVertex2i(-x+xc,y+yc);\
    }

so easy!

When I was introduced to this feature, I didn't notice its advantages... now I do....
haha~~

incompatibility between glut.h and VS .NET

| No Comments | No TrackBacks
I encounter a compiling problem with glut.h

which says:
".... error C2381: 'exit' : redefinition; __declspec(noreturn) differs"
"....include\gl\glut.h(146) : see declaration of 'exit' "
(omitted the directory path)

I found two ways to solve this problem from the Internet:

1. just reverse stdlib.h and glut.h position
    in my case reverse iostream and glut.h
    put iostream or stdlib.h before glut.h

2. or
To fix the error, right click on the project name in the Solution Explorer tab and select Properties -> C/C++ -> Preprocessor -> Preprocessor definitions and append GLUT_BUILDING_LIB to the existing definitions, seperated by semicolons.

Although in my case, the second method didn't work
I got a bunch of linking errors
put them here just for future reference:

1>main.obj : error LNK2019: unresolved external symbol _gluOrtho2D@32 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glFlush@0 referenced in function "void __cdecl lineSegment(void)" (?lineSegment@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl lineSegment(void)" (?lineSegment@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glVertex2i@8 referenced in function "void __cdecl lineSegment(void)" (?lineSegment@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl lineSegment(void)" (?lineSegment@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl lineSegment(void)" (?lineSegment@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl lineSegment(void)" (?lineSegment@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol _glutMainLoop@0 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glutDisplayFunc@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glutCreateWindow@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glutInitWindowSize@8 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glutInitWindowPosition@8 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glutInitDisplayMode@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glutInit@8 referenced in function _main


link to this solution:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/4cf463c1-5fee-4daa-b135-be8b06ab7f8f/

OpenGL library in Windows

| No Comments | No TrackBacks
unfortunately, my VS 2008 didn't come with OpenGL library, anyway, I cannot find it.
After searching the web, opengl library is really hard to find all those components at one time.

So, I list all the places to look for it down here.

1. we need Microsoft's implementation of OpenGL, simply go to microsoft website, and find opengl for win95.
The link is: http://download.microsoft.com/download/win95upg/info/1/W95/EN-US/Opengl95.exe
I cannot guarantee it will be working in the future.
This file contains:
        GL.h, GLAUX.h, GLU.h (which go to GL folder under VC include)
        GLAUX.lib,GLU32.lib,OPENGL32.lib (which go to lib folder under VC)
        GLU32.dll, OPENGL32.dll (which go to system32 folder)

2. besides the basic OpenGL library, we also need GLUT, a very popular extension
    we can obtain GLUT in Nate Robins' webpage
    link: http://www.xmission.com/~nate/opengl.html
after downloading bin files, put .h in include/GL , and put .lib in the lib folder like before

3. sometimes we need GLEE, or other great extensions
    we can simply find those on OpenGL official site
link:http://www.opengl.org/sdk/libs/

4. additionally, we can find ATI's extension of OpenGL in its developer's site
link:http://developer.amd.com/gpu/radeon/Radeon3DProgramming/Pages/default.aspx

(interestingly enough, I myself, always wanted a Nvidia Card, years passed, I kept getting ATI card)

5. Nvidia's extension
link:http://developer.nvidia.com/object/nvidia_opengl_specs.html


I think it's enough for now, we can do some great things out of those fantastic libraries now...

Start working!