English 中文(简体)
从OGLES 1.0到 2.0 的花瓶遮罩
原标题:vbos shaders going from OGLES 1.0 to 2.0

我花了大约一周时间学习并使用OGLES 1.0。 我意识到我需要使用 2.0 来完成一些我发现吸引人的特征。 我花了几天的时间一直在努力从 1.0 转换到 2.0 。 我终于到了一个点, 我没有得到错误( 我能找到), 并且有一个屏幕。 我所看到的只是清晰的颜色。 我试着改变周围的东西, 读读ALOT 来找出我的问题是什么, 但我只是找不到答案 : ( 因此, 我在这里问你为什么我所看到的东西都是清晰的颜色。 假设我的解析器是正确的( 它对1.0 毫无瑕疵 ), 我的弹片/ 阵列/ 指数是正确的( 它们对1.0 ), 我的问题就在我所张贴的代码里 。 请告诉我, 任何我需要开始寻找的方向都非常感谢。 感谢大家提前感谢 。

(please excuse unused variables and methods etc) 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);

时 时
问题回答

你同时咬了很多东西, 我可能会从更简单的东西开始, 如果你不得到任何地方(没有纹理,没有颜色,只有单三角形) 并且从那里积累起来, 当你工作的时候。

我确实看到一个错误, 因为 glBindAttribLation 只在 < / em> 下次拨打 glLinkProgram 后生效, 所以您拨打 glBindAttribLation 的电话没有做任何事情( 您需要在连接阴影器前绑定位置 ) 。

另外,当您编译/链接一个阴影器时,您应该使用 glGetShaderiv (GL_ COMPILE_STATUS) / glGetProgrivi (GL_ LINK_STATUS) 来检查结果。 这比打印信息日志要好得多。





相关问题
IronPython: Trouble building a WPF ShaderEffect

I m trying to build an extensible program where users, among other things, can build their own shader effects. Google searching got me this far; class Test(ShaderEffect): inputProperty = ...

Making Photoshop-like drop shadows in a game

I m making a game where the game s size varies, so I want to make my own shadows. The api i m using can fill rectangles, make ellipses, horizontal lines etc. And supports rgba. Given this, how could I ...

How to change a GLSL shader parameter in Processing

I m playing with shaders in openGL using Processing. I m pretty noob at this and a bit lost. I found this thread that has an example on how to use GLSL shaders in Processing. I m just trying to the ...

Shader limitations

I ve been tuning my game s renderer for my laptop, which has a Radeon HD 3850. This chip has a decent amount of processing power, but rather limited memory bandwidth, so I ve been trying to move more ...

XNA .Fbx textures

I m using the standard .fbx importer with custom shaders in XNA. The .fbx model is UV wrapped properly and is textured appropriately when I use BasicEffect. However when I use my custom effect I have ...

Is it possible to use a pixel shader inside a sprite?

Is it possible to use a pixel shader inside a sprite? I have create a simple pixel shader, that just writes red color, for testing. I have surrounded my Sprite.DrawImage(tex,...) call by the effect....

WPF ShaderEffect with PS 3.0 shaders

在什么地方,我可以找到用作WPF 4的ShaderEffects的PS 3.0 棚户区的例子? I m 寻找这方面的辅导、介绍和任何资源。

热门标签