本文整理匯總了Java中javax.media.opengl.GL.glColor3d方法的典型用法代碼示例。如果您正苦於以下問題:Java GL.glColor3d方法的具體用法?Java GL.glColor3d怎麽用?Java GL.glColor3d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.media.opengl.GL
的用法示例。
在下文中一共展示了GL.glColor3d方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: renderText
import javax.media.opengl.GL; //導入方法依賴的package包/類
private void renderText(GL gl, String text, int x, int y, int font) {
int viewport[] = new int[4];
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
{
gl.glOrtho(0, viewport[2], 0, viewport[3], -1, 1);
gl.glColor3d(1, 1, 1);
gl.glRasterPos3d(0, 0, 0);
glut.glutBitmapString(font, text);
}
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
}
示例2: drawFaceLinesForDebug
import javax.media.opengl.GL; //導入方法依賴的package包/類
public void drawFaceLinesForDebug(GL gl){
for(CSG_Polygon poly : polygons){
if(poly.type == CSG_Polygon.POLY_TYPE.POLY_INSIDE){ // red
gl.glColor3d(0.5, 0.2, 0.2);
}
if(poly.type == CSG_Polygon.POLY_TYPE.POLY_OUTSIDE){ // green
gl.glColor3d(0.2, 0.5, 0.2);
}
if(poly.type == CSG_Polygon.POLY_TYPE.POLY_OPPOSITE){ // blue
gl.glColor3d(0.2, 0.2, 0.5);
}
if(poly.type == CSG_Polygon.POLY_TYPE.POLY_SAME){ // purple
gl.glColor3d(0.5, 0.2, 0.5);
}
if(poly.type == CSG_Polygon.POLY_TYPE.POLY_UNKNOWN){ // gray
gl.glColor3d(0.25, 0.25, 0.25);
}
Iterator<CSG_Vertex> iterV = poly.getVertexIterator();
gl.glBegin(GL.GL_LINE_LOOP);
while(iterV.hasNext()){
gl.glVertex3dv(iterV.next().getXYZ(), 0);
}
gl.glEnd();
}
}
示例3: renderAgent
import javax.media.opengl.GL; //導入方法依賴的package包/類
/**
* Render agent at specified position
* @param gl
* @param position
*/
private void renderAgent(GL gl, GlColor color, Location position) {
gl.glPushMatrix();
{
gl.glTranslated(position.x, position.y, position.z);
// draw sphere
gl.glColor4d(color.r, color.g, color.b, color.a);
glu.gluSphere(quadratic, SPHERE_RADIUS, SPHERE_SLICES, SPHERE_STACKS);
IPogamutEnvironments environments = Lookup.getDefault().lookup(IPogamutEnvironments.class);
if (environments != null) {
Collection c = environments.getEnvironmentSelection(map).lookupAll(this.agent.getDataSource().getClass());
for (Object o : c) {
if (agent.getDataSource().equals(o)) {
gl.glColor3d(0.3, 0.3, 0.3);
glu.gluDisk(quadratic, SPHERE_RADIUS * 1.2, SPHERE_RADIUS * 1.5, 32, 3);
}
}
}
}
gl.glPopMatrix();
Rotation rot = agent.getRotation();
if (rot != null) {
renderRotation(gl, new GlColor(1, 0, 0), position, rot);
}
/* if (window == null) {
window = new GLTextWindow(gl, 100, 20, 200, 50, "Hi, this is a test text 1234567890");
}
window.render();
*/
}
示例4: renderPlacedMapEvent
import javax.media.opengl.GL; //導入方法依賴的package包/類
/**
* Render {@link MapEvent} that is placed at fixed place (=not at the player).
* @param gl
* @param color what color should be map event drawn.
* @param mapEvent map event to render.
*/
private void renderPlacedMapEvent(GL gl, GlColor color, MapEvent mapEvent) {
LogMapMark mapMark = mapEvent.getMark();
Location position = mapMark.getLocation();
if (logger.isLoggable(Level.FINE)) logger.fine(" MSG: " + mapMark.getMessage() + ", LOC: " + position);
// gl.glEnable(GL.GL_BLEND);
// gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glPushMatrix();
{
gl.glTranslated(position.x, position.y, position.z + SPHERE_RADIUS * 1.1);
gl.glColor4d(color.r, color.g, color.b, color.a);
// glu.gluSphere(quadratic, SPHERE_RADIUS * 3, SPHERE_SLICES, SPHERE_STACKS);
glu.gluCylinder(quadratic, SPHERE_RADIUS, SPHERE_RADIUS, 2*SPHERE_RADIUS, 4, 1);
}
gl.glPopMatrix();
gl.glDisable(GL.GL_DEPTH_TEST);
{
gl.glColor3d(0, 0, 0);
gl.glRasterPos3d(position.x, position.y, position.z);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, mapEvent.getMessage());
gl.glColor3d(1, 1, 1);
}
gl.glEnable(GL.GL_DEPTH_TEST);
// gl.glDisable(GL.GL_BLEND);
}
示例5: drawNormalFromOriginForDegug
import javax.media.opengl.GL; //導入方法依賴的package包/類
public void drawNormalFromOriginForDegug(GL gl){
gl.glColor3d(1.0, 0.0, 0.0);
double scale = 1.0;
gl.glBegin(GL.GL_LINES);
gl.glVertex3dv(normal.getScaledCopy(scale).getXYZ(), 0);
gl.glVertex3d(0.0, 0.0, 0.0);
gl.glEnd();
}
示例6: drawPolygonNormalsForDebug
import javax.media.opengl.GL; //導入方法依賴的package包/類
public void drawPolygonNormalsForDebug(GL gl){
float[] currentColor=new float[]{0,0,0,0};
gl.glGetFloatv(GL.GL_CURRENT_COLOR, currentColor, 0);
gl.glColor3d(1.0, 0.0, 0.0);
CSG_Vertex fCenter = getBarycenterVertex();
CSG_Vertex norm = getPlane().getNormal();
double scale = 10;
fCenter.addToVertex(norm.getScaledCopy(scale));
CSG_Vertex nShifted = fCenter.addToVertex(norm.getScaledCopy(scale));
gl.glBegin(GL.GL_LINES);
gl.glVertex3dv(fCenter.getXYZ(), 0);
gl.glVertex3dv(nShifted.getXYZ(), 0);
gl.glEnd();
gl.glColor3d(currentColor[0], currentColor[1], currentColor[2]);
}
示例7: createGridList
import javax.media.opengl.GL; //導入方法依賴的package包/類
/**
* Create OpenGl list for grid lines of the map.
* @return id of a list
*/
private int createGridList(GL gl) {
Box mapBox = map.getBox();
int numMainLines = getNumGridLines(mapBox);
double lineLength = 2 * GRID_SCALE * numMainLines;
// TODO: Is 10 good arbiotrary number?
double floorZ = getGridZ();
int list = gl.glGenLists(1);
gl.glNewList(list, GL.GL_COMPILE);
{
gl.glBegin(GL.GL_LINES);
{
// central X lines, red
double minY = mapBox.getCenterY() - lineLength / 2;
double maxY = mapBox.getCenterY() + lineLength / 2;
gl.glColor3d(0.45, 0.29, 0.32);
gl.glVertex3d(mapBox.getCenterX(), minY, floorZ);
gl.glVertex3d(mapBox.getCenterX(), maxY, floorZ);
// central Y line, green
double minX = mapBox.getCenterX() - lineLength / 2;
double maxX = mapBox.getCenterX() + lineLength / 2;
gl.glColor3d(0.3, 0.57, 0.31);
gl.glVertex3d(minX, mapBox.getCenterY(), floorZ);
gl.glVertex3d(maxX, mapBox.getCenterY(), floorZ);
// other lines for better idea about size of level
// main lines
for (int line = 1; line <= numMainLines; line++) {
for (int coef = -1; coef <= 1; coef += 2) {
// main lines (darker grey)
gl.glColor3d(0.34, 0.34, 0.34);
// draw along Y axis
gl.glVertex3d(mapBox.getCenterX() + coef * line * GRID_SCALE, minY, floorZ);
gl.glVertex3d(mapBox.getCenterX() + coef * line * GRID_SCALE, maxY, floorZ);
// draw along X axis
gl.glVertex3d(minX, mapBox.getCenterY() + coef * line * GRID_SCALE, floorZ);
gl.glVertex3d(maxX, mapBox.getCenterY() + coef * line * GRID_SCALE, floorZ);
// minor lines (lighter grey)
gl.glColor3d(0.41, 0.41, 0.41);
for (int minority = 1; minority < 10; minority++) {
// draw along Y axis
gl.glVertex3d(mapBox.getCenterX() + coef * ((line - 1) * GRID_SCALE + minority * GRID_SCALE / 10), minY, floorZ);
gl.glVertex3d(mapBox.getCenterX() + coef * ((line - 1) * GRID_SCALE + minority * GRID_SCALE / 10), maxY, floorZ);
// draw along X axis
gl.glVertex3d(minX, mapBox.getCenterY() + coef * ((line - 1) * GRID_SCALE + minority * GRID_SCALE / 10), floorZ);
gl.glVertex3d(maxX, mapBox.getCenterY() + coef * ((line - 1) * GRID_SCALE + minority * GRID_SCALE / 10), floorZ);
}
}
}
}
gl.glEnd();
}
gl.glEndList();
return list;
}
示例8: renderInfo
import javax.media.opengl.GL; //導入方法依賴的package包/類
/**
* Render info about agent (in most cases event messages) and its name.
* TODO: Ugly code, refactor
* @param gl
* @param color What color should be used to render info.
* @param location position of agent
*/
private void renderInfo(GL gl, GlColor color, Location location) {
// get text
List<String> infos = new ArrayList<String>(agent.getAssociatedInfo());
infos.add(0, '*' + agent.getName() + '*');
Location topHead = new Location(location);
topHead = new Location(topHead.x, topHead.y, topHead.z + 2 * SPHERE_RADIUS * 1.1);
Location top2d = GLTools.getScreenCoordinates(gl, glu, topHead, null);
int lineGap = 12;
int font = GLUT.BITMAP_HELVETICA_10;
int maxWidth = 0;
for (String line : infos) {
int lineWidth = glut.glutBitmapLength(font, line);
if (lineWidth > maxWidth) {
maxWidth = lineWidth;
}
}
// update starting position
top2d = new Location(top2d.x - maxWidth / 2, top2d.y + (infos.size() - 1) * lineGap);
GlColor textColor = color.getMixedWith(new GlColor(0, 0, 0), 80);
gl.glColor3d(textColor.r, textColor.g, textColor.b);
for (int i = 0; i < infos.size(); i++) {
String text = infos.get(i);
if (i == 0) {
gl.glColor3d(color.r, color.g, color.b);
} else {
gl.glColor3d(textColor.r, textColor.g, textColor.b);
// gl.glColor3d(0, 0, 0);
}
Location textPos = GLTools.getWorldCoordinates(gl, glu, top2d, null);
gl.glRasterPos3d(textPos.x, textPos.y, textPos.z);
glut.glutBitmapString(font, text);
top2d = top2d.setY(top2d.y - lineGap);
}
}
示例9: testRotation
import javax.media.opengl.GL; //導入方法依賴的package包/類
/**
* test the sketch plane rotation and CSG_Vertex rotation code.
* If things are working correctly, every line should end at
* a point of the same color. (purple lines -> purple points;
* orange lines -> orange/green points).S
* @param gl
*/
public static void testRotation(GL gl){
System.out.println(" ------ GL Rotation Test -------- ");
gl.glLoadIdentity();
gl.glLineWidth(2.0f);
gl.glPointSize(5.0f);
CSG_Vertex v1 = new CSG_Vertex(1.0, 1.0, 0.0);
CSG_Vertex v2 = new CSG_Vertex(2.0, 1.0, 0.0);
CSG_Vertex v3 = new CSG_Vertex(2.0, 2.0, 0.0);
CSG_Vertex v4 = new CSG_Vertex(1.0, 2.0, 0.0);
CSG_Vertex vX = new CSG_Vertex(1.0, 0.0, 0.0);
CSG_Vertex vY = new CSG_Vertex(0.0, 1.0, 0.0);
CSG_Vertex vZ = new CSG_Vertex(0.0, 0.0, 1.0);
vX.drawPointForDebug(gl);
vY.drawPointForDebug(gl);
vZ.drawPointForDebug(gl);
for(double yInc= -0.25; yInc<0.26; yInc+= 0.1){
for(double rot=-3.10; rot<3.14; rot+= 0.1){
CSG_Vertex normal = new CSG_Vertex(Math.sin(rot), yInc, Math.cos(rot)).getUnitLength();
//CSG_Vertex normal = new CSG_Vertex(1.0, 0.0, 0.0);
CSG_Plane plane = new CSG_Plane(normal, 0.0);
SketchPlane sP = new SketchPlane(plane);
//System.out.println("--> normal: " + normal);
Translation3D translation = new Translation3D(0.0, 0.0, 0.0);
Rotation3D rotation = new Rotation3D(sP.getRotationX(), sP.getRotationY(), sP.getRotationZ());
CSG_Face f1 = new CSG_Face(new CSG_Polygon(v1, v2, v3, v4));
CSG_Face f2 = f1.getTranslatedCopy(new CSG_Vertex(-3.0, 0.0, 0.0));
CSG_Face f3 = f1.getTranslatedCopy(new CSG_Vertex(-3.0, -3.0, 0.0));
CSG_Face f4 = f1.getTranslatedCopy(new CSG_Vertex( 0.0, -3.0, 0.0));
gl.glColor3d(rot, 0.5, 0.0);
gl.glPointSize(7.0f);
//vX.getTranslatedRotatedCopy(translation, rotation).glDrawVertex(gl);
//vY.getTranslatedRotatedCopy(translation, rotation).glDrawVertex(gl);
vZ.getTranslatedRotatedCopy(translation, rotation).glDrawVertex(gl);
f1.applyTranslationRotation(translation, rotation);
f2.applyTranslationRotation(translation, rotation);
f3.applyTranslationRotation(translation, rotation);
f4.applyTranslationRotation(translation, rotation);
//f1.glDrawFace(gl); //
//f2.glDrawFace(gl); // uncomment these faces to see how
//f3.glDrawFace(gl); // planar regions are rotated.
//f4.glDrawFace(gl); //
gl.glColor3d(0.8, 0.0, 0.8);
sP.getVar1Axis().glDrawVertex(gl);
plane.drawNormalFromOriginForDegug(gl);
gl.glRotatef((float)(rotation.getXRot()*180.0/Math.PI), 1.0f, 0.0f, 0.0f);
gl.glRotatef((float)(rotation.getYRot()*180.0/Math.PI), 0.0f, 1.0f, 0.0f);
gl.glRotatef((float)(rotation.getZRot()*180.0/Math.PI), 0.0f, 0.0f, 1.0f);
gl.glColor3d(0.9, 0.7, 0.3);
gl.glPointSize(5.0f);
//vZ.glDrawVertex(gl);
gl.glBegin(GL.GL_LINES);
gl.glColor3d(0.9, 0.7, 0.3); // normal
gl.glVertex3d(0.0, 0.0, 0.0);
gl.glVertex3d(vZ.getX(), vZ.getY(), vZ.getZ());
gl.glColor3d(0.9, 0.3, 0.9); // x-axis
gl.glVertex3d(0.0, 0.0, 0.0);
gl.glVertex3d(1.0, 0.0, 0.0);
gl.glEnd();
gl.glLoadIdentity();
gl.glColor3d(0.7, 0.7, 0.7);
}
}
}
示例10: testPerimeterFormation
import javax.media.opengl.GL; //導入方法依賴的package包/類
/**
* test the perimeter formation routine.
* This should be able to take any CSG_Face composed of
* many convex polygons and return just the points
* along hte face's perimeter for edge drawing
* purposes in open GL.
* @param gl
*/
public static void testPerimeterFormation(GL gl){
gl.glLoadIdentity();
gl.glTranslated(-5.0, 0.0, 0.0);
Point2D ptA = new Point2D(0.0, 0.0);
Point2D ptB = new Point2D(2.0, 0.0);
Point2D ptC = new Point2D(2.0, 2.0);
Point2D ptD = new Point2D(1.1, 1.0);
Point2D ptE = new Point2D(2.0, 3.0);
Point2D ptF = new Point2D(3.0, 2.0);
Point2D ptG = new Point2D(2.5, 1.0);
Point2D ptH = new Point2D(2.5, 0.0);
Point2D ptI = new Point2D(4.0, 1.0);
Point2D ptJ = new Point2D(3.0, 3.0);
Point2D ptK = new Point2D(2.0, 4.0);
Point2D ptL = new Point2D(0.0, 2.0);
Point2D ptM = new Point2D(-1.0, 1.0);
Prim2DLine l1 = new Prim2DLine(ptA, ptB);
Prim2DLine l2 = new Prim2DLine(ptB, ptC);
Prim2DLine l3 = new Prim2DLine(ptC, ptD);
Prim2DLine l4 = new Prim2DLine(ptD, ptE);
Prim2DLine l5 = new Prim2DLine(ptE, ptF);
Prim2DLine l6 = new Prim2DLine(ptF, ptG);
Prim2DLine l7 = new Prim2DLine(ptG, ptH);
Prim2DLine l8 = new Prim2DLine(ptH, ptI);
Prim2DLine l9 = new Prim2DLine(ptI, ptJ);
Prim2DLine l10 = new Prim2DLine(ptJ, ptK);
Prim2DLine l11 = new Prim2DLine(ptK, ptL);
Prim2DLine l12 = new Prim2DLine(ptL, ptM);
Prim2DLine l13 = new Prim2DLine(ptM, ptA);
Prim2DCycle cycle = new Prim2DCycle();
cycle.add(l1);
cycle.add(l2);
cycle.add(l3);
cycle.add(l4);
cycle.add(l5);
cycle.add(l6);
cycle.add(l7);
cycle.add(l8);
cycle.add(l9);
cycle.add(l10);
cycle.add(l11);
cycle.add(l12);
cycle.add(l13);
Region2D region = new Region2D(cycle);
CSG_Face face = region.getCSG_Face();
face.drawFaceForDebug(gl);
face.drawFaceLinesForDebug(gl);
gl.glTranslated(5.0, 0.0, 0.0);
// now find the perimeter and draw that...
gl.glLineWidth(3.0f);
gl.glPointSize(5.0f);
gl.glColor3d(0.9, 0.7, 0.3);
LinkedList<CSG_Vertex> perim = face.getPerimeterVertices();
for(int i=0; i<perim.size(); i++){
CSG_Vertex vA = perim.get(i);
CSG_Vertex vB = perim.get((i+1)%perim.size());
gl.glBegin(GL.GL_LINE_LOOP);
gl.glVertex3d(vA.getX(), vA.getY(), vA.getZ());
gl.glVertex3d(vB.getX(), vB.getY(), vB.getZ());
gl.glEnd();
}
//System.out.println("face area: " + face.getArea());
gl.glLoadIdentity();
}
示例11: drawPointForDebug
import javax.media.opengl.GL; //導入方法依賴的package包/類
public void drawPointForDebug(GL gl){
gl.glColor3d(0.0, 1.0, 0.0);
gl.glBegin(GL.GL_POINTS);
gl.glVertex3d(x, y, z);
gl.glEnd();
}
示例12: display
import javax.media.opengl.GL; //導入方法依賴的package包/類
@Override
public void display(GLAutoDrawable glAutoDrawable) {
// System.out.println("MER.display " + time + " " + this.mapEvent.getMessage());
GL gl = glAutoDrawable.getGL();
gl.glPushMatrix();
gl.glTranslated(location.x, location.y, location.z + 60 * 1.1);
// display small
// gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE_MINUS_SRC_ALPHA);
GlColor color = new GlColor(entity.getColor(), 0.5);
gl.glColor4d(color.r, color.g, color.b, color.a);
GLUquadric quadratic = glu.gluNewQuadric();
glu.gluSphere(quadratic, SPHERE_RADIUS, SPHERE_SLICES, SPHERE_STACKS);
gl.glPopMatrix();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glColor3d(1,1,1);
gl.glRasterPos3d(location.x, location.y, location.z);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, this.mapEvent.getMessage());
gl.glEnable(GL.GL_DEPTH_TEST);
// gl.glDisable(GL.GL_BLEND);
}