为什么 glColorPointer 不为三角形着色 - 以及 opengl es 的其他奇怪的事情
我对 OpenGL 不太熟悉,但我尝试在屏幕上绘制一个简单的三角形。每个角都涂有不同的颜色。类似于基本教程之类的东西...问题是,
- 三角形只是白色的。
- 该三角形仅在模拟器中可见,在我的 HTC Desire 上不可见。
我的 GLView 类:
public class GLView extends GLSurfaceView implements GLSurfaceView.Renderer {
private FloatBuffer vertexBuff;
private FloatBuffer colorBuff;
public static FloatBuffer makeFloatBuffer(float[] arr)
{
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(arr);
fb.position(0);
return fb;
}
public GLView(Context context) {
super(context);
setRenderer(this);
}
@Override
public void onDrawFrame(GL10 gl) {
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { 1, 0, 0,
0, 1, 0,
0, 0, 1 }));
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { 0, 0, 0,
0, 1, 0,
1, 1, 0}));
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
}
有什么建议吗?
I am not very familiar with OpenGL but I tried to draw a simple triangle on the screen. Each corner colored in a different color. Something like a basic tutorial... The problem is, that
- the triangle just is white.
- the triangle is only visible in emulator not on my HTC Desire.
My GLView class:
public class GLView extends GLSurfaceView implements GLSurfaceView.Renderer {
private FloatBuffer vertexBuff;
private FloatBuffer colorBuff;
public static FloatBuffer makeFloatBuffer(float[] arr)
{
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(arr);
fb.position(0);
return fb;
}
public GLView(Context context) {
super(context);
setRenderer(this);
}
@Override
public void onDrawFrame(GL10 gl) {
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { 1, 0, 0,
0, 1, 0,
0, 0, 1 }));
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { 0, 0, 0,
0, 1, 0,
1, 1, 0}));
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测 OpenGL 状态可能有些未指定,因为您不提供投影或模型视图矩阵。但我猜测主要是因为我对 OpenGL 不太熟悉。不管怎样,我通过向颜色数组添加 alpha 值来让你的代码正常工作
,并提供提到的转换矩阵可能会在设备上实现这一点。
I'm guessing OpenGL state might be somewhat unspecified as you don't provide projection or model view matrices. But I'm guessing mostly as I'm not exactly familiar with OpenGL. Anyway I got your code to work by adding alpha values to color array
And providing mentioned transformation matrices might do the trick on device.