Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  JOGL Exception while running program  (Read 2783 times)
0 Members and 1 Guest are viewing this topic.
Offline vinodpatel

Senior Newbie





« Posted 2007-04-11 05:51:33 »



Dear All,

              I had written a following code but it gives me an exception.

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();
            glError(m_gl.glGetError());
         }
         return QEDResponseCode.Q3D_RENDERER_OK;
      }
      
      SQ3DVERTEX [] Vertices = prepareVertices(vertices, nbVertices);
      
      m_gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
      glError(m_gl.glGetError());
      
      FloatBuffer buffer = FloatBuffer.allocate(3);
      if(m_Texturing && !m_GenerateTexCoords){
         m_gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         glError(m_gl.glGetError());
         buffer.put(0,Vertices[0].u);
         buffer.put(0,Vertices[1].v);
         buffer.position(0);
         m_gl.glTexCoordPointer(2,GL.GL_FLOAT,0,buffer);
         glError(m_gl.glGetError());
      }
      else{
         m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         glError(m_gl.glGetError());
      }

      buffer.put(0,Vertices[0].pos.x);
      buffer.put(1,Vertices[0].pos.y);
      buffer.put(2,Vertices[0].pos.z);
      buffer.position(0);
      m_gl.glVertexPointer(3,GL.GL_FLOAT,0,buffer);
      glError(m_gl.glGetError());

      if(normals==null){
         m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
         glError(m_gl.glGetError());
         buffer.put(0,Vertices[0].normal.x);
         m_gl.glNormalPointer(GL.GL_FLOAT,0,buffer);
         glError(m_gl.glGetError());

         ShortBuffer shBuf = ShortBuffer.allocate(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.position(0);
         m_gl.glDrawElements(GL.GL_TRIANGLES,(int) nbIndex,GL.GL_UNSIGNED_SHORT,shBuf);
         glError(m_gl.glGetError());

         m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
         glError(m_gl.glGetError());
      }
      else{
         m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
         glError(m_gl.glGetError());
         m_gl.glBegin(GL.GL_TRIANGLES);
               int i;
               int face;
               for(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();
            glError(m_gl.glGetError());
            
         m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
         glError(m_gl.glGetError());
      }
      
      m_gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
      glError(m_gl.glGetError());

      if(m_Texturing && !m_GenerateTexCoords){
         m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         glError(m_gl.glGetError());
      }

                     And the exception i am getting is

Caused by: javax.media.opengl.GLException: Argument "ptr" was not a direct buffer
   at com.sun.opengl.impl.GLImpl.glVertexPointer(GLImpl.java:27940)
   at javax.media.opengl.DebugGL.glVertexPointer(DebugGL.java:11682)
   at com.qedsoft.renderer.abstractfile.renderer.impl.CQ3DRendererOpenGL.drawFacesByIndexFlat(CQ3DRendererOpenGL.java:1083)
   at com.qedsoft.renderer.abstractfile.renderer.impl.CQ3DRendererOpenGL.drawFacesByIndex(CQ3DRendererOpenGL.java:1015)


                     Line number 1083 is what i have saw bold in given code.

                     Please let me know what the problem is ?.......
                     

Thanks To All in Advance.
Offline Ultraq

Junior Devvie




That's what she said


« Reply #1 - Posted 2007-04-11 06:31:13 »

Caused by: javax.media.opengl.GLException: Argument "ptr" was not a direct buffer

Try changing the buffer type that gets passed into that method, into a direct buffer and see if it makes a difference.
ie: change the line that says:
    FloatBuffer buffer = FloatBuffer.allocate(3);
into:
    FloatBuffer buffer = FloatBuffer.allocateDirect(3);

Ultraq's Final MooCow
Bits and Pieces by Emanuel Rabina
Offline vinodpatel

Senior Newbie





« Reply #2 - Posted 2007-04-11 06:46:52 »



Dear Ultraq,

   Thanks for reply.

   But there is no method  allocateDirect in FloatBuffer class. That method exits only in ByteBuffer class.
   I am using float data rather than byte.

 Thanks in Advance.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #3 - Posted 2007-04-11 11:28:59 »

Hi,

use the newFloat/Int/...Buffer(elementCount) methods of the BufferUtil. The Util creates correct ordered (native order) direct Buffers.

And don't forget to rewind() your buffer before uploading it to OpenGL.

   But there is no method  allocateDirect in FloatBuffer class. That method exits only in ByteBuffer class.
   I am using float data rather than byte.
right, but you could create a FloatBuffers from ByteBuffers (see the source of BufferUtil if you are interested)

Offline vinodpatel

Senior Newbie





« Reply #4 - Posted 2007-04-11 12:07:38 »



Thanks a lot.

I have created direct buffer by using BufferUtil class of JOGL. It has various static methods to create long, float, short direct buffers.
Offline Ultraq

Junior Devvie




That's what she said


« Reply #5 - Posted 2007-04-12 06:44:38 »

But there is no method  allocateDirect in FloatBuffer class. That method exits only in ByteBuffer class.

Ah true.  My bad.  You can make a direct FloatBuffer using ByteBuffer.allocateDirect(), followed by ByteBuffer.asFloatBuffer().  Although I suspect JOGL's BufferUtil class will do that for you anyway.

Ultraq's Final MooCow
Bits and Pieces by Emanuel Rabina
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #6 - Posted 2007-04-12 16:02:43 »

It's also critical to set the byte order of the ByteBuffer to the native order before viewing it as a FloatBuffer, which the BufferUtil class does and which is why it's strongly recommended to use it instead of calling ByteBuffer.allocateDirect() yourself.
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (349 views)
2018-11-16 13:46:03

hadezbladez (181 views)
2018-11-16 13:41:33

hadezbladez (348 views)
2018-11-16 13:35:35

hadezbladez (84 views)
2018-11-16 13:32:03

EgonOlsen (2177 views)
2018-06-10 19:43:48

EgonOlsen (2206 views)
2018-06-10 19:43:44

EgonOlsen (1378 views)
2018-06-10 19:43:20

DesertCoockie (2011 views)
2018-05-13 18:23:11

nelsongames (1655 views)
2018-04-24 18:15:36

nelsongames (2300 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!