겨울팥죽 여름빙수
Android ndk, unicode to utf-8 or utf-8 to unicode

1. utf-8 to unicode I referenced below site http://en.wikipedia.org/wiki/UTF-8 wstring Utf8ToUnicode(const string& source_str) { int dest_len = 0; int source_len = source_str.length(); const char* source = source_str.c_str(); wchar_t* dest = new wchar_t[source_len]; wstring value; for (int i = 0; i

article thumbnail
Android, NDK Log using __android_log

1. android/log.h In ndk library provide log functions that can be seen in LogCat. First you have to include . #include You can use two functions [__android_log_write] and [__android_log_vprint]. If you want to write log like printf, Use [__android_log_vprint]. It support parameters like %d, %f, %s.etc else [__android_log_write] only send a message. Below show example using [__android_log_write] ..

article thumbnail
Android, Draw text using system font OpenGLES 2.0

1. Typeface you can get typeface info by [Typeface.createFromAsset] method. You don't call this method every frame. Because it happen memory leak problem, so I recommend to use Map class to Manage font data. Below show code using Typeface.createFromAsset. Hashtable m_font_type_face = new Hashtable(); private ResourceManager() { m_font_type_face.put("CORBEL.TTF", Typeface.createFromAsset(MainActi..

article thumbnail
Android, NDK OpenGLES2.0 Texture

1. Load texture I used Android BitmapFactory to decode PNG texture. If you want one source multi flatform, Use libpng. This writing show example BitmapFactory decoding. First we have to load image. Theretofore we have to decide resource foloder. A. res/raw Many developer use assets foloder to manage resource, but I decide resource folder res/raw because res folder managed to R.java, there could ..

article thumbnail
OpenGLES2.0 GLSL, 2D Basic shader

1. Outline Recently, many developer use OpenGLES 2.0 to make a 2d graphics game. But it have little difficult because of OpenGLES1.0 & OpenglES 2.0 graphic-pipeline difference. Especially, when we meet GLSL shader first-time, it give little fear of programming. Follow writing show shader for someone who want to make 2d graphic game or app. 2. Vertex Shader vertex shader handle each vertex infos ..

article thumbnail
OpenGLES 2.0,GLSL lighting code

1. outline OpenGLES 2.0 don't support glLightf. So developer have to make light effect using glsl shader. Following content don't explane about OpenGL2.0 functions like glGetUniformLocation, glGetAttribLocation, ect. 2. Light formula Below formual show graphics expression of light in 3D graphics. I = Global Ambient + Emission + Ambient + Diffuse + Specular = Ga + Me + 1/a+bD+cD^2(Ka*Ia + Kd*Id(N..

article thumbnail
GLSL, OpenGLES2.0 glFog

OpenGLES2.0 not support glFog. So If you want fog effect, you have to a code using glsl. 1. Calculate GL_FOG_MODE have 3 modes. GL_LINEAR : f = (end - z)/(end - start) GL_EXP : f = exp(-density*z) GL_EXP2 : f = exp2(-(density*z)*(density*z)) Color = Color_source*f + (1-f)Color_fog start - fog start distionce(usually 0.0f) end - fog's end distance (usually 1.0f) Color_source is fragment color. Co..

article thumbnail
NDK AdMob, Can't see admob on Framelayout

I added admob view to Android framelayout. I couldn't see ad. I think that admob view is not disappered, because when I click admob location, actvity is changed to show advertisement. To resolve problem, I applied background color to admob view. Below show my code. Colored By Color Scripter™1234567891011121314//-------------------------------------------------------------------------------------..

GLSurfaceView & GLRenderer 설정

1. MainActivity 아래 코드를 보면 알 수 있듯이, MainActivity자체는 별로 하는 일이 없다. setContentView로 화면에 보여질 뷰를 MainGLSurfaceView로 설정한다. openGLVerstion는 MainGLSurfaceView 클래스 내에서, GL버전을 설정하는데 쓰인다. public class MainActivity extends Activity { public static MainGLSurfaceView view; public static Context context = null; public static final intopenGLVerstion = 2; @Override protected void onCreate(Bundle savedInstanceStat..

article thumbnail
이클립스 NDK설정

1. NDK 프로젝트 생성 일단 안드로이드 SDK, NDK, 이클립스를 모두 다운 받는다. - 이클립스 + SDK 다운로드 - NDK 다운로드 - cygwin설치(윈도우 경우) - Eclipse ADT 설치, CDT 등 설치 2. c++ 프로젝트 생성 - 빈 이클립스 프로젝트 생성 - 프로젝트 Right클릭 -> Android Tools -> Add Native Support클릭 - jni폴더 등이 생성되면, 프로젝트를 빌드한번 해주자. - 이렇게 하면 아래 그림과 같이, 기본적인 설정이 끝난다. 3. 추가적인 설정 - NDK 디버깅. 프로젝트 속성 -> c/c++ build -> Build command ndk-build NDK_DEBUG=1 로 변경(추후 추가 설명) - 프로젝트 속성 -> c/c++..