English 中文(简体)
Anders OpenGL ES - I can t make gluLookAt/gluPerspective work
原标题:Android OpenGL ES - I can t make gluLookAt/gluPerspective work

下面的案文是比喻的,因为我想确保有类似问题的人们,例如,本页可以很容易地关注具体问题及其解决办法。 但我现在谈谈我的问题:

我最近开始在安乐施会电话上制定开放式教育计划,并遇到一些问题,了解如何使用蓝.和蓝.。 页: 1 我理解他们做些什么,但我看不出三角。 我在我活动的方法上采用了以下守则。 Said activity Implements GLSurfaceView. Renderer with the on DrawFramemark with @Override. 我的法典是:

gl.glViewport(0, 0, screen_width, screen_height);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //set background to black
gl.glClearDepthf(1.0f); 

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GL10.GL_PROJECTION); // Change PROJECTION matrix
gl.glLoadIdentity();

float aspect_ratio = (float) screen_width / screen_height;
GLU.gluPerspective(gl, 67, aspect_ratio, 1, 100);

gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glMatrixMode(GL10.GL_MODELVIEW); // Change MODELVIEW matrix
gl.glLoadIdentity();

GLU.gluLookAt(gl, 0, 0, 20, 0, 0, 0, 0, 1, 0);

// make triangle with vertices (-2,0,0), (2,0,0), and (0,.5,0)
float[] vertices = { -2f, 0, 0, 2f, 0, 0, 0, .5f, 0 };
ByteBuffer buffer = ByteBuffer.allocateDirect(vertices.length * 4);
buffer.order(ByteOrder.nativeOrder());
FloatBuffer vertex_buffer = buffer.asFloatBuffer();
for (int i = 0; i < 9; i++) {
    vertex_buffer.put(vertices[i]);
}

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertex_buffer);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisable(GL10.GL_DEPTH_TEST);

接下来的几点是关于我对上述法典中关于摄像设施的看法的简短说明。 如果我在以下解释中说错的话,PLEASE会纠正我,因为这可能已经解决我的所有问题!

  1. glMatrixMode(GL10.GL_PROJECTION) switches to changing the camera matrix (for which I load an identity matrix directly afterwards)
  2. GLU.gluPerspective(gl, 67, aspect_ratio, 1, 100) sets a perspective projection with a view frustrum of 67 degree view angle in the y-dimension. Using "aspect_ration=(float)width/height" OpenGL computes the view angle in the x-dimension. Further the "1" is the near clipping plane, while "100" is the value of the far clipping plane in this case.
  3. As far as I know it does not matter, where in the code gluLookAt is called, as long as it is done before the actual drawing (I m unsure about this though). In this example I change to the MODELVIEW matrix first, load an identity matrix, and then gluLookAt is called. 3.
  4. "GLU.gluLookAt(gl, 0, 0, 20, 0, 0, 0, 0, 1, 0)" actually consists of three 3-element vectors. The initial one ((0,0,20) in this example) sets the position of the camera in world coordinates (i.e. 20 units on the positive Z-axis, which means it is "sticking out" of the front of the phone s screen). The second vector determines the point in the world coordinate system the camera looks at (in this example the origin of the coordinate system, i.e. the camera looks along the negative z-axis). The third vector is the up-vector that defines the direction of the y-Axis of the cameras coordinate system (and therefore also the x-axis via cross product with the vector from camera position to the point it looks at).

三角制图法从辅导法中复制(但我发现其他辅导法也有类似规定,因此我认为这不是问题)。

只要我得到,该摄像机现在就位在(0,20美元)上,并着眼于协调系统的起源。 其绘画法从Z-值19开始,到80年(照相机在Z-轴20点,看着负Z-轴心;其视法鲁斯特鲁姆接近于1和100(在这起案件中分别看着Z-轴心)。 因此,三角形应当明显可见,因为它的vert在Z-axis=0架飞机(即Xy-plane)的原产地上,这显然是在看着疲软的。 此外,抽出的vert是按反锁定的;在开放式GL中缺席。

因此,在该问题如此长的介绍之后,我简单的问题是:我所想的是什么,这样,这部法律就没有我期望它做什么?

最佳回答

我在研究进一步辅导后找到答案(然后在我以前使用的辅导中注意到)! 感谢大家的回答,他们非常有助于诊断开放的利比里亚问题,并相信将来会帮助我!

www.un.org/Depts/DGACM/index_spanish.htm 解决我的问题的办法是......,问题不是看上去或看上去,而是在我的情况下是FloatBuffer的内部立场。 我没有确定(0 < i < 9)休息时间后0至0的变相。 2. 至少要有两条指挥,才能将缓冲位置定为0:

  • vertex_buffer.rewind()
  • vertex_buffer.position(0)

据我所知,他们也这样做。 我很快在守则中测试了该职位属于何处,在我的示范法典中,我可以把它称作光线后(GL10.GL_VERTEX_ARRAY),然而,我不得不在光线(glVertexPointer)(3, GL10.GL_FLOAT, 0, vertex_buffer)之前提一下,否则最初的问题就回到了。

我希望这能帮助其他有类似问题或可能只是一小 short和 gl光的人。

再次感谢你们的建议!

问题回答

我在PC、Mac和SOS上只使用了开放式的GL,但从我可以告诉的角度来看,该守则是罚款的。 那么,地雷总是会发生,但我仍然有一个空洞的屏幕,几乎是我从零开始任何3D(不管有APIC)。 希望其中至少有一人会受到你 tried的考验。

  • Add in a glFlush at the end, because you re not actually drawing all that much. You d think the driver would do this for you when you do the buffer swap, but it seems that there s no guarantees of that -- Mac OS X doesn t always seem to, for example.
  • Set background to non-black. If something is drawing in black, you want to see it.
  • Disable GL_LIGHTING. If this is enabled (which I think it is by default?) but you re not supplying normals, everything will come out black. (See above.)
  • Disable GL_CULL_FACE. It doesn t matter how carefully you think about the winding order, there s still a possibility you might have got it wrong. But if GL_CULL_FACE is off, that becomes impossible.
  • Disable GL_DEPTH_TEST. This has saved me a couple of times, when I ve typed glClearDepth(0) by accident. Looks like you re OK in that respect, but it s still worth a go.
  • Check glGetError religiously, after EVERY API call, just in case. (assert(glGetError()==GL_NO_ERROR) will do for starters, but you really want to have a little loop that also prints the result of gluErrorString so that it s easier to see at a glance what might be wrong.)
  • Make sure you do a glBindBuffer to set your ARRAY_BUFFER and ARRAY_ELEMENT_BUFFER bindings to 0. To initialize a VBO, you have to bind it, so if you ve got something somewhere that sets one up it might just leave it bound. This will stuff up your glVertexPointer.
  • Along the lines of the last few - set up more state explicitly. In this case, for example, you might want to glDisableClientState the other array types, just in case. GL starts up with vertex arrays disabled, according to the docs, but it s a possibility worth eliminating.

<> 开放式欧空域用户

在我的案件中,我不得不写信。

gl.glMatrixMode(gl.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl,45,1,1.5f,50);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();

而不仅仅是

GLU.gluPerspective(gl,45,1,1.5f,50);

<代码>SurfaceChanged方法。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签