this question has answer here:
- texture not applying mesh - opengl 1 answer
i using openggl es 2 in android render 3d object. facing problem object not render means nothing drawn on screen.
public void draw(gl10 gl) { gl.glcolor4f(0.0f, 1.0f, 0.0f, 0.5f); gl.glvertexpointer(3, gl10.gl_float, 0, vertexbuffer); gl.glenableclientstate(gl10.gl_vertex_array); for(int i=0; i<parts.size(); i++) { tdmodelpart t=parts.get(i); gl.glnormalpointer(gl10.gl_float, 0, t.getnormalbuffer()); gl.gldrawelements(gl10.gl_triangles,t.getfacescount(),gl10.gl_float,t.getfacebuffer()); gl.gldisableclientstate(gl10.gl_vertex_array); } } public class tdmodelpart { vector<float> faces; vector<float> vtpointer; vector<float> vnpointer; material material; private floatbuffer normalbuffer; floatbuffer facebuffer; public tdmodelpart(vector<float> faces, vector<float> vtpointer, vector<float> vnpointer, material material, vector<float> vn) { super(); this.faces = faces; this.vtpointer = vtpointer; this.vnpointer = vnpointer; this.material = material; bytebuffer bytebuf = bytebuffer.allocatedirect(vnpointer.size() * 4*3); bytebuf.order(byteorder.nativeorder()); normalbuffer = bytebuf.asfloatbuffer(); for(int i=0; i<vnpointer.size(); i++){ float x=vn.get((int) (vnpointer.get(i)*3)); float y=vn.get((int) (vnpointer.get(i)*3+1)); float z=vn.get((int) (vnpointer.get(i)*3+2)); normalbuffer.put(x); normalbuffer.put(y); normalbuffer.put(z); } normalbuffer.position(0); bytebuffer fbuf = bytebuffer.allocatedirect(faces.size() * 4); fbuf.order(byteorder.nativeorder()); facebuffer = fbuf.asfloatbuffer(); facebuffer.put(toprimitivearrays(faces)); facebuffer.position(0); } public string tostring() { string str=new string(); if(material!=null) str+="material name:"+material.getname(); else str+="material not defined!"; str+="\nnumber of faces:"+faces.size(); str+="\nnumber of vnpointers:"+vnpointer.size(); str+="\nnumber of vtpointers:"+vtpointer.size(); return str; } public floatbuffer getfacebuffer() { return facebuffer; } public floatbuffer getnormalbuffer() { return normalbuffer; } private static float[] toprimitivearrays(vector<float> vector) { float[] s; s=new float[vector.size()]; (int i=0; i<vector.size(); i++){ s[i]=vector.get(i); } return s; } public int getfacescount() { return faces.size(); } public material getmaterial() { return material; } }
first of all, set data glnormalpointer
, don't ever glenableclientstate(gl_normal_array)
. , disable vertex array (gldisableclientstate(gl_vertex_array)
) @ end of loop block, means after drawing first part, following parts won't draw anything, since have no vertex array enabled.
likewise doesn't fit normal data specified per-part while vertex data specified once parts. maybe intended looks strange, since vertices (or rather positions) , normals (and other attributes) have match, i.e. draw commands drawing arrays use same index accessing enabled attribute arrays single vertex.
Comments
Post a Comment