Saturday, March 22, 2014

Shader debugging

It is for ES 2.0, maybe also works for desktop GL.Replace LOG_PRINT with your own log printing API.

glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &stat);
if (stat == GL_FALSE)
{
   LOG_PRINT("SDL_LOG", "Error: Vertex shader compiling\n");
   GLsizei iLength, slen = 0;
   glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &iLength);
   GLchar* compiler_log = new GLchar[iLength];
   glGetShaderInfoLog(vertexShader, iLength, &slen, compiler_log);
   LOG_PRINT("SDL_LOG", "%s\n", compiler_log);
   delete[] compiler_log;
}


High cpu usage when idle, win 8

If you find your fan is noisy while idle, M$ may run its famous auto maintenance without your permission. This auto maintenance may be turned on "automatically" during the system update. I do not know why M$ likes it so much.


The following is the way to turn it off.



1. Press the + R keys to open the Run dialog, type taskschd.msc, and click/tap on OK.

2. In the left pane of Task Scheduler, click/tap on to expand Task Scheduler Library, Microsoft, Windows, and TaskScheduler. (see screenshots below)

3. In the middle pane of TaskScheduler, either right click on or select the Regular Maintenance task, and do step 4 or 5 below for what you would like to do. (see screenshots below)

Tuesday, March 18, 2014

android NDK file io with SDL2

The resource management of NDK is ****** unfriendly. The files in the asset fold will be zipped, can not be accessed by NDK directly. Fortunately, SDL2 has file io wrapper. Here is a sample to read a file. Note that, the root path is asset.

SDL_RWops *file = SDL_RWFromFile("yourfile.txt", "r");
size_t len;
len = SDL_RWseek(file, 0, SEEK_END);
SDL_RWseek(file, 0, SEEK_SET);
char * fileChar = new char[len + 1];
SDL_RWread(file,  fileChar, sizeof(char), len);
fileChar[len] = '\0';
SDL_RWclose(file);

Monday, March 17, 2014

Kernel headers for version 3.x-xxxx were not found. If you installed them

One time, I updated my kernel, I could not use vmware 9. It always showed "Kernel headers for version 3.x-xxxx were not found. If you installed them". Archlinux wiki can not solve this.

I found the solution in a post. The kernel version.h file is relocated to some where else since some version. vmware can not find it.

ln -s /usr/lib/modules/3.13.6-1-ck/build/include/generated/uapi/linux/version.h /usr/lib/modules/3.13.6-1-ck/build/include/linux/version.h

Sunday, March 16, 2014

HUD/GUI with pure opengl calls

I am tired looking for good cross-platform gui libs. So far none of existing libs satisfies me.

cocos2d-x (MIT): Perfect for 2D , but I have to figure out how to draw 3D there.
librocket (MIT): Works with existing projects, but stops updating.
MyGUI-es2 (MIT): Have not tried.

I decide to reinvent the wheels.I could do GUI or HUD with only opengl calls. The basic ideal is that, draw 3D first normally, then disable depth related features and draw 2D stuff on the top. I tested with triangles, it seems working. Here is the pseudo-code.

//set your perspective matrix
glUniformMatrix4fv(u_matrix, 1, GL_FALSE, pers_view_mat.data());

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

{
    //3D draw
}
//set your orthogonal matrix
glUniformMatrix4fv(u_matrix, 1, GL_FALSE, orthoMat.data());
{
   glDisable(GL_DEPTH_TEST);
   glDepthMask(GL_FALSE);

   //2D draw

   glEnable(GL_DEPTH_TEST);
   glDepthMask(GL_TRUE);
}

Saturday, March 15, 2014

Importing android project into eclipse gets "Invalid project description"

It could have something to do with git. Moving the whole folder to a sub folder solves the problem.

https://stackoverflow.com/questions/12677093/invalid-project-description-when-importing-project-into-eclipse

Wednesday, March 12, 2014

cocos2d-x with custom gl es 2.0 code

cocos2d-x is a great 2D engine. It is based on ES 2.0. cocos2d-x has its own 2D wrappers on top of ES 2.0 to make it across platform. As long as there is already an EGL context, it is possible to add your own opengl code, or even other 3D engine.

The straight forward way is to override the draw function of a layer class and attach it to the scene. Just put all your gl code into function draw, such as shaders, VBO, and so on. It works. I just tested with a simple triangle though. Howerver, there problem is that my layer overrides everything. The original sprites and fonts are all covered. This is not what I need. I plan to re-use those GUI on top of my own 3D layer.

There is also a post in their forum talking about embedding horde3d to cocos2d-x.

Monday, March 10, 2014

flann 1.8.4 fails on win x64

I tried all I could, but failed.

mingw-64bit, vs 2012, vs 2013, with/without CUDA. 1.8.4 release or latest git. All failed.

Maybe I have to roll back to 1.7 on windows.

Saturday, March 8, 2014

run bat file in msys

I tried to run android.bat from the android-sdk for windows within msys shell. But the windows bat syntax is not working. I found a way after googleing. The following commands work.

cmd /c "your.bat [args,...]"


cocos2d-x ant debug error

If I follow the cocos2d-x tutorial, I receive an error while doing ant debug to generate the apk.

Setting the android sdk dir fixes it.

ant debug -Dsdk.dir= %ANDROID_SDK_ROOT%
or
ant debug -Dsdk.dir= $ANDROID_SDK_ROOT