本文整理匯總了Java中javax.media.opengl.GL2類的典型用法代碼示例。如果您正苦於以下問題:Java GL2類的具體用法?Java GL2怎麽用?Java GL2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GL2類屬於javax.media.opengl包,在下文中一共展示了GL2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: renderSquare
import javax.media.opengl.GL2; //導入依賴的package包/類
public static void renderSquare(OpenGLContext context,float zoomWidth,float zoomHeight,List<Geometry>geometries,Geometry selectedGeometry,float renderWidth,Color color){
GL2 gl = context.getGL().getGL2();
float[] c = color.brighter().getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
for (Geometry temp : geometries) {
gl.glLineWidth(temp == selectedGeometry ? renderWidth * 3 : renderWidth);
Coordinate point = new Coordinate(temp.getCoordinate());
point.x = (point.x - context.getX()) / zoomWidth;
point.y = 1 - (point.y - context.getY()) / zoomHeight;
double rectwidth = 0.01;
gl.glBegin(GL.GL_LINE_STRIP);
gl.glVertex2d(point.x - rectwidth, point.y - rectwidth);
gl.glVertex2d(point.x - rectwidth, point.y + rectwidth);
gl.glVertex2d(point.x + rectwidth, point.y + rectwidth);
gl.glVertex2d(point.x + rectwidth, point.y - rectwidth);
gl.glVertex2d(point.x - rectwidth, point.y - rectwidth);
gl.glEnd();
gl.glFlush();
}
}
示例2: init
import javax.media.opengl.GL2; //導入依賴的package包/類
@Override
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
glu = new GLU();
/* select clearing color (background) color */
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
/* initialize viewing values */
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
// Start animator (which should be a field).
animator = new FPSAnimator(drawable, 60);
animator.start();
}
示例3: renderCross
import javax.media.opengl.GL2; //導入依賴的package包/類
public static void renderCross(OpenGLContext context,float zoomWidth,float zoomHeight,List<Geometry>geometries,Geometry selectedGeometry,float renderWidth,Color color){
GL2 gl = context.getGL().getGL2();
float[] c = color.brighter().getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
if(geometries!=null){
for (Geometry temp : geometries) {
gl.glLineWidth(temp == selectedGeometry ? renderWidth * 2 : renderWidth);
Coordinate point = new Coordinate(temp.getCoordinate());
point.x = (point.x - context.getX()) / zoomWidth;
point.y = 1 - (point.y - context.getY()) / zoomHeight;
double rectwidth = 0.01;
gl.glBegin(GL.GL_LINE_STRIP);
gl.glVertex2d(point.x - rectwidth, point.y);
gl.glVertex2d(point.x + rectwidth, point.y);
gl.glEnd();
gl.glBegin(GL.GL_LINE_STRIP);
gl.glVertex2d(point.x, point.y - rectwidth);
gl.glVertex2d(point.x, point.y + rectwidth);
gl.glEnd();
gl.glFlush();
}
}
}
示例4: renderTriangle
import javax.media.opengl.GL2; //導入依賴的package包/類
public static void renderTriangle(OpenGLContext context,float zoomWidth,float zoomHeight,List<Geometry>geometries,Geometry selectedGeometry,float renderWidth,Color color){
GL2 gl = context.getGL().getGL2();
float[] c = color.brighter().getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
if(geometries!=null){
for (Geometry temp : geometries) {
gl.glLineWidth(temp == selectedGeometry ? renderWidth * 2 : renderWidth);
Coordinate point = new Coordinate(temp.getCoordinate());
point.x = (point.x - context.getX()) / zoomWidth;
point.y = 1 - (point.y - context.getY()) / zoomHeight;
double rectwidth = 0.01;
gl.glBegin(GL.GL_LINE_STRIP);
gl.glVertex2d(point.x - rectwidth, point.y - rectwidth);
gl.glVertex2d(point.x, point.y + rectwidth);
gl.glVertex2d(point.x + rectwidth, point.y - rectwidth);
gl.glVertex2d(point.x - rectwidth, point.y - rectwidth);
gl.glEnd();
gl.glFlush();
}
}
}
示例5: renderCircle
import javax.media.opengl.GL2; //導入依賴的package包/類
public static void renderCircle(OpenGLContext context,float zoomWidth,float zoomHeight,List<Geometry>geometries,Geometry selectedGeometry,float size,Color color){
GL2 gl = context.getGL().getGL2();
float[] c = color.brighter().getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
gl.glBegin(GL.GL_POINTS);
for (int ii=0;ii<geometries.size();ii++) {
Geometry temp =geometries.get(ii);
gl.glLineWidth(temp == selectedGeometry ? size * 2 : size);
gl.glPointSize(temp == selectedGeometry ? size * 2 : size);
Coordinate point = temp.getCoordinate();
double dx=(point.x - context.getX()) / zoomWidth;
double dy=1 - (point.y - context.getY()) / zoomHeight;
for (int i=0; i < 360; i++){
//double angle = 2 * Math.PI * i / 360;
double xx = dx+Math.sin(i)*0.005;
double yy = dy+Math.cos(i)*0.005;
gl.glVertex2d(xx,yy);
}
}
gl.glEnd();
gl.glFlush();
}
示例6: drawPoly
import javax.media.opengl.GL2; //導入依賴的package包/類
/**
*
* @param gl
* @param cs
* @param width
* @param height
* @param x
* @param y
*/
public static void drawPoly(OpenGLContext context,Coordinate[] cs,float width,float height,int x,int y,float rwidth,Color color){
GL2 gl = context.getGL().getGL2();
float[] c = color.getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
gl.glLineWidth(rwidth);
gl.glBegin(GL.GL_LINE_STRIP);
// System.out.println("----------------------------------");
for (int p = 0; p < cs.length; p++) {
double vx=(cs[p].x - x) / width;
double vy=1 - (cs[p].y - y) / height;
// System.out.println(vx+" "+vy+",");
gl.glVertex2d(vx,vy);
}
// System.out.println("----------------------------------");
//close polygon
Coordinate point = cs[0];
gl.glVertex2d((point.x - x) / width, 1 - (point.y - y) / height);
gl.glEnd();
gl.glFlush();
}
示例7: display
import javax.media.opengl.GL2; //導入依賴的package包/類
public void display(GLDrawable gLDrawable)
{
String [] fonts = { "BitMap 9 by 15", "BitMap 8 by 13",
"Times Roman 10 Point ", "Times Roman 24 Point ",
"Helvetica 10 Point ","Helvetica 12 Point ","Helvetica 18 Point "};
final GL2 gl = SumoPlatform.getApplication().getGeoContext().getGL().getGL2();
final GLUT glut = new GLUT();
gl.glClear (GL.GL_COLOR_BUFFER_BIT); // Set display window to color.
gl.glColor3f (0.0f, 0.0f, 0.0f); // Set text e.color to black
gl.glMatrixMode (GL2.GL_MODELVIEW);
gl.glLoadIdentity();
int x = 20, y=15;
for (int i=0; i<7;i++){
gl.glRasterPos2i(x,y); // set position
glut.glutBitmapString(i+2, fonts[i]);
y+= 20;
}
}
示例8: reshape
import javax.media.opengl.GL2; //導入依賴的package包/類
/**
* Needed implementation of method when you change the size of the main window
* @param drawable
* @param x
* @param y
* @param width
* @param height
*/
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
if (height <= 0) { // avoid a divide by zero error!
height = 1;
}
final float aspect = (float) width / (float) height;
GL gl = drawable.getGL();
gl.getGL2().glMatrixMode(GL2.GL_PROJECTION);
gl.getGL2().glLoadIdentity();
glu.gluPerspective(0, aspect, 0.1f, 1);
// Set the view port (display area) to cover the entire window
gl.glViewport(0, 0, width, height);
glu.gluOrtho2D(0, 1, 0, 1);
gl.getGL2().glMatrixMode(GL2.GL_MODELVIEW);
gl.getGL2().glLoadIdentity();
}
示例9: drawPoly
import javax.media.opengl.GL2; //導入依賴的package包/類
/**
*
* @param gl
* @param cs
* @param width
* @param height
* @param x
* @param y
*/
protected void drawPoly(GL2 gl,Coordinate[] cs,float width,float height,int x,int y,float rwidth){
gl.glLineWidth(rwidth);
gl.glBegin(GL.GL_LINE_STRIP);
for (int p = 0; p < cs.length; p++) {
double vx=(cs[p].x - x) / width;
double vy=1 - (cs[p].y - y) / height;
gl.glVertex2d(vx,vy);
}
//close polygon
Coordinate point = cs[0];
gl.glVertex2d((point.x - x) / width, 1 - (point.y - y) / height);
gl.glEnd();
gl.glFlush();
}
示例10: render
import javax.media.opengl.GL2; //導入依賴的package包/類
public void render(OpenGLContext context) {
if (initPosition == null) {
return;
}
int x = context.getX(), y = context.getY();
float zoom = context.getZoom(), width = context.getWidth() * zoom, height = context.getHeight() * zoom;
GL2 gl = context.getGL().getGL2();
gl.glLineWidth(1);
float[] c = Color.GREEN.getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
gl.glBegin(GL.GL_LINE_STRIP);
gl.glVertex2d((initPosition.x - x) / width, 1 - (initPosition.y - y) / height);
if (endPosition == null) {
gl.glVertex2d((imagePosition.x - x) / width, 1 - (imagePosition.y - y) / height);
} else {
gl.glVertex2d((endPosition.x - x) / width, 1 - (endPosition.y - y) / height);
}
gl.glEnd();
gl.glFlush();
}
示例11: render
import javax.media.opengl.GL2; //導入依賴的package包/類
@Override
public void render(Object glC) {
OpenGLContext context=(OpenGLContext)glC;//SumoPlatform.getApplication().getGeoContext();
GL gl = context.getGL();
gl.getGL2().glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
BufferedImage temp=new BufferedImage(overview.getWidth(), overview.getHeight(), overview.getType());
this.overview.copyData(temp.getRaster());
BufferedImage buffer=rescale.filter(temp, temp);
Texture texture = AWTTextureIO.newTexture(((GLBase)gl).getGLProfile(), buffer, true);
//Texture texture = TextureIO.newTexture(rescale.filter(temp, temp), false);
float tempscale=this.scale*context.getHeight()/context.getWidth();
if(tempscale<1){
bindTexture(gl, texture, 0, tempscale, 0, 1);
}
else{
bindTexture(gl, texture, 0, 1, 0, tempscale);
}
texture.disable(gl);
context.setX(0);
context.setY(0);
context.setZoom(Math.max(thumbReader.getWidth() / context.getWidth(),thumbReader.getHeight() / context.getHeight()));
SumoPlatform.getApplication().getLayerManager().render(context);
}
示例12: bindTexture
import javax.media.opengl.GL2; //導入依賴的package包/類
private void bindTexture(GL gl, Texture texture, float xmin, float xmax, float ymin, float ymax) {
texture.enable(gl);
texture.bind(gl);
TextureCoords coords = texture.getImageTexCoords();
gl.getGL2().glBegin(GL2.GL_QUADS);
gl.getGL2().glTexCoord2f(coords.left(), coords.top());
gl.getGL2().glVertex2f(xmin, 1 - ymin);
gl.getGL2().glTexCoord2f(coords.right(), coords.top());
gl.getGL2().glVertex2f(xmax, 1 - ymin);
gl.getGL2().glTexCoord2f(coords.right(), coords.bottom());
gl.getGL2().glVertex2f(xmax, 1 - ymax);
gl.getGL2().glTexCoord2f(coords.left(), coords.bottom());
gl.getGL2().glVertex2f(xmin, 1 - ymax);
gl.getGL2().glEnd();
texture.disable(gl);
}
示例13: bindTexture
import javax.media.opengl.GL2; //導入依賴的package包/類
/**
*
* @param gl
* @param texture
* @param xmin
* @param xmax
* @param ymin
* @param ymax
*/
private void bindTexture(GL gl, Texture texture, float xmin, float xmax, float ymin, float ymax) {
texture.enable(gl);
texture.bind(gl);
TextureCoords coords = texture.getImageTexCoords();
gl.getGL2().glBegin(GL2.GL_QUADS);
gl.getGL2().glTexCoord2f(coords.left(), coords.top());
gl.getGL2().glVertex2f(xmin, 1 - ymin);
gl.getGL2().glTexCoord2f(coords.right(), coords.top());
gl.getGL2().glVertex2f(xmax, 1 - ymin);
gl.getGL2().glTexCoord2f(coords.right(), coords.bottom());
gl.getGL2().glVertex2f(xmax, 1 - ymax);
gl.getGL2().glTexCoord2f(coords.left(), coords.bottom());
gl.getGL2().glVertex2f(xmin, 1 - ymax);
gl.getGL2().glEnd();
texture.disable(gl);
}
示例14: renderVA
import javax.media.opengl.GL2; //導入依賴的package包/類
protected void renderVA(DrawContext dc, RectTile tile, int numTextureUnits)
{
//GL gl = dc.getGL();
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
gl.glVertexPointer(3, GL.GL_FLOAT, 0, tile.ri.vertices.rewind());
for (int i = 0; i < numTextureUnits; i++)
{
gl.glClientActiveTexture(GL.GL_TEXTURE0 + i);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
Object texCoords = dc.getValue(AVKey.TEXTURE_COORDINATES);
if (texCoords != null && texCoords instanceof DoubleBuffer)
gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, ((DoubleBuffer) texCoords).rewind());
else
gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, tile.ri.texCoords.rewind());
}
gl.glDrawElements(javax.media.opengl.GL.GL_TRIANGLE_STRIP, tile.ri.indices.limit(),
javax.media.opengl.GL.GL_UNSIGNED_INT, tile.ri.indices.rewind());
}
示例15: drawBoundingVolumes
import javax.media.opengl.GL2; //導入依賴的package包/類
protected void drawBoundingVolumes(DrawContext dc, ArrayList<TextureTile> tiles)
{
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
float[] previousColor = new float[4];
gl.glGetFloatv(GL2.GL_CURRENT_COLOR, previousColor, 0);
gl.glColor3d(0, 1, 0);
for (TextureTile tile : tiles)
{
if (tile.getExtent(dc) instanceof Renderable)
((Renderable) tile.getExtent(dc)).render(dc);
}
Box c = Sector.computeBoundingBox(dc.getGlobe(), dc.getVerticalExaggeration(), this.levels.getSector());
gl.glColor3d(1, 1, 0);
c.render(dc);
gl.glColor4fv(previousColor, 0);
}