本文整理匯總了Java中javax.media.opengl.GL2.glClear方法的典型用法代碼示例。如果您正苦於以下問題:Java GL2.glClear方法的具體用法?Java GL2.glClear怎麽用?Java GL2.glClear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.media.opengl.GL2
的用法示例。
在下文中一共展示了GL2.glClear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
示例2: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Invokes all layers to draw.
*/
public void draw(GL2 gl) {
super.draw(gl);
if (state != null && gl != null && drawableLayer != null) {
GaiaCanvas canvas = GaiaCanvas.getInstance();
// Clear the color-buffer to white:
gl.glClearColor(0xFF, 0xFF, 0xFF, 0);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
// Set camera.
float currentZoom = state.getZoom();
setupCamera(gl, new GLU(), state.getPosition().getX(), state
.getPosition().getY(), currentZoom, canvas.getWidth(),
canvas.getHeight());
// Draw all layers beginning with the lowest:
drawableLayer.draw(gl, 0);
}
}
示例3: drawNurbSurface
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawNurbSurface(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
GLUgl2 glug12 = new GLUgl2();
GLUnurbs nurbsRenderer = glug12.gluNewNurbsRenderer();
//glug12.gluNurbsProperty(nurbsRenderer, , arg2)
glug12.gluBeginSurface(nurbsRenderer);
int uknot_cnt=8;
float[] uknot = new float[] {0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 1.f, 1.f};
int vknot_cnt = 8;
float[] vknot = uknot;
int ustride=4*3;
int vstride=3;
int uorder=4;
int vorder=4;
int evl_type=GL2.GL_MAP2_NORMAL;
//glug12.gluNurbsSurface(nurbsRenderer, uknot_cnt, uknot, vknot_cnt, vknot, ustride, vstride, ctlarray, uorder, vorder, evl_type);
evl_type=GL2.GL_MAP2_VERTEX_3;
glug12.gluNurbsSurface(nurbsRenderer, uknot_cnt, uknot, vknot_cnt, vknot, ustride, vstride, ctlarray, uorder, vorder, evl_type);
glug12.gluEndSurface(nurbsRenderer);
}
示例4: paint
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void paint(){
// Compute maximum width of text we're going to draw
TextRenderer textRenderer = new TextRenderer(new Font(Font.SERIF,0 , 18));
int maxTextWidth = (int) textRenderer.getBounds(this.text).getWidth();
maxTextWidth = Math.min(maxTextWidth+10,size.width);
GL2 gl=glContext.getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glPolygonMode (GL2.GL_FRONT, GL2.GL_LINE_STRIP);
gl.glColor3f(0.5f, 0.5f, 0.5f);
gl.glBegin(GL2.GL_LINE_STRIP);
gl.glVertex2i( this.posx,this.posy); //x1,y1
gl.glVertex2i( this.posx+maxTextWidth,this.posy ); //x2,y1
gl.glVertex2i( this.posx+maxTextWidth,this.posy +size.height); //x2,y2
gl.glVertex2i( this.posx,this.posy+size.height); //x1,y2
gl.glVertex2i( this.posx,this.posy);
gl.glEnd( );
GLDrawable draw=gl.getGL().getContext().getGLDrawable();
textRenderer.beginRendering(draw.getWidth(),draw.getHeight());
textRenderer.setColor(Color.WHITE);
textRenderer.setSmoothing(true);
textRenderer.draw(this.text,(int)posx,(int)posy+5); //text and position
textRenderer.flush();
textRenderer.endRendering();
gl.glFlush();
}
示例5: display
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
this.drawable = drawable;
// Apply transformations
double transx = -origin.getX(), transy = -origin.getY();
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, width, height, 0, -1, 1);
gl.glViewport(0, 0, width, height);
gl.glTranslated(transx + zoomPos.getX(), transy + zoomPos.getY(), 0);
gl.glScaled(scaleFactor, scaleFactor, 1);
gl.glTranslated(-zoomPos.getX(), -zoomPos.getY(), 0);
gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelview);
gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection);
gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
// Draw edges, arrows and vertices
edgeRenderer.transform(transx, transy, scaleFactor);
edgeRenderer.render();
if (animateLabels) {
labelRenderer.scale(scaleFactor);
labelRenderer.drawLabels();
}
vertexRenderer.transform(transx, transy, scaleFactor);
vertexRenderer.render();
}
示例6: display
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT /* | GL.GL_DEPTH_BUFFER_BIT */);
if(shared.layout != null) {
int res = prenderer.prepare(gl);
if(res == 1) {
// Request a repaint, to generate the next texture.
canvas.repaint();
}
if(res == 2) {
messageOverlay.setMessage("Texture rendering completed.");
switchState(State.EXPLORE);
}
}
shared.camera.apply(gl);
if(shared.layout != null) {
prenderer.drawParallelPlot(drawable, gl);
}
if(DEBUG) {
arcball.debugRender(gl);
}
if(State.MENU.equals(state)) {
menuOverlay.render(gl);
}
if(State.PREPARATION.equals(state)) {
messageOverlay.render(gl);
}
}
示例7: setupLighting
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void setupLighting(GLAutoDrawable drawable, GL2 gl) {
int paramsOffset = 0;
float pos[] = { 2.0f, -2.0f, 10.0f, 0.0f };
float ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
float diffuse[] = {0.9f, 0.9f, 0.9f, 1.0f};
float specular[] = {0.05f, 0.05f, 0.99f, 1.0f};
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glEnable(GL2.GL_AUTO_NORMAL);
gl.glEnable(GL2.GL_NORMALIZE);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient, paramsOffset);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, paramsOffset);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, specular, paramsOffset);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, paramsOffset);
gl.glLightModeli(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, GL2.GL_TRUE);
gl.glClearColor(1f, 1f, 1f, 1f);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
if (gl instanceof GLLightingFunc) {
((GLLightingFunc) gl).glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, blue, 0);
((GLLightingFunc) gl).glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, white, 0);
float[] medHiShiny = new float[] {80.0f};
((GLLightingFunc) gl).glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, medHiShiny, 0);
((GLLightingFunc) gl).glShadeModel(GLLightingFunc.GL_FLAT);
}
}
示例8: drawSurface
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawSurface(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushMatrix();
gl.glEvalMesh2(GL2.GL_FILL, 0, 20, 0, 20);
gl.glPopMatrix();
gl.glFlush();
}
示例9: render
import javax.media.opengl.GL2; //導入方法依賴的package包/類
void render( GL2 gl2 )
{
gl2.glClear( GL.GL_COLOR_BUFFER_BIT );
// draw a triangle filling the window
gl2.glLoadIdentity();
gl2.glBegin( GL.GL_TRIANGLES );
gl2.glColor3f( 1, 0, 0 );
gl2.glVertex3f( 0, 0, 0 );
gl2.glColor3f( 0, 1, 0 );
gl2.glVertex3f( 5, 0, 2 );
gl2.glColor3f( 0, 0, 1 );
gl2.glVertex3f( 2, 5, 3 );
gl2.glEnd();
}
示例10: display
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*
* @see javax.media.opengl.GLEventListener#display(javax.media.opengl.GLAutoDrawable)
*/
@Override
public void display( final GLAutoDrawable drawable )
{
this.updateVis();
final GL2 gl = drawable.getGL().getGL2();
gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW );
gl.glLoadIdentity();
if( this.cameraPosition != null )
{
final float[] pos = this.cameraPosition.getCameraPosition();
this.glu.gluLookAt( pos[0], pos[1], pos[2], pos[3], pos[4], pos[5], pos[6], pos[7], pos[8] );
}
// Prepare light parameters.
if( this.enableLights )
{
final float SHINE_ALL_DIRECTIONS = 1;
final float[] lightPos = {-30, 0, 0, SHINE_ALL_DIRECTIONS};
final float[] lightColorAmbient = {0.2f, 0.2f, 0.2f, 1f};
final float[] lightColorSpecular = {0.5f, 0.5f, 0.5f, 1f};
// Set light parameters.
gl.glLightfv( GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION, lightPos, 0 );
gl.glLightfv( GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_AMBIENT, lightColorAmbient, 0 );
gl.glLightfv( GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR, lightColorSpecular, 0 );
// Enable lighting in GL.
gl.glEnable( GLLightingFunc.GL_LIGHT1 );
gl.glEnable( GLLightingFunc.GL_LIGHTING );
}
gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
this.renderVis( drawable );
}
示例11: drawScene
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void drawScene(GL2 gl)
{
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
// Colors
float red[] = {1.0f,0.0f,0.0f,1.0f};
float green[] = {0.0f,1.0f,0.0f,1.0f};
float blue[] = {0.0f,0.0f,1.0f,1.0f};
// Red rectangle
GLRectangleEntity r1 = new GLRectangleEntity(gl, glu);
r1.x = 0.15f;
r1.y = 0.25f;
r1.z = 0.75f;
r1.w = 0.4f;
r1.h = 0.4f;
r1.c = red;
r1.id = 10;
r1.draw();
// Green rectangle
GLRectangleEntity r2 = new GLRectangleEntity(gl, glu);
r2.x = 0.35f;
r2.y = 0.45f;
r2.z = 0.5f;
r2.w = 0.4f;
r2.h = 0.4f;
r2.c = green;
r2.id = 20;
r2.draw();
// Blue rectangle
GLRectangleEntity r3 = new GLRectangleEntity(gl, glu);
r3.x = 0.45f;
r3.y = 0.15f;
r3.z = 0.25f;
r3.w = 0.4f;
r3.h = 0.4f;
r3.c = blue;
r3.id = 30;
r3.draw();
gl.glFlush();
}
示例12: render
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@SuppressWarnings("static-access")
protected void render(GL2 gl2) {
if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0) {
return;
}
assert (initialized_context_ != null);
final float[] vertex_data = {
//tu, tv, x, y, z
0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f };
FloatBuffer vertices = FloatBuffer.wrap(vertex_data);
gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT);
gl2.glMatrixMode(gl2.GL_MODELVIEW);
gl2.glLoadIdentity();
// Match GL units to screen coordinates.
gl2.glViewport(0, 0, view_width_, view_height_);
gl2.glMatrixMode(gl2.GL_PROJECTION);
gl2.glLoadIdentity();
// Draw the background gradient.
gl2.glPushAttrib(gl2.GL_ALL_ATTRIB_BITS);
gl2.glBegin(gl2.GL_QUADS);
gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // red
gl2.glVertex2f(-1.0f, -1.0f);
gl2.glVertex2f(1.0f, -1.0f);
gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue
gl2.glVertex2f(1.0f, 1.0f);
gl2.glVertex2f(-1.0f, 1.0f);
gl2.glEnd();
gl2.glPopAttrib();
// Rotate the view based on the mouse spin.
if (spin_x_ != 0) {
gl2.glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f);
}
if (spin_y_ != 0) {
gl2.glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f);
}
if (transparent_) {
// Alpha blending style. Texture values have premultiplied alpha.
gl2.glBlendFunc(gl2.GL_ONE, gl2.GL_ONE_MINUS_SRC_ALPHA);
// Enable alpha blending.
gl2.glEnable(gl2.GL_BLEND);
}
// Enable 2D textures.
gl2.glEnable(gl2.GL_TEXTURE_2D);
// Draw the facets with the texture.
assert (texture_id_[0] != 0);
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices);
gl2.glDrawArrays(gl2.GL_QUADS, 0, 4);
// Disable 2D textures.
gl2.glDisable(gl2.GL_TEXTURE_2D);
if (transparent_) {
// Disable alpha blending.
gl2.glDisable(gl2.GL_BLEND);
}
}
示例13: render
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@SuppressWarnings("static-access")
protected void render(GL2 gl2) {
if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0)
return;
assert(initialized_context_ != null);
final float[] vertex_data = {
//tu, tv, x, y, z
0.0f, 1.0f, -1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 1.0f, -1.0f, 0.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, -1.0f, 1.0f, 0.0f
};
FloatBuffer vertices = FloatBuffer.wrap(vertex_data);
gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT);
gl2.glMatrixMode(gl2.GL_MODELVIEW);
gl2.glLoadIdentity();
// Match GL units to screen coordinates.
gl2.glViewport(0, 0, view_width_, view_height_);
gl2.glMatrixMode(gl2.GL_PROJECTION);
gl2.glLoadIdentity();
gl2.glOrtho(0, 0, view_width_, view_height_, 0.1, 100.0);
// Draw the background gradient.
gl2.glPushAttrib(gl2.GL_ALL_ATTRIB_BITS);
gl2.glBegin(gl2.GL_QUADS);
gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // red
gl2.glVertex2f(-1.0f, -1.0f);
gl2.glVertex2f(1.0f, -1.0f);
gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue
gl2.glVertex2f(1.0f, 1.0f);
gl2.glVertex2f(-1.0f, 1.0f);
gl2.glEnd();
gl2.glPopAttrib();
// Rotate the view based on the mouse spin.
if (spin_x_ != 0)
gl2.glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f);
if (spin_y_ != 0)
gl2.glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f);
if (transparent_) {
// Alpha blending style. Texture values have premultiplied alpha.
gl2.glBlendFunc(gl2.GL_ONE, gl2.GL_ONE_MINUS_SRC_ALPHA);
// Enable alpha blending.
gl2.glEnable(gl2.GL_BLEND);
}
// Enable 2D textures.
gl2.glEnable(gl2.GL_TEXTURE_2D);
// Draw the facets with the texture.
assert(texture_id_[0] != 0);
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices);
gl2.glDrawArrays(gl2.GL_QUADS, 0, 4);
// Disable 2D textures.
gl2.glDisable(gl2.GL_TEXTURE_2D);
if (transparent_) {
// Disable alpha blending.
gl2.glDisable(gl2.GL_BLEND);
}
}
示例14: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void draw(GL2 gl) {
boolean lastFrame2D = wasLastFrame2D();
super.draw(gl);
// Clear the color-buffer to white:
gl.glClearColor(0x0, 0x0, 0x0, 0);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
this.setCamera(gl, this.glu, this.width, this.height);
// this.setLights(gl);
gl.glLoadIdentity();
if(state.is2DMode() != lastFrame2D) {
oldRotation = new FloatVector3D(0, 0, 0);
System.arraycopy(IDENTITY, 0, modelViewMatrix, 0, IDENTITY.length);
gl.glRotatef(-90, 1, 0, 0);
gl.glMultMatrixf(modelViewMatrix, 0);
gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelViewMatrix, 0);
gl.glLoadIdentity();
}
FloatVector3D relativeRotation = new FloatVector3D(oldRotation);
relativeRotation.sub(state.getRotation());
// rotate the globe
gl.glRotatef(relativeRotation.getX(), 1, 0, 0);
gl.glRotatef(relativeRotation.getY(), 0, 1, 0);
// compute 'old' rotation
gl.glMultMatrixf(modelViewMatrix, 0);
// reset the rotations
oldRotation = new FloatVector3D(state.getRotation());
// store the current rotation in the GL-state
gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelViewMatrix, 0);
this.drawEarth(gl);
}
示例15: doRoi
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override protected void doRoi() {
transformer.transform(srcRoiPts, dstRoiPts, parameters, false);
double[] pts = dstRoiPts.get();
for (int i = 0; i < pts.length; i++) {
pts[i] /= (1<<pyramidLevel);
}
roi.x(0).y(0).width(maskCL[pyramidLevel].width).height(maskCL[pyramidLevel].height);
// Add +3 all around because cvWarpPerspective() needs it for interpolation,
// and there seems to be something funny with memory alignment and
// ROIs, so let's align our ROI to a 16 byte boundary just in case..
JavaCV.boundingRect(pts, roi, 3, 3, 16, 1);
//System.out.println(roi);
inputData.roiX = roi.x();
inputData.roiY = roi.y();
inputData.roiWidth = roi.width();
inputData.roiHeight = roi.height();
// GLContext glContext = context.getGLContext();
// glContext.makeCurrent();
GL2 gl = context.getGL2();
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, maskfb[pyramidLevel]);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
context.getGLU().gluOrtho2D(0.0f, maskCL[pyramidLevel].width, 0.0f, maskCL[pyramidLevel].height);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, maskCL[pyramidLevel].width, maskCL[pyramidLevel].height);
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glColor4f(1, 1, 1, 1);
gl.glBegin(GL2.GL_POLYGON);
// XXX: Remove "extra" pixels here...
gl.glVertex2d(pts[0], pts[1]);
gl.glVertex2d(pts[2]+1, pts[3]);
gl.glVertex2d(pts[4]+1, pts[5]+1);
gl.glVertex2d(pts[6], pts[7]+1);
gl.glEnd();
// gl.glFinish();
// glContext.release();
}