Pregunta



This is developing a mobile application using OpenGLES2.0 on the android platform (against API 8, if it makes any difference).

I'm attempting to add a UI layer over my currently working rendering system, but it's not working and I'm not sure why. Any help would be greatly appreciated.

Here's what I'm doing:
1) When initialising, I'm loading a whole heap of meshes to be displayed, which use various programs to render. One of the meshes displays a texture and this is working.
2) After I've loaded all the meshes, I load a "button" which is basically a square with the same texture which is already being used in (1) above stretched across it.
3) My main rendering loop makes the depth mask writable and, for each program in turn, renders anything which is opaque, then makes the depth mask read-only and, for each program in turn, renders anything which has any degree of transparency, then clears the depth buffer bit and renders each UI component in turn.

I'm doing one thing which is maybe not the right way of doing things - the program which is rendering my UI components isn't performing any model-view-projection transformation - I'm passing normalised device coordinates into it directly and it's just a pass through. As far as I know, this should work - I only mention it because I'm suspicious of it. The code for the vertex and fragment shader for the UI component program are as follows:
int vShader = compileShader(GLES20.GL_VERTEX_SHADER,
"attribute vec4 aPosition;" +
"attribute vec2 aTexCoord;" +
"varying vec2 vTexCoord;" +
"void main() {" +
" vTexCoord = aTexCoord;" +
" gl_Position = aPosition;" +
"}");
int fShader = compileShader(GLES20.GL_FRAGMENT_SHADER,
"precision mediump float;" +
"uniform sampler2D uTexture;" +
"varying vec2 vTexCoord;" +
"void main() {" +
" gl_FragColor = texture2D(uTexture,vTexCoord);" +
"}");


Here's what I've tried:
1) I've tried preventing the opaque and transparent programs from running. In this case I get a screen completely filled with garbage (banded regular spaced horizontal stripes, alternating between pure black and seemingly random stuff - each band is probably about 50 pixels high).
2) I've inspected the contents of the float array on which my FloatBuffer is based (I can't work out how to inspect the FloatBuffer directly. It all looks good to me.

I'm a little bit stumped! Anyone got any ideas?

¿Fue útil?

Solución

OK, I got to the bottom of this. I'll list the general things to check first in case anyone ever ends up here again, then exactly what my damage was.

In general:
1) If you're not seeing stuff, turn off cull face (glDisable(GL_CULL_FACE)); this way if you've got the handedness of your polygons the wrong way round, you'll still see something.
2) Be aware that 0,0 for OpenGL is the bottom left, but you've probably decided that 0,0 is the top left for your UI code (this can aid and abet you in giving your triangles the wrong handedness). Here point 13 shows how to avoid this.
3) If you're getting garbage on the screen, you've probably forgotten to clear your buffers.

So, specifically, I'd got some triangles the wrong way round (due to the mismatch between origins in my UI code and the OpenGL code) and, when starting to prune stuff back to the basics to debug, had accidentially commented out the glClear call.

Regarding whether it's possible to no do a matrix transformation for orthoganal code, I feel that it should be, but can't report back; cutting stuff back to basics meant that that code went and, once I'd got it working, I sure wasn't going to put it back!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top