Skip to content

Instantly share code, notes, and snippets.

@narrowtux
Created November 21, 2011 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narrowtux/1383796 to your computer and use it in GitHub Desktop.
Save narrowtux/1383796 to your computer and use it in GitHub Desktop.
GenericPolygon.java
p.addPoint(0, 0, new Color(0xffffffff));
p.addPoint(0, 10, new Color(0xffffffff));
p.addPoint(10, 10, new Color(0xffffffff));
p.addPoint(10, 0, new Color(0xffffffff));
public class GenericPolygon extends GenericWidget implements Polygon {
LinkedList<Pair<Point, Color>> points = new LinkedList<Pair<Point,Color>>();
Color lastColor = null;
public WidgetType getType() {
return WidgetType.Polygon;
}
public void render() {
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glBlendFunc(770, 771);
GL11.glShadeModel(GL11.GL_SMOOTH);
MinecraftTessellator t = Spoutcraft.getTessellator();
t.startDrawingQuads();
for(Pair<Point, Color> point:points) {
Point p = point.getLeft();
Color c = point.getRight();
System.out.println("Drawing "+p+" "+c);
t.setColorRGBAFloat(c.getRedF(), c.getGreenF(), c.getBlueF(), c.getAlphaF());
t.addVertex(p.getX(), p.getX(), 0);
}
t.draw();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
...
}
/*
* This file is part of Spoutcraft (http://wiki.getspout.org/).
*
* Spoutcraft is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Spoutcraft is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.spoutcraft.spoutcraftapi.gui;
public class Point {
private int x, y;
public Point() {
x = 0;
y = 0;
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point(Point other) {
this.x = other.x;
this.y = other.y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Point copy() {
return new Point(this);
}
@Override
public String toString() {
return "Point{x="+x+"; y="+y+"}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment