android opengl es 1.1 - 在某些设备上绘制故障 - 内部截图

时间:2014-03-09 18:31:37

标签: java android opengl-es

顶部图像是不希望的结果(它似乎也闪烁)。 底部图像是我希望渲染在所有设备上的样子。

Glitchy render

Good render

您好,我似乎在为我的galaxy s4渲染纹理方块时出现问题,但是我的gt p3113平板电脑上没有... ...

以下是我的GLRenderer的代码:

@Override
public void onDrawFrame(GL10 gl)
{
    manObjects.draw(gl, 0, 0);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
    if (height == 0)
    { // Prevent A Divide By Zero By
        height = 1; // Making Height Equal One
    }

    gl.glViewport(0, 0, width, height); // Reset The Current Viewport
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix

    // respect the height:width ratio of the window.
    GLU.gluOrtho2D(gl, -1f, 1f, 1.6f, -1.6f);

    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity(); // Reset The Modelview Matrix
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
    // Settings
    gl.glEnable(GL10.GL_TEXTURE_2D); // Enable Texture Mapping
    gl.glShadeModel(GL10.GL_SMOOTH); // Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
    gl.glClearDepthf(1.0f); // Depth Buffer Setup

    // Really Nice Perspective Calculations
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glEnable(GL10.GL_BLEND); // Enable blending
    gl.glDisable(GL10.GL_DEPTH_TEST); // Disable depth test
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    // Load textures
    manObjects.load(gl, mContext);
}

任何人都有任何关于为什么会这样做的想法?更具体地说,为什么它可以在一个设备上工作而不在另一个设备上工作?

绘制代码:

public void draw(GL10 gl, float x, float y)
{
    gl.glLoadIdentity();
    gl.glBindTexture(GL10.GL_TEXTURE_2D, texPointers[0]);
    tSquare[0].draw(gl);
}

public void drawBLACK(GL10 gl)
{
    gl.glLoadIdentity();
    gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glScalef(1f, 1.6f, 1);
    gl.glColor4f(0, 0, 0, 1);
    tSquare[0].draw(gl);
    gl.glColor4f(1, 1, 1, 1);
}

tSquare [0] .draw(GL):

public void draw(GL10 gl)
{
    //Enable the vertex, texture and normal state
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    //Point to our buffers
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

    //Draw the vertices as triangle strip
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

    //Disable the client state before leaving
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

2 个答案:

答案 0 :(得分:1)

这是我的onDrawFrame示例,请尝试在onDrawFrame中进行gl调用

首先制作

public int width, height;

然后

@Override
    public void onSurfaceChanged(GL10 gl, int width, int height) { 
        this.width = width;
        this.height = height;
    }

然后onDrawFrame就像这样

@Override
public void onDrawFrame(GL10 gl)
{
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrthof(0.0f, width, 0.0f, height, -1.0f, 1.0f);
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glEnable(GL10.GL_BLEND);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
        gl.glEnable(GL10.GL_TEXTURE_2D);
        manObjects.draw(gl, 0, 0);
}

答案 1 :(得分:0)

可能的解决方案:

我在绘制明星的电话之前添加了另一个平局。这个添加的绘图调用绘制了一个覆盖整个屏幕的巨大的黑色矩形......

我觉得我只是掩盖了这个问题并没有真正修复它...... 想法?