Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  GLU tesselation problem  (Read 1223 times)
0 Members and 1 Guest are viewing this topic.
Offline zoppo

Junior Newbie




Java games rock!


« Posted 2004-06-12 22:29:48 »

Hello,

I hope someone can help me out. I added GLU tesselation for complex polygons to my renderer,
but it does not work for all cases.
It works for complex non-intersecting polygons,
I tried it with a VMAP0 data set - country boundaries for european states with 100k+ vertices. But once I try to tesselate this simple self-intersecting polygon:

0,0, 100,100, 0,100, 100,0

I get a complaint that the combine callback is not defined. Which is funny because this callback is called right before the error callback and it holds the correct new vertex position.

Also the begin, vertex and end callbacks are apparently not called at all...

I boiled this down into the following code, what am I doing wrong here?

private void drawTesselPoly(GL gl, GLU glu) {
   if( this.tesselator == null)
   {
       tesselator = glu.gluNewTess();                  
       glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_VERTEX, this);
                 glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_VERTEX_DATA, this);
                 glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_BEGIN, this);
                 glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_END, this);
                 glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_ERROR, this);
                 glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_COMBINE, this);
                 glu.gluTessCallback(this.tesselator, GLU.GLU_TESS_COMBINE_DATA, this);                  
           }
           
           glu.gluTessProperty(this.tesselator, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);            
                       
           TessPoint3D vertex1 = new TessPoint3D(0.0,0.0,0.0);
           
           glu.gluTessBeginPolygon( tesselator, vertex1);        
           glu.gluTessBeginContour(tesselator);

           glu.gluTessVertex(tesselator, new double[]{0, 0, 0} , new TessPoint3D(0, 0, 0));
           glu.gluTessVertex(tesselator, new double[]{100, 100, 0} , new TessPoint3D(100,100,0));
           glu.gluTessVertex(tesselator, new double[]{0, 100, 0} , new TessPoint3D(0,100,0));
           glu.gluTessVertex(tesselator, new double[]{100, 0, 0} , new TessPoint3D(100,0,0));
                                               
           glu.gluTessEndContour(tesselator);
           glu.gluTessEndPolygon(tesselator);            
     }


I defined the callbacks in my renderer class (which implements the
GLUtesselatorCallback) like this:


     public void begin(int arg0) {      
           gl.glBegin( arg0);      
     }
     
     public void beginData(int arg0, Object arg1) {
           gl.glBegin( arg0);            
     }
     
     public void vertex(Object arg0) {      
           TessPoint3D tessp = (TessPoint3D)arg0;      
           gl.glVertex3d( tessp.x, tessp.y, tessp.z);
     }

     public void vertexData(Object arg0, Object arg1) {            
           TessPoint3D tessp = (TessPoint3D)arg0;
           gl.glVertex3d( tessp.x, tessp.y, tessp.z);      
     }
     
     public void end() {
           gl.glEnd();      
     }
     
     public void endData(Object arg0) {
           gl.glEnd();            
     }
     
     public void combine(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3) {
           gl.glVertex3dv(arg0);                  
     }
     
     public void combineData(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3, Object arg4) {
           gl.glVertex3dv(arg0);
     }
     
     public void error(int arg0) {
           System.out.println("tess error: "+glu.gluErrorString(arg0));
     }
     
     public void errorData(int arg0, Object arg1) {
           System.out.println("tess errorData: "+glu.gluErrorString(arg0));            
     }

TessPoint is a small private class:

     private class TessPoint3D
     {
           public double x;
           public double y;
           public double z;
           
           public TessPoint3D(double p1, double p2, double p3) {
                 
                 x = p1; y = p2; z = p3;
           }            
     }  


Best regards,

Greg
Offline poonam

Junior Newbie




Java games rock!


« Reply #1 - Posted 2004-10-12 21:03:30 »

Hey Greg,
 I faced a similar problem and in my case I was getting the same point as an output of tessellation.

Replace your vertex callback function with this

public void vertex(Object vertexData)
{
  Point p = new Point();
  if (vertexData instanceof double[])
 {
   double[] myData = (double[]) vertexData;       
   if (myData.length == 6)
  {
     double[] d2 = {myData[0], myData[1], myData[2]};
     p = new Point(myData[0], myData[1]);
     pointList.add(p);
    gl.glVertex3dv(d2);                  
  }
 else
  {
   double[] d2 = {myData[0], myData[1], myData[2]};
   p = new Point(myData[0], myData[1]);
pointList.add(p);
                             gl.glVertex3dv(d2);      
                       }
           }
Offline poonam

Junior Newbie




Java games rock!


« Reply #2 - Posted 2004-10-12 21:10:54 »

Sorry, i hit post before completing the reply!

Ok, here i continue with the reply.

Disregard the Point data structures. Its just my internal representation class.


public void combine( double[] coords,Object[] data, float[] weight,      Object[] outData) {
           int i;      
           double[] vertex = new double[6];
           vertex[0] = coords[0];
           vertex[1] = coords[1];            
           vertex[2] = coords[2];
                       
           for (i=3; i < 6; i++)
           {
                 vertex = weight[0] * ((double[])data[0])
                                               + weight[1] * ((double[])data[1])
                                               + weight[2] * ((double[])data[2])
                                               + weight[3] * ((double[])data[3]);
           }



     outData[0] = vertex;
}



Also, when you are passing the points to the gluTessVertex(GLUtessellator, data, vertexData) function first fill in a 2-D array of points say P[numPoints][3] and fill it in with the polygon vertices that you need to tessellate. If you want to add additional information about vertex colors then make another array PData[numPoints][6] and fill it in with the first 3 data members as your vertex co-ordinates (x, y, z) and the other 3 as (r, g, b) triples.

now when call gluTessVertex(tesselator, P, PData) for every point "i" in your polygon.

This should solve the problem.
It did for me!

Hope that helps!
Poonam
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pepijnve

Junior Member




Java games rock!


« Reply #3 - Posted 2004-10-13 18:03:56 »

Quote
Hello,
     public void combine(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3) {
           gl.glVertex3dv(arg0);                  
     }
     
     public void combineData(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3, Object arg4) {
           gl.glVertex3dv(arg0);
     }


While not an error in the strict sense, the combine callback should not be sending vertices to OpenGL. The intention of this callback is to give you the opportunity to combine your own data structure into a new object. The last Object[] parameter is an output parameter. The idea is that you create the new object and put it in this array. An example of how you could implement it is as follows:
1  
2  
3  
public void combine(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3) {
  arg3[0] = new TessPoint3D(arg0[0], arg0[1], arg0[2]);
}

I don't remember for sure, but I think the reason why you may be getting an error is that the arg3 parameter contains null if you don't fill it yourself.
As an aside, if your point TessPoint3D will only contain x,y,z coordinates, it is not needed. You can replace
1  
glu.gluTessVertex(tesselator, new double[]{0, 0, 0} , new TessPoint3D(0, 0, 0));

with
1  
2  
double[] point = new double[] {0,0,0};
glu.gluTessVertex(tesselator, point, point);

and
1  
2  
3  
public void combine(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3) {
  arg3[0] = new TessPoint3D(arg0[0], arg0[1], arg0[2]);
}

with
1  
2  
3  
public void combine(double[] arg0, Object[] arg1, float[] arg2, Object[] arg3) {
  arg3[0] = arg0;
}

The reason why the glu tesselator makes the distinction between the parameters is so that if for instance you have a point object that also contains a color, that you can interpolate the color as well in the combine method.
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.

xsi3rr4x (62 views)
2014-04-15 18:08:23

BurntPizza (60 views)
2014-04-15 03:46:01

UprightPath (73 views)
2014-04-14 17:39:50

UprightPath (56 views)
2014-04-14 17:35:47

Porlus (73 views)
2014-04-14 15:48:38

tom_mai78101 (99 views)
2014-04-10 04:04:31

BurntPizza (159 views)
2014-04-08 23:06:04

tom_mai78101 (254 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!