OpenGL ES 对象形状在早期版本的 Android Honeycomb 中无法正确绘制
我画一个圆圈,即使我在android中使用java opengl ES画一个基本形状(例如正方形,菱形)。
如果我在蜂窝中运行应用程序,形状会很好,但如果我在姜饼中运行它,形状会增加一些不必要的点,这些点会被绘制(它会分散),如果我继续执行它,很少会没有这些点。
我的渲染器类,
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);
}
在我的 Circle 类中,
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);
}
我真的一无所知。我不知道为什么它在 android 版本 <3.0 中无法正确绘制。
编辑:我试图解决它,我发现当我尝试绘制点时,很少有顶点在 android 2.3.3 中走出视口(可能是无穷大,我不知道),但对于相同的点android 3.0 它绘制了正确的形状。
帮帮我吧。
Im drawing a circle and even if i draw a basic shape (eg.square, diamond) using java opengl ES in android.
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
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.
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.
Help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
系数 1.25 是什么意思?如果您的圆显示为椭圆形,那是因为您的投影矩阵没有考虑窗口方面。
What's that factor 1.25 supposed to mean? If your circle is coming out as an ellipse, then that's because your projection matrix doesn't take into account window aspect.
我犯了一个错误
问题在于
sliceCount 是点 x、y、z 的总数。我把它除以 3。
I made a blunder mistake
The issue was in
where the sliceCount is total number of points x,y,z. I divided that one by 3.