2014년 7월 9일 수요일

Cocos2d-x



Cocos2d-x 의 특징









Cocos2d-x 는 게임엔진이다.



모바일디바이스는, PC 에 비해서, 하드웨어 수행성능이 현저히 떨어진다.

이런 환경에서는, 앱의 크기, 랜더링 속도(FPS) 가 매우 제한적이다.


스마트폰에서 실행되는 게임엔진은 많지만, 대부분은 앱의 크기가 매우 커진다거나,
랜더링 속도가 매우 느리다는 특징이 있다.

Cocos2d-x 는 앱의 크기와 랜더링 속도에서 사용가능한 수행성능을 보여준다.




Cocos2d-x 의 특징은 다음과 같다.

1. 오픈소스이다. 상용앱을 만드는데 라이센스 문제가 없다.


2. C++ 로 개발가능하다. 안드로이드에서 Java 가 아닌 C++ 을 사용할수있다.


3. 문서, 튜토리얼, 커뮤니티가 활발하다. 즉, 학습하는데 충분한 문서를 구할수있다.
      예를들어, C++ 로 개발하면서 AdMob 같은 Java 라이브러리를 연동하는
      방법에대한 문서가 이미 존재한다.


4. C++ 이므로, 당연히 build target 에 대한 문제가 있다.
    Native code 이므로 CPU Architecture 에따라 따로따로 빌드해야한다. ( arm, x86, mips )
    이부분에 아픔이 있다.



5. Native code 이므로, Java 보다 코드의 복잡도가 높아진다.
    메모리 관리에대한 위험도가 높아진다.
    개발자는 머리가 좀더 아파진다.




6. Cocos3D 가 개발중이다. 출시 예정일은 2015 년. !!!!

    현재는 3D Extension 으로 2.5D 게임 개발이 가능하다.





















Cocos2d-x 의 cpp-test 를 Eclipse 에서 run 하는 방법


http://cocos2d-x.org/wiki/How_to_Build_an_Android_Project_with_Eclipse



Eclipse에서 Cocos2d-x Sample 을 build 하고, android phone 에서 실행시키는 과정.



<전제조건>
다음 항목이 설치되어 있어야한다.

Cocos2d-x
JDK/SDK 1.6+
NDK r9d+
Apache Ant
Python 2.7.5
Eclipse with ADT Bundle

Windows 콘솔에서 android-build.py 를 사용하여 Libcocos2dx 가 빌드되어있어야한다.



1. Eclipse 에서 proj.android 를 open 한다.

Eclipse 를 실행시킨다.

Package Explorer 에서 right click 한후, Import... 를 선택한다.

Existing Android Code Into Workspace 를 선택하고 Next 를 선택한다.






다음 폴더를 선택한다.

[cocos2d-x directory]\tests\cpp-tests\proj.android


Finish 를 선택한다.



2. Libcocos2dx project 를 import 한다.

위와 동일한 방법으로 다음 위치에 있는 프로젝트를 import 한다.

[cocos2d-x directory]\cocos\platform\android\java




3. build 하고 run 시켜본다.


Run as .. -> Android Application



















2014년 7월 7일 월요일

Cocos2d-x 의 cpp-test 를 android phone 에서 run 하는 방법


(http://cocos2d-x.org/wiki/How_to_run_cphttp://cocos2d-x.org/wiki/How_to_run_cpp-tests_on_Androidp-tests_on_Android)



윈도우 콘솔에서 Cocos2d-x Sample 을 build 하고, android phone 에 설치하는 과정.




<개발환경 전제조건>

아래 소프트웨어가 이미 설치되어 있어야 한다.

Cocos2d-x
Java JDK/SDK
Android SDK
Android NDK r9d+
Apache Ant
Python 2.7.5


<환경변수>
시스템 환경변수에 다음 변수가 설정되어 있어야 한다.

COCOS2D_CONSOLE_ROOT
NDK_ROOT
ANDROID_SDK_ROOT
ANT_ROOT

설정되어있지 않다면 Cocos2d-x 폴더에서 setup.py 를 실행시켜 설정한다.



<빌드>
Cocos2d-x Sample 을 build 하려면, android-build.py 를 사용한다.


android list targets

python android-build.py -p 19 cpp-tests



<설치>
빌드된 apk 파일을 android phone 에 설치하려면, adb 를 사용한다.

adb install CppTests-debug.apk











Windows 에서 Cocos2d-x 시작하기

<Windows 에서 Cocos2d-x 시작하기>


Cocos2d-x 설치후, sample 프로젝트를 실행해보는 과정.


1.Cocos2d-x 최신버전을 다운받는다.

2. build 폴더에 있는 cocos2d-win32.vc2012.sln 파일을 Visual studio 2012 에서 연다.

3. cpp-tests 프로젝트를 시작프로젝트로 설정(Set as StartUp Project)하고, build, run 해본다.









새 프로젝트 만드는 방법.


새 프로젝트를 만들때, Visual Studio 의 기존 Wizard 방식 ( File / New / Project... ) 은 아직 존재하지 않는것으로 보인다.
대신 cocos console 을 사용한다.
cocos console 은 Python 이 설치되어 있어야 한다.



1. Python 이 설치되어 있어야 한다.

2. 시스템 환경변수 Path 에 <cocos console> 경로를 넣어주어야 한다.

       "[cocos2d-x root]\tools\cocos2d-console\bin\"


경로 설정이 제대로 되었는지 윈도우 콘솔에서 다음 명령어로 확인해 본다.

cocos -h
cocos new -h


3. 새 프로젝트를 만드는 명령어는 다음과 같다.

"cocos new MyGame -p com.MyCompany.MyGame -l cpp -d F:/MyProject"



-p : package name
-l : language
-d : directory


4. 생성된 proj.win32 폴더에 있는 솔루션 파일( .sln )을 Visual Studio 에서 연다.

5. build, run 해본다.









2014년 4월 25일 금요일

Vertex Shader problem in Galaxy S Mali GPU


Google document 의 문제인가.
Galaxy S Mali GPU 의 문제인가.


http://developer.android.com/training/graphics/opengl/index.html


http://stackoverflow.com/questions/22384272/android-opengl-es-not-rasterizing-matrix-multiplication-switched




------- EDIT : SOLUTION FOUND -------
Okay, I found the error. The google document shows a "wrong" the multiplication of the matrices in the vertex shader:
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
void main() {
   gl_Position = uMVPMatrix * vPosition;
}
This doesn't seem to be a problem for my old Galaxy S1 but somehow the S3 (or the Mali GPU) is picky about this. I changed the order of multiplication to this:
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
void main() {
   gl_Position = vPosition * uMVPMatrix;
}
And it works (also on the S1). Still not sure why the S1 works fine with both versions but this solves the problem.




--------------------------------------------------------
Google document 는 문제가 없고,
Galaxy S Mali GPU 도 문제가 없다.


translate 까지 정확히 동작하려면 matrix 가 앞에오는 코드가 맞다.

uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
void main() {
   gl_Position = uMVPMatrix * vPosition;
}



model matrix 에서 rotation, translation 까지 정상적으로 동작하게하려면,
 matrix 가 앞에오는 다음 코드가 맞다.


gl_Position = uMVPMatrix * vPosition;



viewport 설정.
view matrix 설정.
projection matrix 설정.
model matrix 설정.


gl_Position = vPosition * uMVPMatrix;

Samsung Galaxy note 8.0 SHW-M500W 에서 위 코드만 정상적으로 출력되고,  matrix 가 앞에 오는 맞는 코드는 출력되지 않는것처럼 보이는 현상은 projection matrix 가 잘못 설정되어 있거나, matrix 를 곱하는 순서가 잘못되었거나, 같은 matrix 를 입출력에 같이사용하거나 할때 나타난다.

matrix 가 뒤에 오는 위 코드를 사용하면 translate 가 되지 않는다.


model matrix 에서 rotation, translation 까지 정상적으로 동작하게하려면,
 matrix 가 앞에오는 다음 코드가 맞다.


gl_Position = uMVPMatrix * vPosition;



2013년 8월 21일 수요일

Applying Projection and Camera Views












import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

private GLSurfaceView mGLView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);
       
        //setContentView(R.layout.activity_main);
       
       
       
        // Create a GLSurfaceView instance and set it
        // as the ContentView for this Activity.      
        mGLView = new MyGLSurfaceView(this);
        setContentView( mGLView);
       
   
       
    }
   

    @Override
    protected void onPause() {
   
        super.onPause();
       
        // The following call pauses the rendering thread.
        // If your OpenGL application is memory intensive,
        // you should consider de-allocating objects that
        // consume significant memory here.
        mGLView.onPause();
    }
   
    @Override
    protected void onResume() {
   
        super.onResume();
       
        // The following call resumes a paused rendering thread.
        // If you de-allocated graphic objects for onPause()
        // this is a good place to re-allocate them.
        mGLView.onResume();
    }  


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        // getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}




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



import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.SystemClock;
import android.util.Log;

public class MyGLRenderer implements GLSurfaceView.Renderer {
private static final String TAG = "MyRenerer";
private Triangle mTriangle;
private Square mSquare;
private final float[] mMVPMatrix      = new float[16];
private final float[] mProjMatrix     = new float[16];
private final float[] mVMatrix        = new float[16];
private final float[] mRotationMatrix = new float[16];
// Declare as volatile because we are updating it from another thread
public volatile float mAngle;


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Set the background frame color
GLES20.glClearColor( 1.0f, 0.0f, 0.0f, 1.0f);
// GLES20.glClearColor( 0.5f, 0.5f, 0.5f, 1.0f);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glDepthFunc(GLES20.GL_LEQUAL);

// set the camera position ( View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -5, 0, 0, 0, 0, 1, 0);
mTriangle = new Triangle();
mSquare = new Square();
}
@Override
public void onDrawFrame(GL10 gl) {
// Redraw background color
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// set the camera position ( View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -5, 0, 0, 0, 0, 1, 0);
// Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
// Combine the projection and camera view matices
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
// Create a rotation for the triangle
//long time = SystemClock.uptimeMillis() % 4000L;
//float angle = 0.090f * ((int) time);
// mAngle = angle;
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
// Combine the rotation matrix with the projection and camera view
        Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);
mTriangle.draw(mMVPMatrix);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

// Adjust the viewport based on geometry changes,
// such as screen rotation
GLES20.glViewport( 0, 0, width, height);
float ratio = (float) width / height;
// float FIXED_RATIO = 2;
// this projection matrix is applied to object coordinates
// in the onDrawFrame() method
Matrix.frustumM( mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
// Matrix.frustumM( mProjMatrix, 0, -FIXED_RATIO, FIXED_RATIO, -FIXED_RATIO, FIXED_RATIO, 1, 10);
Log.e(TAG, "onSurfaceChanged");
}
    public static int loadShader(int type, String shaderCode){

        // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
        // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
        int shader = GLES20.glCreateShader(type);

        // add the source code to the shader and compile it
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);

        return shader;
    }

    
    public static void checkGlError(String glOperation) {
    int error;
    while((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
    Log.e(TAG, glOperation + ": glError " + error);
    throw new RuntimeException(glOperation + ": glError " + error);
    }
    }

}


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



import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;


public class MyGLSurfaceView extends GLSurfaceView {
private final MyGLRenderer mRenderer;

public MyGLSurfaceView(Context context) {

super(context);
// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
        mRenderer = new MyGLRenderer();
setRenderer( mRenderer);
// Render the view only when there is a change in the drawing data
setRenderMode( GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
    private float mPreviousX;
    private float mPreviousY;
public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
switch( e.getAction()) {
case MotionEvent.ACTION_MOVE:
float dx = x - mPreviousX;
float dy = y - mPreviousY;
// reverse direction of rotation above the mid-line
if (y > getHeight() / 2) {
dx = dx * -1;
}
// reverse direction of rotation to left of the mid-line
if(x < getWidth() / 2) {
dy = dy * -1;
}
mRenderer.mAngle += (dx + dy)*TOUCH_SCALE_FACTOR; // 180.0F / 320
requestRender();
}
mPreviousX = x;
    mPreviousY = y;
    
    
    Log.e( "MyGLSurfaceView", "onTouchEvent");
return true;
}


}


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



import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import android.opengl.GLES20;

public class Triangle {
    private final String vertexShaderCode =
   
    // This matrix member variable provides a hook to manipulate
    // the coordinates of objects that use this vertex shader.
    "uniform mat4 uMVPMatrix; " +    
            "attribute vec4 vPosition;" +
            "void main() {" +
            "  gl_Position = uMVPMatrix * vPosition;" +
            "}";

        private final String fragmentShaderCode =
            "precision mediump float;" +
            "uniform vec4 vColor;" +
            "void main() {" +
            "  gl_FragColor = vColor;" +
            "}";
private FloatBuffer vertexBuffer;
    private final int mProgram;
    private int mPositionHandle;
    private int mColorHandle;
    private int mMVPMatrixHandle;
// number of coordinates per vertex in this array
static final int COORDS_PER_VERTEX = 3;

static float triangleCoords[] = {
0.0f,  0.622008459f, 0.0f,
  -0.5f, -0.311004243f, 0.0f,
0.5f, -0.311004243f, 0.0f
};
    private final int vertexCount = triangleCoords.length / COORDS_PER_VERTEX;
    private final int vertexStride = COORDS_PER_VERTEX * 4; // bytes per vertex
float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f };
public Triangle() {
// initialize vertex byte buffer for shape coordinates
ByteBuffer bb = ByteBuffer.allocateDirect(
// (number of coordinate values * 4 bytes per float)
triangleCoords.length * 4

);
// use the device hardware's native byte order
bb.order( ByteOrder.nativeOrder() );
// create a floating point buffer from the ByteBuffer
vertexBuffer = bb.asFloatBuffer();
// add the coordinates to the FloatBuffer
vertexBuffer.put(triangleCoords);
// set the buffer to read the first coordinate
vertexBuffer.position(0);

        // prepare shaders and OpenGL program
        int vertexShader   = MyGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER,
        vertexShaderCode);
        int fragmentShader = MyGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER,
                                                      fragmentShaderCode);

        mProgram = GLES20.glCreateProgram();             // create empty OpenGL Program
        GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
        GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
        GLES20.glLinkProgram(mProgram);                  // create OpenGL program executables
}
    public void draw(float[] mvpMatrix) {
        // Add program to OpenGL environment
        GLES20.glUseProgram(mProgram);

        // get handle to vertex shader's vPosition member
        mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

        // Enable a handle to the triangle vertices
        GLES20.glEnableVertexAttribArray(mPositionHandle);

        // Prepare the triangle coordinate data
        GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                     GLES20.GL_FLOAT, false,
                                     vertexStride, vertexBuffer);

        // get handle to fragment shader's vColor member
        mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

        // Set color for drawing the triangle
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);
        
        
        // get handle to shape's transformation matrix
        mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
        MyGLRenderer.checkGlError("glGetUniformLocation");
        
        // Apply the projection and view transformation
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle,  1, false, mvpMatrix, 0);
        MyGLRenderer.checkGlError("glUniformMatrix4fv");
        
        
        
        

        // Draw the triangle
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

        // Disable vertex array
        GLES20.glDisableVertexAttribArray(mPositionHandle);
    }

}









2013년 8월 19일 월요일

Paypal vs. ACH/Wire



출처: http://aroundck.tistory.com/1356






Paypal(페이팔) vs. ACH/Wire 수입지급방식.

Paypal(페이팔)은 무엇인가?

페이팔(Paypal) 이란?

- 가입자의 신용카드나 은행계좌가 연동된 온라인 상의 계좌를 제공하는 서비스이다. 가입자는 이메일 주소를 통해 계정에 가입할 수 있으며,  이 가상계좌를 통해 송금, 입금, 청구가 가능하다. 회원가입 및 계좌보유는 무료지만, 거래시에 수수료를 청구하여 사업을 영위한다. 가입시 이메일주소와 신용카드 또는 은행계좌 정보가 있어야 한다.

- 은행계좌 연결시 인증을 완료하기까지 약 3~5일정도 걸린다.

-  ebay 가 모회사로, 1998년도에 설립된 신용도 높은 미국의 온라인 결제 대행사로 믿을 수 있다.






페이팔(Paypal) 수수료

- 개인간 거래에서 페이팔 잔고에서 송금하거나 상품을 구매하는 것은 무료. 연계된 은행계좌가 있을 경우, 그 계좌가 미국이나 캐나다 은행일 경우 무료로 이용가능하나, 이외 지역의 계좌일 경우에는 수수료 발생. 수수료는 3.4~4.9% 발생한다. 백만원 이하의 소액 송금의 경우 은행 송금보다는 페이팔 송금이 유리하다.


- 상업적 거래시 페이팔을 사용할 경우 판매자가 3.9% +  Fixed fee 를 내기 때문에 개인은 무료이다. 다시 말해 구매자는 수수료 걱정이 없고, 판매자가 수수료를 문다. ( 이 수수료가 반영되어 가격이 책정되어 있겠다. )


- 다른 통화 거래인 경우 환전 수수료가 추가로 발생한다. ( 2.5%~3.5% )


- 페이팔 계좌에서 내 은행계좌로 인출할 때는 인출 수수료가 다음과 같이 발생한다.
( 한국의 경우 )
 * 15만원 이상시 무료
 * 15만원 이하는 1,500원 수수료.




ACH/Wire 는 무엇인가?
- ACH/Wire 는 일반적인 은행 송금을 이야기한다.



ACH/Wire 와 Paypal 의 수수료 비교.

- Admob 결제시 Paypal 과 ACH/Wire 두 가지 방법 중 선택할 수 있다.


- ACH/Wire 를 사용할 경우,  Admob 은 100$ 이상일 경우만 송금을 수행하는데, 이 때 50$의 송금 수수료 + 환전수수료 3.5% + 국내은행에서는 수취금액이 100$ 이상일 경우 1만원의 수수료. 100$ 이하일 경우는 수수료가 발생하지 않는다. 지급기간은 약 2주 정도 소모된다.


- Paypal 을 사용할 경우, 15만원 이하의 금액에 대해서는 1,500원의 수수료가, 15만원 이상의 금액에 대해서는 송금 수수료가 발생하지 않는다. 하지만 환전수수료 2.5~3.5% 는 발생한다. 지급기간은 약 2주 정도 소모된다.


- 결론적으로 Paypal 이 수수료는 더 저렴한 편이다.



Best case for adMob
- Paypal 결제계좌를 잡고, 15만원 이상일 때 15만원 이상 단위로 출금하는 것이 현재 가장 저렴한 수수료.






2013년 8월 17일 토요일

Publisher Account 등록



Google Play 에서 앱을 판매하려면

Google Play Developer Console 에 등록해야 한다.


https://play.google.com/apps/publish/



등록비는 $25 이다.
Google Wallet 을 사용하여 결제한다.


유료앱을 판매하려면 Google Wallet Merchant Account 가 있어야 한다.


한국은 유료앱 판매가능국가 에 포함되어 있으므로 Google Wallet Merchant Account 를 만들 수 있다.


등록 과정에서 신용카드가 필요하다.
















비열한 앱시장



출처: http://www.distimo.com



앱개발자. 무엇을 만들어 팔아야 하나?

게임이다.


다음 그림은 앱 카테고리별 다운로드수와 매출액 비율을 나타낸다.

게임이 가장 높다.









애플 앱스토어에서 앱의 평균가격은 약 $2 수준이다.









시간이 자날수록, 시장에서 승리한 소수의 앱이 시장 매출액의 대부분을 가지고 가는 현상이 관찰된다.  승자독식.






앱스토어와 구글플래이의 매출액을 비교해본다.
앱스토어 73%.
구글플래이 27%.










매출액 기준으로, 아직까지는 미국이 최대의 앱시장이다.



2012년 11월 일일 매출액 : 애플 앱스토어  $15M USD, 구글플래이 $3.5M USD.( 73% : 27% )

구글플래이에서 매출액 Top3 는 미국, 일본, 한국.
         ; Samsung's hometown 한국이 매출액 3위다.
           최대 인구를 가진 중국은 보이지 않는다.















2013년 8월 16일 금요일

Drawing Shapes











import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

private GLSurfaceView mGLView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);    
     
        //setContentView(R.layout.activity_main);
     
     
        // Create a GLSurfaceView instance and set it
        // as the ContentView for this Activity.
     
        mGLView = new MyGLSurfaceView(this);
        setContentView( mGLView);      
     
    }
 

    @Override
    protected void onPause() {
   
        super.onPause();
     
        // The following call pauses the rendering thread.
        // If your OpenGL application is memory intensive,
        // you should consider de-allocating objects that
        // consume significant memory here.
        mGLView.onPause();
    }
 
    @Override
    protected void onResume() {
   
        super.onResume();
     
        // The following call resumes a paused rendering thread.
        // If you de-allocated graphic objects for onPause()
        // this is a good place to re-allocate them.
        mGLView.onResume();
    }  


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        // getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
}


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





import android.content.Context;
import android.opengl.GLSurfaceView;


public class MyGLSurfaceView extends GLSurfaceView {

public MyGLSurfaceView(Context context) {

super(context);


// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2);



// Set the Renderer for drawing on the GLSurfaceView
setRenderer( new MyRenderer());


// Render the view only when there is a change in the drawing data
setRenderMode( GLSurfaceView.RENDERMODE_WHEN_DIRTY);


}


}


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




import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;

public class MyRenderer implements GLSurfaceView.Renderer {


private Triangle mTriangle;


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {

// Set the background frame color
GLES20.glClearColor( 1.0f, 0.0f, 0.0f, 1.0f);

mTriangle = new Triangle();

}

@Override
public void onDrawFrame(GL10 gl) {

// Redraw background color
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );


mTriangle.draw();

}


@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

GLES20.glViewport( 0, 0, width, height);

}


    public static int loadShader(int type, String shaderCode){

        // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
        // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
        int shader = GLES20.glCreateShader(type);

        // add the source code to the shader and compile it
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);

        return shader;
    }


}


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





import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import android.opengl.GLES20;

public class Triangle {

    private final String vertexShaderCode =
            "attribute vec4 vPosition;" +
            "void main() {" +
            "  gl_Position = vPosition;" +
            "}";

        private final String fragmentShaderCode =
            "precision mediump float;" +
            "uniform vec4 vColor;" +
            "void main() {" +
            "  gl_FragColor = vColor;" +
            "}";



private FloatBuffer vertexBuffer;
    private final int mProgram;
    private int mPositionHandle;
    private int mColorHandle;

// number of coordinates per vertex in this array
static final int COORDS_PER_VERTEX = 3;

static float triangleCoords[] = {
0.0f,  0.622008459f, 0.0f,
  -0.5f, -0.311004243f, 0.0f,
0.5f, -0.311004243f, 0.0f
};

    private final int vertexCount = triangleCoords.length / COORDS_PER_VERTEX;
    private final int vertexStride = COORDS_PER_VERTEX * 4; // bytes per vertex



float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f };

public Triangle() {



// initialize vertex byte buffer for shape coordinates
ByteBuffer bb = ByteBuffer.allocateDirect(


// (number of coordinate values * 4 bytes per float)
triangleCoords.length * 4

);


// use the device hardware's native byte order
bb.order( ByteOrder.nativeOrder() );

// create a floating point buffer from the ByteBuffer
vertexBuffer = bb.asFloatBuffer();

// add the coordinates to the FloatBuffer
vertexBuffer.put(triangleCoords);

// set the buffer to read the first coordinate
vertexBuffer.position(0);


        // prepare shaders and OpenGL program
        int vertexShader = MyRenderer.loadShader(GLES20.GL_VERTEX_SHADER,
                                                   vertexShaderCode);
        int fragmentShader = MyRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER,
                                                     fragmentShaderCode);

        mProgram = GLES20.glCreateProgram();             // create empty OpenGL Program
        GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
        GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
        GLES20.glLinkProgram(mProgram);                  // create OpenGL program executables


}


    public void draw() {
        // Add program to OpenGL environment
        GLES20.glUseProgram(mProgram);

        // get handle to vertex shader's vPosition member
        mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

        // Enable a handle to the triangle vertices
        GLES20.glEnableVertexAttribArray(mPositionHandle);

        // Prepare the triangle coordinate data
        GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                     GLES20.GL_FLOAT, false,
                                     vertexStride, vertexBuffer);

        // get handle to fragment shader's vColor member
        mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

        // Set color for drawing the triangle
        GLES20.glUniform4fv(mColorHandle, 1, color, 0);

        // Draw the triangle
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

        // Disable vertex array
        GLES20.glDisableVertexAttribArray(mPositionHandle);
    }


}











Eclipse hangs at the Android SDK Content Loader

eclipse -clean