com.jogamp.opengl.GLException Java Examples

The following examples show how to use com.jogamp.opengl.GLException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Batch.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Draw the contents of this batch using the specified open GL context.
 * <p>
 * This assumes that all the relevant shader loading and binding of uniforms
 * has been done immediately prior to this call on the specified GL context.
 *
 * @param gl The GL context to draw the batch to.
 */
public void draw(final GL3 gl) {
    if (!finalised) {
        throw new RenderException("Attempting to draw this batch before first finalising it on the relevant open GL context.");
    }

    // glDrawArrays() throws INVALID_OPERATION on some video cards when using texture buffers.
    // Catch it here to avoid problems in other areas.
    try {
        gl.glBindVertexArray(vertexArrayObjectName[0]);

        enableVertexAttribArrays(gl);

        gl.glDrawArrays(primitiveType, 0, numVertices);

        disableVertexAttribArrays(gl);

        gl.glBindVertexArray(0);
    } catch (GLException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
Example #2
Source File: JOGLRenderer.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
static Texture importTexture(File f, final boolean deleteOnExit) throws GLException, IOException {
	final Texture tex = TextureIO.newTexture(f, false);
	if (deleteOnExit && f.exists())
		try {
			if (WarpPI.getPlatform().getSettings().isDebugEnabled())
				throw new IOException("Delete on exit!");
			f.delete();
		} catch (final Exception ex) {
			f.deleteOnExit();
		}
	tex.setTexParameteri(JOGLRenderer.gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
	tex.setTexParameteri(JOGLRenderer.gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
	f = null;
	return tex;
}
 
Example #3
Source File: JOGLSkin.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final DisplayOutputDevice d) {
	try {
		final OpenedTextureData i = JOGLRenderer.openTexture(texturePath, isResource);
		t = JOGLRenderer.importTexture(i.f, i.deleteOnExit);
		w = i.w;
		h = i.h;
		((JOGLEngine) d.getGraphicEngine()).registerTexture(t);
		initialized = true;
	} catch (GLException | IOException e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
Example #4
Source File: GLVisualProcessor.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new GLVisualProcessor with a {@link GraphRenderable} and an
 * {@link AxesRenderable} and a {@link FPSRenderable}.
 *
 * @param debugGl Whether or not to utilise a GLContext that includes
 * debugging.
 * @param printGlCapabilities Whether or not to print out a list of GL
 * capabilities upon initialisation.
 */
public GLVisualProcessor(final boolean debugGl, final boolean printGlCapabilities) {
    graphRenderable = new GraphRenderable(this);
    final AxesRenderable axesRenderable = new AxesRenderable(this);
    final FPSRenderable fpsRenderable = new FPSRenderable(this);
    renderer = new GLRenderer(this, Arrays.asList(graphRenderable, axesRenderable, fpsRenderable), debugGl, printGlCapabilities);
    try {
        canvas = new GLCanvas(SharedDrawable.getGLCapabilities());
    } catch (GLException ex) {
        GLInfo.respondToIncompatibleHardwareOrGL(null);
        throw ex;
    }
}
 
Example #5
Source File: JOGLFont.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
private void genTexture() {
	try {
		texture = JOGLRenderer.importTexture(tmpFont, true);
		tmpFont = null;
	} catch (GLException | IOException e) {
		e.printStackTrace();
	}
}
 
Example #6
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
Texture buildTexture(final GL gl, final BufferedImage im) {
	try {
		final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), im, true);
		final Texture texture = new Texture(gl, data);
		data.flush();
		return texture;
	} catch (final GLException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example #7
Source File: Screenshots.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Stolen from com.jogamp.opengl.util.awt.Screenshot.readToBufferedImage()
 * 
 * JOGL 2.1.2
 */
private static BufferedImage readToBufferedImage(
    int x,int y, int width, int height, boolean alpha) throws GLException {

  int bufImgType = (alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
  int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2ES3.GL_BGR);

  // Allocate necessary storage
  BufferedImage image = new BufferedImage(width, height, bufImgType);

  GLContext glc = GLContext.getCurrent();
  GL gl = glc.getGL();

  // Set up pixel storage modes
  GLPixelStorageModes psm = new GLPixelStorageModes();
  psm.setPackAlignment(gl, 1);

  // read the BGR values into the image
  gl.glReadPixels(x, y, width, height, readbackType,
      GL.GL_UNSIGNED_BYTE,
      ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData()));

  // Restore pixel storage modes
  psm.restore(gl);

  if( glc.getGLDrawable().isGLOriented() ) {
    // Must flip BufferedImage vertically for correct results
    ImageUtil.flipImageVertically(image);
  }
  return image;
}
 
Example #8
Source File: UIListenerBase01.java    From jogl-samples with MIT License 5 votes vote down vote up
public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zoom), 0, objName);

    final String filename = dir + tech + sw +".png";
    if(screenshot.readPixels(drawable.getGL(), false)) {
        screenshot.write(new File(filename));
    }
}
 
Example #9
Source File: GPURendererListenerBase01.java    From jogl-samples with MIT License 5 votes vote down vote up
public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    pw.printf("-%03dx%03d-Z%04d-S%02d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), sampleCount[0], objName);

    final String filename = dir + tech + sw +".png";
    if(screenshot.readPixels(drawable.getGL(), false)) {
        screenshot.write(new File(filename));
    }
}
 
Example #10
Source File: TestTextRendererNEWT10.java    From jogl-samples with MIT License 5 votes vote down vote up
public void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount) throws GLException, IOException {
    final String dir = "./";
    final String objName = getSimpleTestName(".")+"-snap"+screenshot_num;
    screenshot_num++;
    final String modeS = Region.getRenderModeString(renderModes);
    final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
            drawable.getChosenGLCapabilities().getNumSamples(),
            TestTextRendererNEWT10.fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
    final String filename = dir + bname +".png";
    if(screenshot.readPixels(gl, false)) {
        screenshot.write(new File(filename));
    }
}
 
Example #11
Source File: TestTextRendererNEWTBugXXXX.java    From jogl-samples with MIT License 5 votes vote down vote up
public void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount) throws GLException, IOException {
    final String dir = "./";
    final String objName = getSimpleTestName(".")+"-snap"+screenshot_num;
    screenshot_num++;
    final String modeS = Region.getRenderModeString(renderModes);
    final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
            drawable.getChosenGLCapabilities().getNumSamples(),
            TestTextRendererNEWTBugXXXX.fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
    final String filename = dir + bname +".png";
    if(screenshot.readPixels(gl, false)) {
        screenshot.write(new File(filename));
    }
}
 
Example #12
Source File: TestTextRendererNEWT00.java    From jogl-samples with MIT License 5 votes vote down vote up
public void printScreen(final int renderModes, final GLAutoDrawable drawable, final String dir, final String objName, final boolean exportAlpha) throws GLException, IOException {
    final String modeS = Region.getRenderModeString(renderModes);
    final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
            drawable.getChosenGLCapabilities().getNumSamples(),
            TestTextRendererNEWT00.fontSizeFixed, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, vbaaSampleCount[0]);
    final String filename = dir + bname +".png";
    if(screenshot.readPixels(drawable.getGL(), false)) {
        screenshot.write(new File(filename));
    }
}
 
Example #13
Source File: TexCache.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
private int loadGLTexture(GL2GL3 gl, LoadingEntry le) {

		if (le.failed.get()) {
			return badTextureID;
		}

		int[] i = new int[1];
		gl.glGenTextures(1, i, 0);
		int glTexID = i[0];

		gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, glTexID);

		if (le.compressed)
			gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR );
		else
			gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR_MIPMAP_LINEAR );

		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAG_FILTER, GL2GL3.GL_LINEAR );
		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT);
		gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT);

		gl.glPixelStorei(GL2GL3.GL_UNPACK_ALIGNMENT, 1);

		// Attempt to load to a proxy texture first, then see what happens
		int internalFormat = 0;
		if (le.hasAlpha && le.compressed) {
			// We do not currently support compressed textures with alpha
			assert(false);
			return badTextureID;
		} else if(le.hasAlpha && !le.compressed) {
			internalFormat = GL2GL3.GL_RGBA;
		} else if(!le.hasAlpha && le.compressed) {
			internalFormat = GL2GL3.GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
		} else if(!le.hasAlpha && !le.compressed) {
			internalFormat = GL2GL3.GL_RGB;
		}

		gl.glBindBuffer(GL2GL3.GL_PIXEL_UNPACK_BUFFER, le.bufferID);
		gl.glUnmapBuffer(GL2GL3.GL_PIXEL_UNPACK_BUFFER);

		try {
			if (le.compressed) {
				gl.glCompressedTexImage2D(GL2GL3.GL_TEXTURE_2D, 0, internalFormat, le.width,
				                          le.height, 0, le.data.capacity(), 0);
				_renderer.usingVRAM(le.data.capacity());
			} else {
				gl.glTexImage2D(GL2GL3.GL_TEXTURE_2D, 0, internalFormat, le.width,
				                le.height, 0, GL2GL3.GL_BGRA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV, 0);
				_renderer.usingVRAM(le.width*le.height*4);
			}

			// Note we do not let openGL generate compressed mipmaps because it stalls the render thread really badly
			// in theory it could be generated in the worker thread, but not yet
			if (!le.compressed)
				gl.glGenerateMipmap(GL2GL3.GL_TEXTURE_2D);
		} catch (GLException ex) {
			// We do not have enough texture memory
			LogBox.renderLog(String.format("Error loading texture: %s", le.imageURI.toString()));
			LogBox.renderLog(String.format("  %s", ex.toString()));
			return badTextureID;
		}

		gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, 0);

		gl.glBindBuffer(GL2GL3.GL_PIXEL_UNPACK_BUFFER, 0);
		i[0] = le.bufferID;
		gl.glDeleteBuffers(1, i, 0);

		// Finally queue a redraw in case an asset avoided drawing this one
		_renderer.queueRedraw();
		return glTexID;
	}
 
Example #14
Source File: TestTextRendererNEWT10.java    From jogl-samples with MIT License 4 votes vote down vote up
void testTextRendererImpl(final int renderModes, final int sampleCount) throws InterruptedException, GLException, IOException {
    final GLProfile glp;
    if(forceGL3) {
        glp = GLProfile.get(GLProfile.GL3);
    } else if(forceES2) {
        glp = GLProfile.get(GLProfile.GLES2);
    } else {
        glp = GLProfile.getGL2ES2();
    }

    final GLCapabilities caps = new GLCapabilities( glp );
    caps.setAlphaBits(4);
    if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
        caps.setSampleBuffers(true);
        caps.setNumSamples(sampleCount);
    }
    System.err.println("Requested: "+caps);
    System.err.println("Requested: "+Region.getRenderModeString(renderModes));

    final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, 800, 400, true);
    final GLDrawable drawable = winctx.context.getGLDrawable();
    final GL2ES2 gl = winctx.context.getGL().getGL2ES2();

    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    System.err.println("Chosen: "+winctx.window.getChosenCapabilities());

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
    rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
    final TextRegionUtil textRenderUtil = new TextRegionUtil(renderModes);

    // init
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    renderer.init(gl, 0);
    rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
    screenshot = new GLReadBufferUtil(false, false);

    // reshape
    gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());

    // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
    renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);

    final int[] sampleCountIO = { sampleCount };
    // display
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    if( null == customStr ) {
        renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0,  0, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "Hello World", 0, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "4567890123456", 4, -1, -1000,sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "I like JogAmp", 4, -1, -1000, sampleCountIO);

        int c = 0;
        renderString(drawable, gl, renderer, textRenderUtil, "GlueGen", c++, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "JOAL", c++, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "JOGL", c++, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "JOCL", c++, -1, -1000, sampleCountIO);
    } else {
        renderString(drawable, gl, renderer, textRenderUtil, customStr, 0,  0, -1000, sampleCountIO);
    }
    drawable.swapBuffers();
    printScreen(renderModes, drawable, gl, false, sampleCount);

    sleep();

    // dispose
    screenshot.dispose(gl);
    renderer.destroy(gl);

    NEWTGLContext.destroyWindow(winctx);
}
 
Example #15
Source File: TestTextRendererNEWT10.java    From jogl-samples with MIT License 4 votes vote down vote up
@Test
public void test02TextRendererVBAA04() throws InterruptedException, GLException, IOException {
    testTextRendererImpl(Region.VBAA_RENDERING_BIT, 4);
}
 
Example #16
Source File: TestTextRendererNEWT10.java    From jogl-samples with MIT License 4 votes vote down vote up
@Test
public void test01TextRendererMSAA04() throws InterruptedException, GLException, IOException {
    testTextRendererImpl(0, 4);
}
 
Example #17
Source File: TestTextRendererNEWT10.java    From jogl-samples with MIT License 4 votes vote down vote up
@Test
public void test00TextRendererNONE00() throws InterruptedException, GLException, IOException {
    testTextRendererImpl(0, 0);
}
 
Example #18
Source File: TestTextRendererNEWTBugXXXX.java    From jogl-samples with MIT License 4 votes vote down vote up
void testTextRendererImpl(final Font[] fonts, final int renderModes, final int sampleCount, final boolean onlyIssues) throws InterruptedException, GLException, IOException {
    final GLProfile glp;
    if(forceGL3) {
        glp = GLProfile.get(GLProfile.GL3);
    } else if(forceES2) {
        glp = GLProfile.get(GLProfile.GLES2);
    } else {
        glp = GLProfile.getGL2ES2();
    }

    final GLCapabilities caps = new GLCapabilities( glp );
    caps.setAlphaBits(4);
    if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
        caps.setSampleBuffers(true);
        caps.setNumSamples(sampleCount);
    }
    caps.setOnscreen(false);
    System.err.println("Requested: "+caps);
    System.err.println("Requested: "+Region.getRenderModeString(renderModes));

    final int totalHeight = ( (int)fontSize + 1 ) * ( onlyIssues ? 3 : 6 ) * fonts.length;
    final NEWTGLContext.WindowContext winctx =
            NEWTGLContext.createWindow(caps, 800, totalHeight, true);
    final GLDrawable drawable = winctx.context.getGLDrawable();
    final GL2ES2 gl = winctx.context.getGL().getGL2ES2();

    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    System.err.println("Chosen: "+winctx.window.getChosenCapabilities());

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
    rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
    final TextRegionUtil textRenderUtil = new TextRegionUtil(renderModes);

    // init
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    renderer.init(gl, 0);
    rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
    screenshot = new GLReadBufferUtil(false, false);

    // reshape
    gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());

    // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
    renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);

    final int[] sampleCountIO = { sampleCount };
    // display
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    for(int i=0; i<fonts.length; i++) {
        final Font font = fonts[i];
        renderString(drawable, gl, renderer, font, textRenderUtil, font.getFullFamilyName(null).toString()+": "+issues, 0,  0==i?0:-1, -1000, sampleCountIO);
        if(!onlyIssues) {
            renderString(drawable, gl, renderer, font, textRenderUtil, "012345678901234567890123456789", 0,  -1, -1000, sampleCountIO);
            renderString(drawable, gl, renderer, font, textRenderUtil, "abcdefghijklmnopqrstuvwxyz", 0, -1, -1000, sampleCountIO);
            renderString(drawable, gl, renderer, font, textRenderUtil, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, -1, -1000, sampleCountIO);
        }
        renderString(drawable, gl, renderer, font, textRenderUtil, "", 0, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, font, textRenderUtil, "", 0, -1, -1000, sampleCountIO);
    }

    drawable.swapBuffers();
    printScreen(renderModes, drawable, gl, false, sampleCount);

    sleep();

    // dispose
    screenshot.dispose(gl);
    renderer.destroy(gl);

    NEWTGLContext.destroyWindow(winctx);
}
 
Example #19
Source File: TestTextRendererNEWTBugXXXX.java    From jogl-samples with MIT License 4 votes vote down vote up
@Test
public void test01OnlyIssues() throws InterruptedException, GLException, IOException {
    testTextRendererImpl(FontSet01.getSet01(), Region.VBAA_RENDERING_BIT, 4, true);
}
 
Example #20
Source File: TestTextRendererNEWTBugXXXX.java    From jogl-samples with MIT License 4 votes vote down vote up
@Test
public void test00All() throws InterruptedException, GLException, IOException {
    testTextRendererImpl(FontSet01.getSet01(), Region.VBAA_RENDERING_BIT, 4, false);
}
 
Example #21
Source File: GPUTextRendererListenerBase01.java    From jogl-samples with MIT License 4 votes vote down vote up
public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final boolean exportAlpha) throws GLException, IOException {
    final String fn = font.getFullFamilyName(null).toString();
    printScreen(drawable, dir, tech, fn.replace(' ', '_'), exportAlpha);
}
 
Example #22
Source File: OpenGLGFXCMD.java    From sagetv with Apache License 2.0 4 votes vote down vote up
private void initpbuffer()
{
  GL2 gl;
  System.out.println("initpbuffer");
  osdwidth=newosdwidth;
  osdheight=newosdheight;
  GLCapabilities caps = new GLCapabilities(null);
  caps.setHardwareAccelerated(true);
  caps.setDoubleBuffered(false);
  caps.setAlphaBits(8);
  caps.setRedBits(8);
  caps.setGreenBits(8);
  caps.setBlueBits(8);
  caps.setDepthBits(0);
  caps.setFBO(false);
  System.out.println("initpbuffer2");
  if (!GLDrawableFactory.getFactory(caps.getGLProfile()).canCreateGLPbuffer(null, caps.getGLProfile()))
  {
    throw new GLException("pbuffers unsupported");
  }
  if(pbuffer!=null) pbuffer.destroy();
  System.out.println("initpbuffer3");
  pbuffer = GLDrawableFactory.getFactory(caps.getGLProfile()).createOffscreenAutoDrawable(null,
      caps,
      null,
      osdwidth,
      osdheight
      );
  pbuffer.setContext(pbuffer.createContext(c.getContext()), true);
  //pbuffer.setContext(c.getContext(), false);
  System.out.println("initpbuffer4: pbuffers is null? " + (pbuffer==null));
  if(pbuffer.getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT)
  {
    System.out.println("Couldn't make pbuffer current?");
    return;
  }
  System.out.println("initpbuffer5");
  gl = pbuffer.getGL().getGL2();

  gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);

  gl.glClear( gl.GL_COLOR_BUFFER_BIT);

  gl.glViewport(0, 0, osdwidth, osdheight);
  gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
  gl.glLoadIdentity();
  gl.glOrtho(0,osdwidth,0,osdheight,-1.0,1.0);
  gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
  gl.glLoadIdentity();

  // TODO: look into reusing same texture like OSX version...
  if(osdt!=null) gl.glDeleteTextures(1, osdt, 0);
  osdt = new int[1];
  byte img[] = new byte[osdwidth*osdheight*4];
  gl.glGenTextures(1, osdt, 0);
  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,osdt[0]);
  gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
  gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
  gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 4, osdwidth, osdheight, 0,
      gl.GL_BGRA, bigendian ? gl.GL_UNSIGNED_INT_8_8_8_8_REV : gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img));

  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, osdt[0]);
  gl.glCopyTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, 0, 0, osdwidth, osdheight);
  gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  System.out.println("initpbuffer6");
  pbuffer.getContext().release();
  System.out.println("initpbuffer7");
}
 
Example #23
Source File: JOGLFont.java    From WarpPI with Apache License 2.0 4 votes vote down vote up
private void pregenTexture(boolean[][] chars) throws IOException {
		final int totalChars = intervalsTotalSize;
		int w = powerOf2((int) Math.ceil(Math.sqrt(totalChars) * charW));
		int h = powerOf2((int) Math.ceil(Math.sqrt(totalChars) * charH));
		int maxIndexW = (int) Math.floor((double) w / (double) charW) - 1;
		int maxIndexH = (int) Math.floor((double) h / (double) charH) - 1;
		if (w > h) {
			System.out.println("w > h");
			h = powerOf2((int) Math.ceil((double) totalChars / (double) maxIndexW * charH));
			maxIndexH = (int) Math.floor((double) h / (double) charH) - 1;
		} else {
			System.out.println("w <= h");
			w = powerOf2((int) Math.ceil((double) totalChars / (double) maxIndexH * charW));
			maxIndexW = (int) Math.floor((double) w / (double) charW) - 1;
		}
//		final int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));

		System.out.println((int) Math.ceil(Math.sqrt(totalChars) * charW) + " * " + (int) Math.ceil(Math.sqrt(totalChars) * charH) + " --> " + w + " * " + h);

		final File f = Files.createTempFile("texture-font-", ".png").toFile();
		f.deleteOnExit();
		final FileOutputStream outputStream = new FileOutputStream(f);
		final ImageInfo imi = new ImageInfo(w, h, 8, true); // 8 bits per channel, alpha
		// open image for writing to a output stream
		final PngWriter png = new PngWriter(outputStream, imi);
		for (int y = 0; y < png.imgInfo.rows; y++) {
			final ImageLineInt iline = new ImageLineInt(imi);
			final int[] xValues = new int[imi.cols];
			for (int indexX = 0; indexX <= maxIndexW; indexX++) {// this line will be written to all rows
				final int charY = y % charH;
				final int indexY = (y - charY) / charH;
				final int i = indexY * (maxIndexW + 1) + indexX - minCharIndex;
				boolean[] currentChar;
				if (i < totalChars && (currentChar = chars[i]) != null)
					for (int charX = 0; charX < charW; charX++)
						if (i >= 0 & i < totalChars && currentChar != null && currentChar[charX + charY * charW])
							xValues[indexX * charW + charX] = 0xFFFFFFFF;
			}
			ImageLineHelper.setPixelsRGBA8(iline, xValues);
			if (y % 10 == 0)
				System.out.println(y + "/" + png.imgInfo.rows);
			png.writeRow(iline);
		}
		chars = null;
		png.end();
		WarpPI.getPlatform().gc();

		try {
			memoryWidth = w;
			memoryHeight = h;
			memoryWidthOfEachColumn = maxIndexW + 1;
			textureW = w;
			textureH = h;
			outputStream.flush();
			outputStream.close();
			WarpPI.getPlatform().gc();
			tmpFont = f;
		} catch (GLException | IOException e) {
			e.printStackTrace();
		}
	}