1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
public void drawPolyLine(GL gl, String form,float ColorFirstCoord,float ColorSecondCoord,float ColorThirdCoord,Boolean IsTextured, String TextureURL, float TextureCoords[][], float x, float y, float z, double RotationAngle)
{
//gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); //Clear The Screen And The Depth Buffer
//gl.glLoadIdentity(); //Reset The View
gl.glRotatef((float) -RotationAngle,1,0,0);
gl.glTranslatef(x,y,z-2);
gl.glEnable(GL.GL_TEXTURE_2D);
TextureLoader.Texture tex1 = null;
// 1) We test if there is no texture for the polyline
if (TextureURL == null)
{
// 1.1) We draw a Triangle
if(form.toUpperCase().equals("TRIANGLE"))
{
// We begin drawing the Triangle
gl.glBegin(GL.GL_TRIANGLES);
gl.glNormal3f(0,0,1.0f);
// if the ColorFirstCoord is not -100 (is not null), we define the color for the Triangle
if (ColorFirstCoord !=-100)
{
gl.glColor3f(ColorFirstCoord,ColorSecondCoord,ColorThirdCoord) ;
}
for (int i=0;i< 3;i++)
{
gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
}
gl.glEnd();
}
// 1.2) We draw a Quad
if(form.toUpperCase().equals("QUADS"))
{
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0,0,1.0f);
// if the ColorFirstCoord is not -100 (is not null), we define the color for the quad
if (ColorFirstCoord !=-100)
{
gl.glColor3f(ColorFirstCoord,ColorSecondCoord,ColorThirdCoord) ;
}
for (int i=0;i<4;i++)
{
gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
}
gl.glEnd();
}
// 1.3) We draw a Polygon
if(form.toUpperCase() == "POLYGON")
{
gl.glBegin(GL.GL_POLYGON);
gl.glBegin(GL.GL_TRIANGLES);
for (int i=0;i< ThePolyLinePoints.size();i++)
{
gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
}
gl.glEnd();
}
}
// 2) If the polygone have a texture
else
{
try
{
tex1 = TextureLoader.readTexture(TextureURL);
}
catch(IOException e)
{
System.err.println("Unable to load texture : "+ TextureURL);
}
if( tex1 != null )
PolyLineTexture = tex1.toGL(gl,glu,false);
else
PolyLineTexture = -1;
// 2.1) We draw a Triangle
if(form.toUpperCase().equals("TRIANGLE"))
{
gl.glBindTexture(GL.GL_TEXTURE_2D, PolyLineTexture);
gl.glBegin(GL.GL_TRIANGLES);
gl.glNormal3f(0,0,1.0f);
for (int i=0;i< 3;i++)
{
gl.glTexCoord2d(TextureCoords[i][0],TextureCoords[i][1]);
gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
}
gl.glEnd();
}
// 2.2) We draw a Quad
if(form.toUpperCase().equals("QUADS"))
{
gl.glBindTexture(GL.GL_TEXTURE_2D, PolyLineTexture);
gl.glBegin(GL.GL_QUADS);
//gl.glNormal3f(0,0,1.0f);
for (int i=0;i<4;i++)
{
gl.glTexCoord2d(TextureCoords[i][0],TextureCoords[i][1]);
gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
}
gl.glEnd();
}
// 2.3) We draw a Polygon
if(form.toUpperCase() == "POLYGON")
{
gl.glBindTexture(GL.GL_TEXTURE_2D, PolyLineTexture);
gl.glBegin(GL.GL_POLYGON);
for (int i=0;i< ThePolyLinePoints.size();i++)
{
gl.glTexCoord2d(TextureCoords[i][0],TextureCoords[i][1]);
gl.glVertex3f(getPoint(i,ThePolyLinePoints).getX(),getPoint(i,ThePolyLinePoints).getY(),getPoint(i,ThePolyLinePoints).getZ());
}
gl.glEnd();
}
}
} // End drawPolyLine method |
Partager