Android 画圆的奇怪问题
UPDATE2:尝试只渲染一个四边形 更新:完整的代码在这里。有人能确认我的密码有问题吗 我一直在尝试用Opengl ES 1.0绘制一个圆。我在Windows平台上使用了很多SDL和OpenGL,并且主要使用glBegin和glEnd,因为我的游戏使用的多边形数很低 粘贴下来的是创建对象时调用的代码Android 画圆的奇怪问题,android,opengl-es,3d,Android,Opengl Es,3d,UPDATE2:尝试只渲染一个四边形 更新:完整的代码在这里。有人能确认我的密码有问题吗 我一直在尝试用Opengl ES 1.0绘制一个圆。我在Windows平台上使用了很多SDL和OpenGL,并且主要使用glBegin和glEnd,因为我的游戏使用的多边形数很低 粘贴下来的是创建对象时调用的代码 float ini[]=new float[360*3]; ByteBuffer temp=ByteBuffer.allocateDirect(ini.length*4);
float ini[]=new float[360*3];
ByteBuffer temp=ByteBuffer.allocateDirect(ini.length*4);
temp.order(ByteOrder.nativeOrder());
vertex=temp.asFloatBuffer();
int i;
float D2R=(float) (3.14159265/180);
for (i=0;i<360;i++){
float XX=(float)(Math.sin(i*D2R)*size);
float YY=(float)(Math.cos(i*D2R)*size);
ini[i*2]=XX;
ini[i*2+1]=YY;
ini[i*2+2]=0;
}
vertex.put(ini);
Log.d("GAME","SPAWNED NEW OBJECT");
length=ini.length;
//vertex=ByteBuffer.allocateDirect(temp.length*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
//vertex.put(temp);
vertex.position(0);
它画了一个圆(当它实际决定运行时),并添加了一些wierd线。
这里举一个例子:
这是你的错
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glLoadIdentity();
gl.glViewport(0, 0, arg1, arg2);
gl.glOrthof(0,(float)arg1,(float)arg2,0,-1,1);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
这没有道理:
float ini[]=new float[360*3];
/* ... */
for (i=0;i<360;i++){
float XX=(float)(Math.sin(i*D2R)*size);
float YY=(float)(Math.cos(i*D2R)*size);
ini[i*2]=XX;
ini[i*2+1]=YY;
ini[i*2+2]=0;
}
是的,我在开始阅读每一行的10分钟后就发现了。这是我第一次使用GLDrawArray,glVertexPointer,非常感谢您的帮助!它现在开始工作了!
float ini[]=new float[360*3];
/* ... */
for (i=0;i<360;i++){
float XX=(float)(Math.sin(i*D2R)*size);
float YY=(float)(Math.cos(i*D2R)*size);
ini[i*2]=XX;
ini[i*2+1]=YY;
ini[i*2+2]=0;
}
float ini[]=new float[360*2];
/* ... */
for (i=0;i<360;i++){
float XX=(float)(Math.sin(i*D2R)*size);
float YY=(float)(Math.cos(i*D2R)*size);
ini[i*2]=XX;
ini[i*2+1]=YY;
}
/* ... */
gl.glVertexPointer(2, GL10.GL_FLOAT,0, vertex);
float ini[]=new float[360*3];
/* ... */
for (i=0;i<360;i++){
float XX=(float)(Math.sin(i*D2R)*size);
float YY=(float)(Math.cos(i*D2R)*size);
ini[i*3]=XX;
ini[i*3+1]=YY;
ini[i*3+2]=0;
/* ^ */
/* ^ */
}
/* ... */
gl.glVertexPointer(3, GL10.GL_FLOAT,0, vertex);
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 360);