Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  now IndexedQuadArray works perfectly...  (Read 1902 times)
0 Members and 1 Guest are viewing this topic.
Offline mksingh1

Senior Newbie





« Posted 2006-05-26 17:17:11 »

while i was trying to implement  the Indexed geometry Array,i came across a problem.When i used the IndexedTriangleArray,the geometry has been drawn perfectly. But when i tried to use IndexedQuadArray,absolutely nothing was displayed on the screen.Isearched the forum,if anyone else has faced the sanme problem.I found many people who has also faced the same problem,but no one has comeup with the solution.
 Then i checed the library class of Xith, and i found that in PACKAGE--com.xith3d.render.jogl......CLASS----ShapeAtomPeer....METHOD---private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray), some code is missing...actually the functinality of IndexedTriangle is defined ,but nothing for IndexedQuadArray ,IndexedLineArray,IndexedLineStrip Array is defined. Then i just added the function of the missing Arrays, n it start working perfectly. PLzzz try this in ur programs, and let me know if it works correctly in ur programs also.
  The modified method is.......


  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... n plzzz let me know if it works...
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Reply #1 - Posted 2006-05-26 19:14:55 »

If it does work for you it probably works everywhere. I can integrate it into CVS after confirmation.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline mksingh1

Senior Newbie





« Reply #2 - Posted 2006-05-26 19:30:00 »

thanx buddy..i m sure,it will work 4 everyone.. Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Reply #3 - Posted 2006-05-27 09:43:15 »

thanx buddy..i m sure,it will work 4 everyone.. Smiley
Anyway it can't be worse that it's actually ^^ Let's commit.
Hmm.. yeah but now we are on JSR-231 renderer (since Xith3D 0.7) so is it compliant ?

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2006-05-27 09:52:42 »

Not that it's any of my business, but when looking at such code I get all itchy.

Not only are those if's a bit slower, it's also very messy. There is also a new IntBuffer object created for every glDrawElements (due to slice()).

When dealing with tens of thousands of items in the world, the preformance suffers significantly.

Why not do it OO,  where every ***Array has a render-method. It's more clean, and a tad faster.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (36 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!