use of com.jogamp.opengl.GL2 in project tdme by andreasdr.
the class Engine method updateRenderer.
/**
* Updates the renderer with given drawable
* @param drawable
*/
private void updateRenderer(GLAutoDrawable drawable) {
if (drawable.getGL().isGL3()) {
GL3 gl = (GL3) drawable.getGL().getGL3();
// notify gl context to renderer
renderer.setGL(gl);
} else if (drawable.getGL().isGL2()) {
GL2 gl = (GL2) drawable.getGL().getGL2();
// notify gl context to renderer
renderer.setGL(gl);
} else if (drawable.getGL().isGLES2()) {
GLES2 gl = (GLES2) drawable.getGL().getGLES2();
// notify gl context to renderer
renderer.setGL(gl);
} else {
System.out.println("Engine::updateRenderer(): unsupported GL!");
}
}
use of com.jogamp.opengl.GL2 in project gephi by gephi.
the class OffscreenCanvas method reshapeTile.
@Override
public void reshapeTile(TileRendererBase tr, int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight) {
GL2 gl = tr.getAttachedDrawable().getGL().getGL2();
double aspectRatio = (double) imageWidth / (double) imageHeight;
// Compute overall frustum
float left, right, bottom, top;
top = (float) (nearDistance * Math.tan(viewField * 3.14159265 / 360.0));
bottom = -top;
left = (float) (bottom * aspectRatio);
right = (float) (top * aspectRatio);
float w = right - left;
float h = top - bottom;
// Compute tiled frustum
float l = left + tileX * w / imageWidth;
float r = l + tileWidth * w / imageWidth;
float b = bottom + tileY * h / imageHeight;
float t = b + tileHeight * h / imageHeight;
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustum(l, r, b, t, nearDistance, farDistance);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
setCameraPosition(gl, GLU);
}
use of com.jogamp.opengl.GL2 in project gephi by gephi.
the class OffscreenCanvas method display.
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
Color backgroundColor = vizController.getVizModel().getBackgroundColor();
gl.glClearColor(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, transparentBackground ? 0f : 1f);
engine.display(gl, GLU);
}
use of com.jogamp.opengl.GL2 in project gephi by gephi.
the class OffscreenCanvas method init.
@Override
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
initConfig(gl);
engine.initDisplayLists(gl, GLU);
TextManager textManager = VizController.getInstance().getTextManager();
textManager.reinitRenderers();
}
use of com.jogamp.opengl.GL2 in project gephi by gephi.
the class ScreenshotMaker method run.
@Override
public void run() {
beforeTaking();
try {
// Stop display
engine.stopDisplay();
// Start progress
Progress.start(progressTicket);
Thread.sleep(100);
final OffscreenCanvas drawable = new OffscreenCanvas(tileWidth, tileHeight, transparentBackground, antiAliasing);
GLAutoDrawable autoDrawable = drawable.getGLAutoDrawable();
//Tile rendering
final TileRenderer renderer = new TileRenderer();
renderer.setImageSize(width, height);
renderer.setTileSize(tileWidth, tileHeight, 0);
renderer.attachAutoDrawable(autoDrawable);
final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider = GLPixelBuffer.defaultProviderWithRowStride;
final boolean[] flipVertically = { false };
final GLEventListener preTileGLEL = new GLEventListener() {
@Override
public void init(final GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, transparentBackground ? 4 : 3, true);
final GLPixelBuffer imageBuffer = pixelBufferProvider.allocate(gl, null, pixelAttribs, true, width, height, 1, 0);
renderer.setImageBuffer(imageBuffer);
flipVertically[0] = !drawable.isGLOriented();
}
@Override
public void dispose(final GLAutoDrawable drawable) {
}
@Override
public void display(final GLAutoDrawable drawable) {
}
@Override
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
}
};
renderer.setGLEventListener(preTileGLEL, null);
vizConfig.setDisableLOD(true);
engine.updateLOD();
// Render tiles
int tiles = renderer.getParam(TileRenderer.TR_COLUMNS) * renderer.getParam(TileRenderer.TR_ROWS);
Progress.switchToDeterminate(progressTicket, tiles);
while (!renderer.eot() && !cancel) {
renderer.display();
Progress.progress(progressTicket);
}
Progress.switchToIndeterminate(progressTicket);
renderer.detachAutoDrawable();
autoDrawable.invoke(true, new GLRunnable() {
@Override
public boolean run(final GLAutoDrawable drawable) {
drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
// drawable.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
return false;
}
});
vizConfig.setDisableLOD(false);
engine.updateLOD();
if (!cancel) {
final GLPixelBuffer imageBuffer = renderer.getImageBuffer();
final TextureData textureData = new TextureData(autoDrawable.getChosenGLCapabilities().getGLProfile(), transparentBackground ? GL.GL_RGBA : GL.GL_RGB, width, height, 0, imageBuffer.pixelAttributes, false, false, flipVertically[0], imageBuffer.buffer, null);
// Get File
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
if (!autoSave) {
//Get last directory
String lastPathDefault = NbPreferences.forModule(ScreenshotMaker.class).get(LAST_PATH_DEFAULT, null);
String lastPath = NbPreferences.forModule(ScreenshotMaker.class).get(LAST_PATH, lastPathDefault);
final JFileChooser chooser = new JFileChooser(lastPath);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setDialogTitle(NbBundle.getMessage(ScreenshotMaker.class, "ScreenshotMaker.filechooser.title"));
DialogFileFilter dialogFileFilter = new DialogFileFilter(NbBundle.getMessage(ScreenshotMaker.class, "ScreenshotMaker.filechooser.pngDescription"));
dialogFileFilter.addExtension("png");
chooser.addChoosableFileFilter(dialogFileFilter);
File selectedFile = new File(chooser.getCurrentDirectory(), getDefaultFileName() + ".png");
chooser.setSelectedFile(selectedFile);
int returnFile = chooser.showSaveDialog(null);
if (returnFile == JFileChooser.APPROVE_OPTION) {
ScreenshotMaker.this.file = chooser.getSelectedFile();
if (!ScreenshotMaker.this.file.getPath().endsWith(".png")) {
ScreenshotMaker.this.file = new File(ScreenshotMaker.this.file.getPath() + ".png");
}
//Save last path
defaultDirectory = ScreenshotMaker.this.file.getParentFile().getAbsolutePath();
NbPreferences.forModule(ScreenshotMaker.class).put(LAST_PATH, defaultDirectory);
} else {
ScreenshotMaker.this.file = null;
}
} else {
ScreenshotMaker.this.file = new File(defaultDirectory, getDefaultFileName() + ".png");
}
}
});
// Write file
if (file != null) {
TextureIO.write(textureData, file);
}
}
autoDrawable.destroy();
//Reinit text renderer
textManager.reinitRenderers();
engine.startDisplay();
//Progress finish
Progress.finish(progressTicket);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
// After taking
afterTaking();
}
Aggregations