本文整理汇总了Java中javax.media.opengl.GLContext.makeCurrent方法的典型用法代码示例。如果您正苦于以下问题:Java GLContext.makeCurrent方法的具体用法?Java GLContext.makeCurrent怎么用?Java GLContext.makeCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.opengl.GLContext
的用法示例。
在下文中一共展示了GLContext.makeCurrent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispose
import javax.media.opengl.GLContext; //导入方法依赖的package包/类
public void dispose() {
if (vertices != null) {
vertices.clear();
}
vertices = null;
if (points != null)
points.clear();
points = null;
subImage = null;
if (texture != null) {
GLContext context = ww.getSceneController().getDrawContext().getGLContext();
int i = context.makeCurrent();
if (i == GLContext.CONTEXT_CURRENT) {
((Disposable) texture).dispose();
context.release();
} else
System.err.println("Could not make GLContext current");
}
texture = null;
}
示例2: setup
import javax.media.opengl.GLContext; //导入方法依赖的package包/类
private static void setup( GLCanvas glcanvas, GLContext glcontext ) {
Rectangle rectangle = glcanvas.getClientArea();
glcanvas.setCurrent();
glcontext.makeCurrent();
GL2 gl = glcontext.getGL().getGL2();
gl.glMatrixMode( GL2.GL_PROJECTION );
gl.glLoadIdentity();
// coordinate system origin at lower left with width and height same as the window
GLU glu = new GLU();
glu.gluOrtho2D( 0.0f, rectangle.width, 0.0f, rectangle.height );
gl.glMatrixMode( GL2.GL_MODELVIEW );
gl.glLoadIdentity();
gl.glViewport( 0, 0, rectangle.width, rectangle.height );
glcontext.release();
}
示例3: render
import javax.media.opengl.GLContext; //导入方法依赖的package包/类
private static void render( GLCanvas glcanvas, GLContext glcontext ) {
Rectangle rectangle = glcanvas.getClientArea();
glcanvas.setCurrent();
glcontext.makeCurrent();
GL2 gl = glcontext.getGL().getGL2();
gl.glClear( GL.GL_COLOR_BUFFER_BIT );
// draw a triangle filling the window
gl.glLoadIdentity();
gl.glBegin( GL.GL_TRIANGLES );
gl.glColor3f( 1, 0, 0 );
gl.glVertex2f( 0, 0 );
gl.glColor3f( 0, 1, 0 );
gl.glVertex2f( rectangle.width, 0 );
gl.glColor3f( 0, 0, 1 );
gl.glVertex2f( rectangle.width / 2, rectangle.height );
gl.glEnd();
glcanvas.swapBuffers();
glcontext.release();
}
示例4: isOpenGLAvailable
import javax.media.opengl.GLContext; //导入方法依赖的package包/类
/**
* Check current graphic card/drivers OpenGL capabilities to see if they match those required by WorldWind to work
* @return true if we are good, false otherwise
*/
public boolean isOpenGLAvailable() {
if (_openGlAvailable == null) {
synchronized (this) {
if (_openGlAvailable == null) {
try {
// create an offscreen context with the current graphic device
final GLProfile glProfile = GLProfile.getDefault(GLProfile.getDefaultDevice());
final GLCapabilities caps = new GLCapabilities(glProfile);
caps.setOnscreen(false);
caps.setPBuffer(false);
final GLDrawable offscreenDrawable = GLDrawableFactory.getFactory(glProfile).createOffscreenDrawable(null, caps,
new DefaultGLCapabilitiesChooser(), 1, 1);
offscreenDrawable.setRealized(true);
final GLContext context = offscreenDrawable.createContext(null);
final int additionalCtxCreationFlags = 0;
context.setContextCreationFlags(additionalCtxCreationFlags);
context.makeCurrent();
final GL gl = context.getGL();
// WWJ will need those to render the globe
_openGlAvailable = gl.isExtensionAvailable(GLExtensions.EXT_texture_compression_s3tc)
|| gl.isExtensionAvailable(GLExtensions.NV_texture_compression_vtc);
} catch (final Throwable e) {
_openGlAvailable = false;
}
}
}
}
return _openGlAvailable;
}
示例5: submitToGL
import javax.media.opengl.GLContext; //导入方法依赖的package包/类
public <T> GLFutureTask<T> submitToGL(Callable<T> c){
final GLFutureTask<T> result = new GLFutureTask<T>(tr.getRootWindow().getCanvas(),c);
if(isGLThread())
if(gpuFeature.getGl().getContext().isCurrent()){
result.run();
return result;
}else{
final GLContext context = gpuFeature.getGl().getContext();
context.makeCurrent();
result.run();
context.release();
}
result.enqueue();
return result;
}
示例6: checkForUpdate
import javax.media.opengl.GLContext; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected boolean checkForUpdate() {
// Linux-specific workaround: On Linux JOGL holds the SunToolkit AWT lock in mtgame commit methods.
// In order to avoid deadlock with any threads which are already holding the AWT lock and which
// want to acquire the lock on the dirty rectangle so they can draw (e.g Embedded Swing threads)
// we need to temporarily release the AWT lock before we lock the dirty rectangle and then reacquire
// the AWT lock afterward.
// NOTE: we need to do this manually, rather than using a swingsafe processor, because
// we need to be holding the AWT lock when we return from this method.
// TODO: low: MTgame probably provides a cleaner way to reacquire the lock.
GLContext glContext = null;
if (isAWTLockHeldByCurrentThreadMethod != null) {
try {
Boolean ret = (Boolean) isAWTLockHeldByCurrentThreadMethod.invoke(null);
if (ret.booleanValue()) {
glContext = GLContext.getCurrent();
glContext.release();
}
} catch (Exception ex) {
}
}
final int texid = getTexture().getTextureId();
// In this implementation, we need to check our DirtyTrackingGraphics to see whether it is dirty.
// If it is dirty, we copy the entire buffered image into the imageGraphics.
g.executeAtomic(new Runnable() {
public void run() {
Rectangle dirtyRect = g.getDirtyRectangle();
if (dirtyRect != null) {
//System.err.println("DBSI: Rendering into texid = " + texid);
int x1 = dirtyRect.x;
int y1 = dirtyRect.y;
int x2 = dirtyRect.x + dirtyRect.width - 1;
int y2 = dirtyRect.y + dirtyRect.height - 1;
if (!imageGraphics.drawImage(bufImage, x1, y1, x2, y2,
x1, y1, x2, y2, null, null)) {
logger.warning("drawImage returned false. Skipping image rendering.");
}
g.clearDirty();
checkForUpdateReturn = true;
} else {
checkForUpdateReturn = false;
}
}
});
// Linux-specific workaround: Reacquire the lock if necessary.
if (glContext != null) {
glContext.makeCurrent();
}
return checkForUpdateReturn;
}