opengl - Generating a sphere manually -


in opengl (lwjgl java), using glu.sphere.sphere() can make easy generate sphere after tens of spheres 32x32 resolution, becomes slow. im thinking of using buffers send vertices+colors+normals+indices once , change them using opencl.

question: if take origin (0,0,0) center of sphere, can choose normal equal vertex?

example: north pole of sphere vertex=(0,1,0) can surface-normal (0,1,0) again? can same thing vertices? element array order if can make optimized? guessing triangle vertex can used many neighbour triangles. im begineer need pointer useage of efficient drawelementarray function , index array generation.

note: im keeping cpu @ 1400mhz cant handle computing on host side , opengl not accept multi-threaded drawing of spheres.

following valentin's suggestion, opened inside of glu , found drawing element element. use buffer generation.

if (this.drawstyle == 100010)         {           gl11.glbegin(0);           if (normals)             gl11.glnormal3f(0.0f, 0.0f, nsign);           gl11.glvertex3f(0.0f, 0.0f, radius);           if (normals)             gl11.glnormal3f(0.0f, 0.0f, -nsign);           gl11.glvertex3f(0.0f, 0.0f, -radius);            (int = 1; < stacks - 1; i++) {             float rho = * drho;             (int j = 0; j < slices; j++) {               float theta = j * dtheta;               float x = cos(theta) * sin(rho);               float y = sin(theta) * sin(rho);               float z = cos(rho);               if (normals)                 gl11.glnormal3f(x * nsign, y * nsign, z * nsign);               gl11.glvertex3f(x * radius, y * radius, z * radius);             }           }           gl11.glend(); 

the reason getting slower , slower, because glu geometry meshes rendered using glu uses immediate mode rendering.

you download java decompiler , decompile lwjgl_util.jar, follow package paths glu.sphere.sphere() , can lookup draw() method. take , see how code works, , create own method instead of using glvertex, etc methods. add values floatbuffer, , create vbo of sphere.

here free java decompiler!


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -