Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (763)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
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  
  IndexedQuadArray bug?  (Read 1225 times)
0 Members and 1 Guest are viewing this topic.
Offline orz

Senior Newbie




Java games rock!


« Posted 2004-05-10 13:12:58 »

Hi all

I've just started to use Xith3D for a project, and I've encountered a problem using the IndexedQuadArray class. I've created an array of coordinates (coords), an array of normals (normals), and two int arrays specifying which coordinates and normals to use.

When creating the geometry using IndexedQuadArray I get no errors, but when I create a shape from the geometry and render it, nothing is shown. However, if I traverse the arrays myself, and then use QuadArray instead, everything works fine.

See the code attached below for details.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
//Doesn't work:
            //IndexedQuadArray tube = new IndexedQuadArray(coords.length, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, coordIndices.length);
            //tube.setCoordinateIndices(0, coordIndices);
            //tube.setNormals(0, normals);
            //tube.setNormalIndices(0, normalIndices);
            
            //Works fine:
            Point3f[] myCoords = new Point3f[coordIndices.length];
            Vector3f[] myNorms = new Vector3f[coordIndices.length];
            for (int i = 0; i < coordIndices.length; i++){
                  myCoords[i] = coords[coordIndices[i]];
                  myNorms[i] = normals[normalIndices[i]];
            }
            QuadArray tube = new QuadArray(myCoords.length, GeometryArray.COORDINATES | GeometryArray.NORMALS);
            tube.setCoordinates(0, myCoords);
            tube.setNormals(0, myNorms);


Edit: Saw the option to format the code :)
Offline mksingh1

Senior Newbie





« Reply #1 - Posted 2006-05-26 09:07:22 »

i guess there is no problem in ur code..the problem is with the one of the library class of Xith....go to the PACKAGE--com.xith3d.render.jogl......CLASS----ShapeAtomPeer....in this class go to the METHOD---private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray)....... in this method actually some code is missing..... i have made changes in this code....now the working code should be...



  private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray) {
       
        ProfileTimer.startProfile("drawGeometry");
        int numVertices = geoArray.getValidVertexCount();
//       
        if (numVertices == 0) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping because there are no valid vertices ");
            ProfileTimer.endProfile();
            return;
        }

       

        // get the format of verticies
        int format = geoArray.getVertexFormat();

        int stripCount = 0;
        int[] stripVertexCounts = null;

        // if a strip array then get the above two values
        if (geoArray instanceof GeometryStripArray) {
            stripCount = ((GeometryStripArray) geoArray).getNumStrips();
            stripVertexCounts = ((GeometryStripArray) geoArray).
                    getStripVertexCounts();
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a strip array " + stripCount + " strips");
        }

        // find out if color3f data was supplied and if it was use it


        int mode = 0;

        if ((geoArray instanceof IndexedGeometryArray)) {
            canvas.addTriangles( ((IndexedGeometryArray)geoArray).getValidIndexCount()/geoArray.getFaceSize());
           
        } else if (geoArray instanceof TriangleArray) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a triangle array with " + numVertices + " vertices");
            mode = GL.GL_TRIANGLES; // say that we want to draw trianlges
            canvas.addTriangles(numVertices/geoArray.getFaceSize());
        } else if (geoArray instanceof QuadArray) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a quad array with " + numVertices + " vertices");
            mode = GL.GL_QUADS; // say that we want to draw quads
            canvas.addTriangles(numVertices/geoArray.getFaceSize());
        } else if (geoArray instanceof PointArray) {
            mode = GL.GL_POINTS; // say that we want to draw points
            canvas.addTriangles(numVertices/geoArray.getFaceSize());
        } else if (geoArray instanceof LineArray) {
            mode = GL.GL_LINES; // say that we want to draw lines
        } else if (!(geoArray instanceof GeometryStripArray)) {
            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping unknown geometry : " + geoArray.getClass().getName());
           
            ProfileTimer.endProfile();
            return; // don't know how to draw this
        }

        // do the actual drawing genericly

        setupBuffers(canvas, gl, geoArray);
        if (geoArray instanceof GeometryStripArray) {

            //setPointers(gl);

            if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Starting drawing strips for GeometryStripArray");
            // loop through the strips

            if (geoArray instanceof LineStripArray) {
                mode = GL.GL_LINE_STRIP; // say that we want to draw a line strip
            } else if (geoArray instanceof TriangleStripArray) {
                mode = GL.GL_TRIANGLE_STRIP; // say that we want to draw a triangle strip
//                if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG,"Drawing a triangle strip "+strip+" of "+stripCount+" strips and "+stripVertexCounts[strip]+" vertices");
            } else if (geoArray instanceof TriangleFanArray) {
                mode = GL.GL_TRIANGLE_FAN; // say that we want to draw a triangle fan
            }

            int start = 0;
            for (int strip = 0; strip < stripCount; strip++) {

                gl.glDrawArrays(mode, start, stripVertexCounts[strip]);
                start += stripVertexCounts[strip];

            }
        } else if (geoArray instanceof IndexedGeometryArray) {
           if (geoArray instanceof IndexedLineArray) {
                mode = GL.GL_LINES; // say that we want to draw points
                IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
                gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
            }
           
           if (geoArray instanceof IndexedQuadArray) {
                 mode = GL.GL_QUADS; // say that we want to draw points
                 IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
                 gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
             }
            if (geoArray instanceof IndexedTriangleArray) {
                mode = GL.GL_TRIANGLES; // say that we want to draw points
                IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
                gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
            } else if ( geoArray instanceof IndexedGeometryStripArray ) {
                if ( geoArray instanceof IndexedTriangleStripArray ) {
               mode = GL.GL_TRIANGLE_STRIP;
                IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                int[] strips = igsa.getStripVertexCounts();
                int start = 0;
                for (int s = 0; s < strips.length; s++) {
                    gl.glDrawElements(mode,strips,GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                    start += strips;
                }
            }
                if ( geoArray instanceof IndexedLineStripArray ) {
                   mode = GL.GL_LINE_STRIP;
                    IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                    int[] strips = igsa.getStripVertexCounts();
                    int start = 0;
                    for (int s = 0; s < strips.length; s++) {
                        gl.glDrawElements(mode,strips,GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                        start += strips;
                    }
                }
                if ( geoArray instanceof IndexedTriangleFanArray ) {
                   mode = GL.GL_TRIANGLE_FAN;
                    IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                    int[] strips = igsa.getStripVertexCounts();
                    int start = 0;
                    for (int s = 0; s < strips.length; s++) {
                        gl.glDrawElements(mode,strips,GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                        start += strips;
                    }
                } 
            }
           
        } else {
            gl.glDrawArrays(mode, geoArray.getInitialVertexIndex(), geoArray.getValidVertexCount());
        }
        ProfileTimer.endProfile();
    }



i guess replacing the previous code with this one,will solve ur problem......try this...All the best...
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

nelsongames (1058 views)
2018-04-24 18:14:32

ivj94 (1637 views)
2018-03-24 14:47:39

ivj94 (562 views)
2018-03-24 14:46:31

ivj94 (1459 views)
2018-03-24 14:43:53

Solater (567 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!