1

OGLES 1.0 の学習と使用に約 1 週間を費やしました。魅力的だと思ったいくつかの機能には、2.0 を使用する必要があることに気付きました。ここ数日、1.0 から 2.0 への変換に取り組んでいます。最終的にエラーが発生しないポイントに到達し(見つけることができます)、画面がレンダリングされました。私が見るのはクリアカラーだけです。私は自分の問題が何であるかを理解するために物事を変えてALOTを読んでみましたが、答えを見つけることができません:(だからここで私が見るのはクリアカラーだけである理由をあなたに尋ねています.私のパーサーが正しいと仮定して(それは働いていた) 1.0 では問題なく) 私の BufferObjects/arrays/indices は正しいです (それらは 1.0 の場合でした) 私の問題は投稿しているコードにあります. 探し始める必要がある場所への任意の方向を教えてください. よろしくお願いします.

(未使用の変数やメソッド等はご容赦ください) renderer

public class TestRenderer implements Renderer {
private static final String TAG = TestRenderer.class.getSimpleName();
Cube tester;
Parser parser;
Context context;

private int mProgram;
private int muMVPMatrixHandle;
private float[] mMVPMatrix = new float[16];
private float[] mMMatrix = new float[16];
private float[] mVMatrix = new float[16];
private float[] mProjMatrix = new float[16];
private String vertexShaderCode = "attribute vec4 a_Position; "
        + "attribute vec3 a_Normal; " + "attribute vec2 a_Textcoords; "
        + "varying vec2 v_Textcoords;" + "uniform mat4 uMVPMatrix;  "

        + "attribute vec4 vPosition;  " + "void main(){ "
        + "v_Textcoords = a_Textcoords;"
        + " gl_Position = uMVPMatrix * vPosition; " +

        "}  ";

private String fragmentShaderCode = "precision mediump float; "
        + "varying vec2 v_Textcoords;" + "uniform sampler2D u_Texture; "
        + "void main(){ "
        + " gl_FragColor = texture2D(u_Texture, v_Textcoords); " + "} ";

TestRenderer(Context context) {
    this.context = context;
    parser = new Parser(context);
    parser.parse("Turret2.obj");
    tester = new Cube(parser.v, parser.f, parser.vt, parser.vtPointer,
            parser.vn, parser.vnPointer, 1);
}

public static void checkGLError(String msg) {
    int e = GLES20.glGetError();
    if (e != GLES20.GL_NO_ERROR) {
        Log.d(TAG, "GLES20 ERROR: " + msg + " " + e);
        Log.d(TAG, errString(e));
    }
}

public static String errString(int ec) {
    switch (ec) {
    case GLES20.GL_NO_ERROR:
        return "No error has been recorded.";
    case GLES20.GL_INVALID_ENUM:
        return "An unacceptable value is specified for an enumerated argument.";
    case GLES20.GL_INVALID_VALUE:
        return "A numeric argument is out of range.";
    case GLES20.GL_INVALID_OPERATION:
        return "The specified operation is not allowed in the current state.";
    case GLES20.GL_INVALID_FRAMEBUFFER_OPERATION:
        return "The command is trying to render to or read from the framebuffer"
                + " while the currently bound framebuffer is not framebuffer complete (i.e."
                + " the return value from glCheckFramebufferStatus is not"
                + " GL_FRAMEBUFFER_COMPLETE).";
    case GLES20.GL_OUT_OF_MEMORY:
        return "There is not enough memory left to execute the command."
                + " The state of the GL is undefined, except for the state"
                + " of the error flags, after this error is recorded.";
    default:
        return "UNKNOW ERROR";
    }
}

public void onDrawFrame(GL10 unused) {
    // TODO Auto-generated method stub
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    tester.draw(mProgram);
    checkGLError("onDrawFrame 0");

}

public void onSurfaceChanged(GL10 unused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

    float ratio = (float) width / height;

    Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, .001f, 100);
    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, 0, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

}

public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);

    mProgram = GLES20.glCreateProgram();
    checkGLError("onSurfaceCreated 3");

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    checkGLError("onSurfaceCreated 1");

    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,
            fragmentShaderCode);

    GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader
                                                    // to program

    checkGLError("onSurfaceCreated 5");

    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment
                                                        // shader to program
    checkGLError("onSurfaceCreated 2");

    GLES20.glLinkProgram(mProgram);
    checkGLError("onSurfaceCreated 7");
    Log.d(TAG,
            "link program true/false 1 = "
                    + GLES20.glGetProgramInfoLog(mProgram));

    GLES20.glUseProgram(mProgram);
    checkGLError("onDrawFrame 2");
    checkGLError("onSurfaceCreated 8");
    Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.turretbottom);
    tester.loadTextures(context, bmp);
}

private int loadShader(int type, String shaderCode) {

    int shader = GLES20.glCreateShader(type);
    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);

    Log.d(TAG, "Shader info log = " + GLES20.glGetShaderInfoLog(shader));

    return shader;
}

}

public void draw(int program) {

    GLES20.glGenBuffers(4, vboIds, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, verts.length, vertBuff,
            GLES20.GL_STATIC_DRAW);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[1]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, textVerts.length, textBuff,
            GLES20.GL_STATIC_DRAW);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[2]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, normPoints.length,
            normBuff, GLES20.GL_STATIC_DRAW);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, vboIds[3]);
    GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, 2 * indexa.length,
            faceBuff, GLES20.GL_STATIC_DRAW);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[0]);
    GLES20.glEnableVertexAttribArray(0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[1]);
    GLES20.glEnableVertexAttribArray(1);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[2]);
    GLES20.glEnableVertexAttribArray(2);

    GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, 0);

    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 0, 0);

    GLES20.glVertexAttribPointer(2, 3, GLES20.GL_FLOAT, false, 0, 0);

    GLES20.glBindAttribLocation(program, 0, "a_Position");
    GLES20.glBindAttribLocation(program, 1, "a_Textcoords");
    GLES20.glBindAttribLocation(program, 2, "a_Normal");

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, indexa.length,
            GLES20.GL_UNSIGNED_SHORT, 0);
    GLES20.glDeleteBuffers(4, vboIds, 0);

}
4

1 に答える 1