简体   繁体   English

在早期版本的android蜂窝中,OpenGL ES对象形状没有正确绘制

[英]OpenGL ES object shape is not drawing properly in earlier version of android honeycomb

Im drawing a circle and even if i draw a basic shape (eg.square, diamond) using java opengl ES in android. 即使我在android中使用java opengl ES绘制基本形状(例如,方形,菱形),我画一个圆圈。

If I run the application in honeycomb the shape is coming fine but if I run it in gingerbread with the shape few more unnecessary points where getting drawn(it getting scattered) and if I keep on executing it rarely it comes without those points. 如果我在蜂窝状态下运行应用程序,那么形状就会好起来但是如果我在姜饼中运行它的形状几乎没有不必要的点被绘制(它变得分散),如果我继续执行它很少没有那些点。

My Renderer class, 我的渲染器类,

public void onDrawFrame(GL10 gl) {
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -5.0f);
gl.glRotatef(-100, 1.0f, 0.0f, 0.0f);
gl.glRotatef(40, 1.0f, 0.0f, 0.0f);

mCircle= new Circle();
     Circle.setCirclePoints(1.5f,4, 1, 360);
Circle.draw(gl);

}

public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);         
     float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(-6.5f, +6.5f, -6.5f, 6.5f, 6.5f, -6.5f);

  }
          public void onSurfaceCreated(GL10 gl, EGLConfig config) {
       gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glClearColor(0,0,0,0);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
    }   

In my Circle Class 在我的Circle Class中

public void setCirclePoints(float radius, int slices, int stacks,
        float angle)
    ByteBuffer vbb = ByteBuffer.allocateDirect(((slices+2)* 3 * 4));
    vbb.order(ByteOrder.nativeOrder());
    mSliceVertexBuffer = vbb.asFloatBuffer();

    mSliceVertexBuffer.put(0.0f);
    mSliceVertexBuffer.put(0.0f);
    mSliceVertexBuffer.put(nsign * radius);

    for (int j = 0; j <= slices; j++) {
        theta = j * dtheta;
        x = (float) 1.25f * (float) (Math.cos(theta + dupTheta));
        y = (float) Math.sin(theta + dupTheta);
        z = nsign;
        mSliceVertexBuffer.put(x * radius);
        mSliceVertexBuffer.put(y * radius);
        mSliceVertexBuffer.put(z * radius);
        } 

              }
public void draw(GL10 gl){
     gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
     gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mSliceVertexBuffer);
     gl.glColor4f(212,21,54,34);
    gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,sliceCount);
     gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}

Im really clue less.. I dont know why its not drawing properly in android version <3.0. 我真的很少知道..我不知道为什么它在Android版本<3.0中没有正确绘图。

edit: I tried to solve it, I found that when I'm trying to plot the points, few vertex are going out of the viewport(may be infinity, I dont know) in android 2.3.3, but for the same points in android 3.0 it drawing the proper shape. 编辑:我试图解决它,我发现当我试图绘制点时,很少有顶点出现在android 2.3.3中的视口(可能是无穷大,我不知道),但对于相同的点android 3.0它绘制了正确的形状。

Help me out. 帮帮我。

 x = (float) 1.25f * (float) (Math.cos(theta + dupTheta)); 

What's that factor 1.25 supposed to mean? 什么是因素1.25应该是什么意思? If your circle is coming out as an ellipse, then that's because your projection matrix doesn't take into account window aspect. 如果您的圆圈是椭圆形,那么这是因为您的投影矩阵没有考虑窗口方面。

I made a blunder mistake The issue was in 我犯了一个错误的错误。问题出在了

    gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,sliceCount);

where the sliceCount is total number of points x,y,z. 其中sliceCount是点x,y,z的总数。 I divided that one by 3. 我把那个除以3。

       gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,sliceCount/3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM