Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Animation Program Crash  (Read 457 times)
0 Members and 1 Guest are viewing this topic.
Offline vinodpatel

Senior Newbie





« Posted 2007-06-01 08:39:56 »


Hello All,

               I am new in openGL. I am developing one animation application. The code of one of the function is shown below. The method written in bold letter results in to JVM crash.

              Is there any other way exists to do the same thing without using the glDrawElements function.

***********************
      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 Huh
            }

            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 0;
      }

      SQ3DVERTEX[] Vertices = prepareVertices(vertices, nbVertices);

      m_gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
      logger.error("GL_VERTEX_ARRAY is enabled.");
      
      FloatBuffer buffer = BufferUtil.newFloatBuffer(Vertices.length * 2);
      if (m_Texturing && !m_GenerateTexCoords) {
         m_gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         logger.error("GL_TEXTURE_COORD_ARRAY is enabled.");
         for (int Icount = 0; Icount < Vertices.length; 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);
         logger.error("GL_TEXTURE_COORD_ARRAY is disabled.");
      }

      buffer = BufferUtil.newFloatBuffer(Vertices.length * 3);
      for (int Icount = 0; Icount < Vertices.length; 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);
         logger.error("GL_NORMAL_ARRAY is enabled.");
         buffer = BufferUtil.newFloatBuffer(Vertices.length);
         for (int Icount = 0; Icount < Vertices.length; Icount++) {
            buffer.put(Vertices[Icount].normal.x);
         }
         buffer.rewind();
         m_gl.glNormalPointer(GL.GL_FLOAT, 0, buffer);

         ShortBuffer shBuf = BufferUtil.newShortBuffer(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);
         logger.error("GL_NORMAL_ARRAY is disabled.");
      } else {
         m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
         logger.error("GL_NORMAL_ARRAY is disabled.");
         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);
         logger.error("GL_NORMAL_ARRAY is enabled.");
      }

      m_gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
      logger.error("GL_VERTEX_ARRAY is disabled.");

      if (m_Texturing && !m_GenerateTexCoords) {
         m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         logger.error("GL_TEXTURE_COORD_ARRAY is disabled.");
      }
      logger.error("");



******************

Regards
Vinod Patel
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (106 views)
2013-05-17 21:29:12

alaslipknot (114 views)
2013-05-16 21:24:48

gouessej (143 views)
2013-05-16 00:53:38

gouessej (139 views)
2013-05-16 00:17:58

theagentd (151 views)
2013-05-15 15:01:13

theagentd (135 views)
2013-05-15 15:00:54

StreetDoggy (179 views)
2013-05-14 15:56:26

kutucuk (202 views)
2013-05-12 17:10:36

kutucuk (203 views)
2013-05-12 15:36:09

UnluckyDevil (209 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.123 seconds with 21 queries.