java - Android Open GL ES Textures messed up -


i have own method draw images. uses vertex , uvbuffers.

i draw following:

spritebatch.begin(blendmode) <- sets blending spritebatch.draw(parameters) <- add vertices list of vertex arrays spritebatch.end() <- sets buffers , draw out @ once 

and works charm.

however when try drawstring method uses same draw method. texture uv maps or buffers screwed (everything draws solid rectangle missing pixels).

i use angelcode bitmap font generator.

i use same functinality difference set textures , uv maps according current character's data.

i post draw functions in case messed in other functions.

public void begin(int source, int destination) {     gl.glenable(gl10.gl_blend);     gl.glblendfunc(source, destination); } 

all buffers , variables (i didn't want declare in functions)

arraylist<float[]> vertices = new arraylist<float[]>(); floatbuffer vertexbuffer; arraylist<short[]> indices = new arraylist<short[]>(); shortbuffer indexbuffer; float minu = 0; float maxu = 1; float minv = 0; float maxv = 1; arraylist<glcolor> colors = new arraylist<glcolor>(); glcolor c_color; arraylist<float[]> vertexuvs = new arraylist<float[]>(); floatbuffer uvbuffer; arraylist<transformationmatrix> matrices = new arraylist<transformationmatrix>(); transformationmatrix matrix = new transformationmatrix(); arraylist<integer> textures = new arraylist<integer>(); 

draw method accesses main method drawstring

public void draw(texture2d texture, rectangle destination, rectangle source, glcolor color) {     draw(texture, destination, source, color, new vector2(0, 0), 0); } 

draw method

public void draw(texture2d texture, rectangle destination, rectangle source, glcolor color, vector2 origin, float rotation) {     vertices.add(new float[]{-origin.x, -origin.y,             destination.width - origin.x, -origin.y,             destination.width - origin.x, destination.height - origin.y,                     -origin.x, destination.height - origin.y});      indices.add(new short[]{0, 1, 2, 2, 3, 0});      //generate uv of vertices      minu = 0;     maxu = 1;     minv = 0;     maxv = 1;      if (source != null)     {         minu = (float)source.x / (float)texture.getwidth();         maxu = (float)(source.x + source.width) / (float)texture.getwidth();         minv = (float)source.y / (float)texture.getheight();         maxv = (float)(source.y + source.height) / (float)texture.getheight();     }     vertexuvs.add(new float[]{minu, minv,                         maxu, minv,                         maxu, maxv,                         minu, maxv});      //calculate matrix     matrix = new transformationmatrix();     matrix.translate(destination.x + origin.x, destination.y + origin.y, 0);     matrix.rotate(0, 0, rotation);     matrices.add(matrix);      colors.add(color);     textures.add(texture.id);     } 

draw string method (that causes bugs)

public void drawstring(spritefont spritefont, string text, vector2 vector, glcolor color) {     int cursorx = (int)vector.x;     int cursory = (int)vector.y;      (int = 0; < text.length(); i++)     {         char c = text.charat(i);         if (c == '\n') cursorx += spritefont.lineheight;         else         {             int index = (int)c;              //draw character             if (spritefont.characters.length <= index)             {                 log.d("spritefont error", "character not presented in spritefont!");                 continue;             }              characterdescriptor cd = spritefont.characters[index];              rectangle source = new rectangle(cd.x, cd.y, cd.width, cd.height);             //draw character             rectangle destination = new rectangle(cursorx + cd.xoffset, cursory + cd.yoffset, cd.width, cd.height);              draw(spritefont.pages[cd.page], destination, source, color);              cursorx += cd.xadvance;         }     } } 

and ending method:

public void end() {     vertexbuffer = bytebuffer.allocatedirect(vertices.size() * 8 * 4).order(byteorder.nativeorder()).asfloatbuffer();     (int = 0; < vertices.size(); i++)     {         vertexbuffer.put(vertices.get(i));     }     vertexbuffer.flip();       //generate indices     indexbuffer = bytebuffer.allocatedirect(indices.size() * 6 * 2).order(byteorder.nativeorder()).asshortbuffer();     (int = 0; < vertices.size(); i++)     {         indexbuffer.put(indices.get(i));     }     indexbuffer.flip();      //generate uv of vertices     uvbuffer = bytebuffer.allocatedirect(vertexuvs.size() * 8 * 4).order(byteorder.nativeorder()).asfloatbuffer();     (int = 0; < vertexuvs.size(); i++)     {         uvbuffer.put(vertexuvs.get(i));     }     uvbuffer.flip();      //bind vertices      (int = 0; < colors.size(); i++)     {         //bind pointers         gl.glenableclientstate(gl10.gl_vertex_array);         gl.glenableclientstate(gl10.gl_texture_coord_array);         gl.glenable(gl10.gl_texture_2d);         vertexbuffer.position(i * 8);         gl.glvertexpointer(2, gl10.gl_float, 0, vertexbuffer);         uvbuffer.position(i * 8);         gl.gltexcoordpointer(2, gl10.gl_float, 0, uvbuffer);         matrix = matrices.get(i);         c_color = colors.get(i);          gl.glmatrixmode(gl10.gl_modelview);         gl.glloadidentity();         gl.gltranslatef(matrix.translationx, matrix.translationy, matrix.translationz);         gl.glrotatef((float)math.sqrt(matrix.rotationx * matrix.rotationx + matrix.rotationy*matrix.rotationy + matrix.rotationz*matrix.rotationz), matrix.rotationx, matrix.rotationy, matrix.rotationz);         //bind texture         gl.glbindtexture(gl10.gl_texture_2d, textures.get(i));         gl.glcolor4f(c_color.r, c_color.g, c_color.b, c_color.a);          //draw elements         gl.gldrawelements(gl10.gl_triangles, 8, gl10.gl_unsigned_short, indexbuffer);          gl.glbindtexture(gl10.gl_texture_2d, 0);         gl.gldisable(gl10.gl_texture_2d);         gl.gldisableclientstate(gl10.gl_vertex_array);         gl.gldisableclientstate(gl10.gl_texture_coord_array);     }      //disable things     gl.gldisable(gl10.gl_blend);     colors.clear();     matrices.clear();     vertices.clear();     vertexuvs.clear(); } 

i still try find solution. i'll try post image understanding problem. in advance.

i feel ashamed answer questions everytime found out. didn't clear texture buffer draw buffers. don't had no real question on site. @ least it's solved now. feel stupid after solving 1 of problems. comments though!


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -