Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - zelo

Pages: [1]
1
Support / Android Colorovo CityTab Vision 3D Glass free 3d tablet
« on: April 22, 2014, 11:09:33 am »
Hi all,

I would like to develop a simple 3d application to Colorovo CityTab Vision 3D tablet. It is a glass free 3d tablet.

This device use vertical interlaced 3d display and It must be created "manually".

I create a sample app:

Code: [Select]
public class Stencil {
/*
* this code generates the interlaced pattern to the stencil buffer for
* stereoscopic masking
*/

private float vertices[];

private FloatBuffer vertexBuffer;

public Stencil() {


}

void interlace_stencil(GL10 gl, int gliWindowWidth, int gliWindowHeight) {

vertex(gliWindowWidth, gliWindowHeight);
// seting screen-corresponding geometry
gl.glViewport(0, 0, gliWindowWidth, gliWindowHeight);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glLoadIdentity();
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
//
// // clearing and configuring stencil drawing
gl.glEnable(gl.GL_STENCIL_TEST);
gl.glClearStencil(0);
gl.glClear(gl.GL_STENCIL_BUFFER_BIT);
gl.glStencilOp(gl.GL_REPLACE, gl.GL_REPLACE, gl.GL_REPLACE); //
// colorbuffer
// // is
// // copied to stencil
gl.glDisable(gl.GL_DEPTH_TEST);
gl.glStencilFunc(gl.GL_ALWAYS, 1, 1); // to avoid interaction with
// stencil
// content
// drawing stencil pattern
gl.glColor4f(1, 1, 1, 1);
// gl.glColor4f(1, 1, 1, 0); // alfa is 0 not to interfere with alpha
// tests
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// Set the face rotation
gl.glFrontFace(GL10.GL_CW);

// Point to our vertex buffer
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

// Draw the vertices
gl.glDrawArrays(GL10.GL_LINES, 0, vertices.length / 3);

// Disable the client state before leaving
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP); // disabling
// changes
// buffer
gl.glFlush();
}

private void vertex(int gliWindowWidth, int gliWindowHeight) {
float gliY = -1;

ArrayList<Float> ver = new ArrayList<Float>();
for (int i = 0; i < gliWindowWidth; i += 2) {
double d = (1f/Float.valueOf(gliWindowWidth))*2.0;

float f = ((float) (i*d))-1f;

ver.add(f);
ver.add(-1f);
ver.add(0f);

ver.add(f);
ver.add(1f);
ver.add(0f);

}
Float[] temp = ver.toArray(new Float[ver.size()]);

vertices = new float[temp.length];
for (int i = 0; i < temp.length; i++) {
Float float1 = temp[i];
vertices[i] = float1.floatValue();
}
// a float has 4 bytes so we allocate for each coordinate 4 bytes
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());

// allocates the memory from the byte buffer
vertexBuffer = byteBuffer.asFloatBuffer();

// fill the vertexBuffer with the vertices
vertexBuffer.put(vertices);

// set the cursor position to the beginning of the buffer
vertexBuffer.position(0);
}
}

Code: [Select]
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT
| GL10.GL_STENCIL_BUFFER_BIT);

stencil.interlace_stencil(gl, width, height);

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,
100.0f);
gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();


gl.glStencilFunc(gl.GL_NOTEQUAL, 1, 1); // draws if stencil <> 1
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); /* black */
gl.glClear(gl.GL_COLOR_BUFFER_BIT);

gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -10.0f);
gl.glRotatef(mCubeRotation, 1.0f, 1.0f, 1.0f);

setLeftEnv(gl);
gl.glEnable(GL10.GL_DEPTH_TEST);
mCube.draw(gl);

gl.glStencilFunc(gl.GL_EQUAL, 1, 1); // draws if stencil <> 0
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -10.0f);
gl.glRotatef(mCubeRotation, 1.0f, 1.0f, 1.0f);

setRightEnv(gl);
gl.glEnable(GL10.GL_DEPTH_TEST);
mCube.draw(gl);

gl.glLoadIdentity();

mCubeRotation -= 0.15f;
}

private void setLeftEnv(GL10 gl) {
GLU.gluLookAt(gl, 0 - (mEyeDistance), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f,
0.0f, 1.0f, 0.0f);

}

private void setRightEnv(GL10 gl) {
GLU.gluLookAt(gl, 0 + (mEyeDistance), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f,
0.0f, 1.0f, 0.0f);

}

It works well. But I don't know, how to implement this with JPCT-AE.
Can you help me?

Thank you in anticipation.

Pages: [1]