Hello,
Initialization Code
=============================================================
// Initialize rendering context
m_gl.glEnable(GL.GL_CULL_FACE);
m_gl.glEnable(GL.GL_DEPTH_TEST);
m_gl.glShadeModel(GL.GL_SMOOTH);
m_gl.glDepthFunc(GL.GL_LESS);
m_gl.glClearDepth(1);
m_gl.glClearColor(0, 0, 0, 0);
// Alpha
m_gl.glDisable(GL.GL_BLEND);
m_gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
// Lights
for (int Jcount = GL.GL_LIGHT0; Jcount <= GL.GL_LIGHT7; Jcount++) {
m_gl.glDisable(Jcount);
}
m_gl.glEnable(GL.GL_LIGHTING);
m_gl.glFrontFace(GL.GL_CW);
m_gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
m_DebugFontHeight = 16;
if (m_DeviceContext == null) {
}
m_Texturing = false;
m_GenerateTexCoords = false;
m_EnvMapOn = false;
m_NormalizeNormals = false;
m_ViewMatrix.setIdentity();
m_WorldMatrix.setIdentity();
endRendererContext();
setActive(true);
setRendererType("OpenGL");
setRendererSubType("");
return QEDResponseCode.Q3D_RENDERER_OK;
rendering code
---------------------------------------------------------------------------------------
try{
if (m_Texturing && m_EnvMapOn && normals != null) {
CQ3DMatrix worldview = new CQ3DMatrix();
worldview.mul(m_ViewMatrix, m_WorldMatrix);
for (int i = 0, face = 0; i < nbIndex; i += 3, face++) {
CQ3DVector normal = new CQ3DVector();
normal.assign(normals[face]);
normal.transformNoTrans(worldview);
if (m_NormalizeNormals) {
normal.normalize(); // Maybe a scale ???
}
float UV[] = new float[2];
UV[0] = normal.m_Vector.x * 0.5f + 0.5f;
UV[1] = normal.m_Vector.y * 0.5f + 0.5f;
float norm[] = new float[3];
norm[0] = normals[face].x;
norm[1] = normals[face].y;
norm[2] = normals[face].z;
m_gl.glBegin(GL.GL_TRIANGLES);
m_gl.glNormal3fv(norm, 0);
m_gl.glTexCoord3fv(UV, 0);
norm[0] = vertices[faces[face + faceindex].a].pos.x;
norm[1] = 0;
norm[2] = 0;
m_gl.glVertex3fv(norm, 0);
norm[0] = vertices[faces[face + faceindex].b].pos.x;
m_gl.glVertex3fv(norm, 0);
norm[0] = vertices[faces[face + faceindex].c].pos.x;
m_gl.glVertex3fv(norm, 0);
m_gl.glEnd();
}
return QEDResponseCode.Q3D_RENDERER_OK;
}
SQ3DVERTEX[] Vertices = prepareVertices(vertices, nbVertices);
m_gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
//FloatBuffer buffer = BufferUtil.newFloatBuffer(Vertices.length * 2);
FloatBuffer buffer = getFloatBuffer((int)nbVertices*2,1);
if (m_Texturing && !m_GenerateTexCoords) {
m_gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
for (int Icount = 0; Icount < nbVertices; Icount++) {
buffer.put(Vertices[Icount].u);
buffer.put(Vertices[Icount].v);
}
buffer.rewind();
m_gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, buffer);
} else {
m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
}
//buffer = BufferUtil.newFloatBuffer(Vertices.length * 3);
buffer = getFloatBuffer((int)nbVertices*3,2);
for (int Icount = 0; Icount < nbVertices; Icount++) {
buffer.put(Vertices[Icount].pos.x);
buffer.put(Vertices[Icount].pos.y);
buffer.put(Vertices[Icount].pos.z);
}
buffer.rewind();
m_gl.glVertexPointer(3, GL.GL_FLOAT, 0, buffer);
if (normals == null){
m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
//buffer = BufferUtil.newFloatBuffer(Vertices.length*3);
buffer = getFloatBuffer((int)nbVertices*3,3);
for (int Icount = 0; Icount < nbVertices; Icount++) {
buffer.put(Vertices[Icount].normal.x);
buffer.put(Vertices[Icount].normal.y);
buffer.put(Vertices[Icount].normal.z);
}
buffer.rewind();
m_gl.glNormalPointer(GL.GL_FLOAT, 0, buffer);
//ShortBuffer shBuf = BufferUtil.newShortBuffer(faces.length * 3);
ShortBuffer shBuf = getShortBuffer(faces.length * 3);
for (int Icount = faceindex; Icount < faces.length; Icount++) {
shBuf.put((short) faces[Icount].a);
shBuf.put((short) faces[Icount].b);
shBuf.put((short) faces[Icount].c);
}
shBuf.rewind();
m_gl.glDrawElements(GL.GL_TRIANGLES, (int) nbIndex,GL.GL_UNSIGNED_SHORT, shBuf);
m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
} else {
m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
m_gl.glBegin(GL.GL_TRIANGLES);
for (int i = 0, face = 0; i < nbIndex; i += 3) {
buffer.put(0, normals[face].x);
buffer.put(1, normals[face].y);
buffer.put(2, normals[face].z);
m_gl.glNormal3fv(buffer);
m_gl.glArrayElement(faces[face + faceindex].a);
m_gl.glArrayElement(faces[face + faceindex].b);
m_gl.glArrayElement(faces[face + faceindex].c);
face++;
}
m_gl.glEnd();
m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
}
m_gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
if (m_Texturing && !m_GenerateTexCoords) {
m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
}
}
catch(NullPointerException e){
logger.error("Vertices object =" + vertices);
logger.error("Normals object =" + normals);
logger.error("Faces object =" + faces);
}
return QEDResponseCode.Q3D_RENDERER_OK;
Renderer state method code
switch ((int) state)
{
case QEDConstantCode.Q3DRENDERSTATE_ZTESTENABLE:
{
if (value > 0){
m_gl.glEnable(GL.GL_DEPTH_TEST);
}
else{
m_gl.glDisable(GL.GL_DEPTH_TEST);
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_ZWRITEENABLE:
{
if (value > 0)
m_gl.glDepthMask(true);
else
m_gl.glDepthMask(false);
}
break;
case QEDConstantCode.Q3DRENDERSTATE_COLORWRITEENABLE:
{
if (value > 0)
m_gl.glColorMask(true, true, true, true);
else
m_gl.glColorMask(false, false, false, false);
}
break;
case QEDConstantCode.Q3DRENDERSTATE_FILLMODE:
{
switch ((int) value)
{
case QEDConstantCode.Q3DFILL_WIREFRAME:
m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
m_gl.glDisable(GL.GL_POLYGON_SMOOTH);
break;
case QEDConstantCode.Q3DFILL_SOLID:
m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
break;
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_SHADEMODE:
{
switch ((int) value)
{
case QEDConstantCode.Q3DSHADE_FLAT:
{
m_gl.glShadeModel(GL.GL_FLAT);
}
break;
case QEDConstantCode.Q3DSHADE_GOURAUD:
{
m_gl.glShadeModel(GL.GL_SMOOTH);
}
break;
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_SPECULARENABLE: {}
break;
case QEDConstantCode.Q3DRENDERSTATE_AMBIENT:
{
float tab[] = new float[4];
tab[0] = ((float) ((value >> 16) & 0xFF)) / 255.0f;
tab[1] = ((float) ((value >> 8) & 0xFF)) / 255.0f;
tab[2] = ((float) ((value) & 0xFF)) / 255.0f;
tab[3] = ((float) ((value >> 24) & 0xFF)) / 255.0f;
m_gl.glEnable(GL.GL_LIGHTING);
m_gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, FloatBuffer.wrap(tab));
}
break;
case QEDConstantCode.Q3DRENDERSTATE_CULLMODE:
{
switch ((int) value)
{
case QEDConstantCode.Q3DCULL_NONE:
{
m_gl.glDisable(GL.GL_CULL_FACE);
}
break;
case QEDConstantCode.Q3DCULL_CCW:
{
m_gl.glFrontFace(GL.GL_CW);
m_gl.glCullFace(GL.GL_BACK);
m_gl.glEnable(GL.GL_CULL_FACE);
}
break;
case QEDConstantCode.Q3DCULL_CW:
{
m_gl.glFrontFace(GL.GL_CCW);
m_gl.glCullFace(GL.GL_BACK);
m_gl.glEnable(GL.GL_CULL_FACE);
}
break;
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_TWOSIDED:
{
m_gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, (int) value);
}
break;
case QEDConstantCode.Q3DRENDERSTATE_LIGHTING:
{
if (value > 0){
m_gl.glEnable(GL.GL_LIGHTING);
}
else{
m_gl.glDisable(GL.GL_LIGHTING);
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_COLORVERTEX: {}
break;
case QEDConstantCode.Q3DRENDERSTATE_NORMALIZENORMALS:
{
if (value > 0) {
m_gl.glEnable(GL.GL_NORMALIZE);
m_NormalizeNormals = true;
} else {
m_gl.glDisable(GL.GL_NORMALIZE);
m_NormalizeNormals = false;
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_ALPHABLENDENABLE:
{
if (value > 0) {
m_gl.glEnable(GL.GL_BLEND);
m_gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
m_gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
}else{
m_gl.glDisable(GL.GL_BLEND);
m_gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
}
}
break;
}
Regards