Java Code Examples for com.badlogic.gdx.utils.BufferUtils#newIntBuffer()

The following examples show how to use com.badlogic.gdx.utils.BufferUtils#newIntBuffer() . 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: Renderer.java    From VuforiaLibGDX with MIT License 6 votes vote down vote up
public Renderer() {

        lights = new Environment();
        lights.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));

        camera = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        camera.near = 1.0F;
        camera.far = 1000.0F;
        //set camera into "Vuforia - style" direction
        camera.position.set(new Vector3(0,0,0));
        camera.lookAt(new Vector3(0,0,1));

        IntBuffer buffer = BufferUtils.newIntBuffer(16);
        Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer);
        int units = buffer.get(0);
        Log.d("TAG", "Max texture units: "+units);
        modelBatch = new ModelBatch(new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 0)));
    }
 
Example 2
Source File: Screenshot.java    From Cubes with MIT License 6 votes vote down vote up
public static Setting screenshotResolutionSetting() {
  return new DropDownSetting(resolutions) {
    @Override
    public void onChange() {
      if ("normal".equals(selected) || "max".equals(selected)) return;

      IntBuffer intBuffer = BufferUtils.newIntBuffer(2);
      Gdx.gl20.glGetIntegerv(GL20.GL_MAX_VIEWPORT_DIMS, intBuffer);
      int maxWidth = intBuffer.get(0);
      int maxHeight = intBuffer.get(1);

      int[] resolution = resolutionMap.get(selected);
      if (resolution[0] > maxWidth || resolution[1] > maxHeight) selected = "normal";
    }

    @Override
    public boolean shouldDisplay() {
      return Compatibility.get().getApplicationType() == Application.ApplicationType.Desktop;
    }
  };
}
 
Example 3
Source File: Screenshot.java    From Cubes with MIT License 6 votes vote down vote up
@Override
public void frameStart() {
  if (!state.compareAndSet(0,  1)) return;

  String setting = ((DropDownSetting) Settings.getSetting(Settings.GRAPHICS_SCREENSHOT_SIZE)).getSelected();
  if ("max".equals(setting)) {
    IntBuffer intBuffer = BufferUtils.newIntBuffer(2);
    Gdx.gl20.glGetIntegerv(GL20.GL_MAX_VIEWPORT_DIMS, intBuffer);
    screenshotWidth = Math.min(intBuffer.get(0), 16384);
    screenshotHeight = Math.min(intBuffer.get(1), 16384);
  } else {
    screenshotWidth = Screenshot.resolutionMap.get(setting)[0];
    screenshotHeight = Screenshot.resolutionMap.get(setting)[1];
  }

  Log.debug("Attempting to take " + setting + " (" + screenshotWidth + "x" + screenshotHeight + ") resolution screenshot");
  frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, screenshotWidth, screenshotHeight, true, true);
  frameBuffer.begin();

  oldWidth = Graphics.RENDER_WIDTH;
  oldHeight = Graphics.RENDER_HEIGHT;
  Adapter.getInterface().resize(screenshotWidth, screenshotHeight);
}
 
Example 4
Source File: UniformSetter.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
private static IntBuffer getIntBuffer(JsonArray argsJson) {
  int[] intArgs = getIntArray(argsJson);
  IntBuffer intBuffer = BufferUtils.newIntBuffer(intArgs.length);
  intBuffer.put(intArgs);
  intBuffer.position(0);
  return intBuffer;
}
 
Example 5
Source File: PlatformInfoUtil.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
public static void getGlVersionInfo(JsonObject platformInfoJson, GL30 gl30) {

    BufferUtils.newIntBuffer(16);

    platformInfoJson.addProperty("GL_VERSION", Gdx.gl.glGetString(GL20.GL_VERSION));
    platformInfoJson.addProperty("GL_SHADING_LANGUAGE_VERSION", Gdx.gl.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
    platformInfoJson.addProperty("GL_VENDOR", Gdx.gl.glGetString(GL20.GL_VENDOR));
    platformInfoJson.addProperty("GL_RENDERER", Gdx.gl.glGetString(GL20.GL_RENDERER));

    IntBuffer buff = BufferUtils.newIntBuffer(16);

    buff.clear();
    Gdx.gl.glGetIntegerv(GL30.GL_MAJOR_VERSION, buff);
    platformInfoJson.addProperty("GL_MAJOR_VERSION", buff.get(0));

    buff.clear();
    Gdx.gl.glGetIntegerv(GL30.GL_MINOR_VERSION, buff);
    platformInfoJson.addProperty("GL_MINOR_VERSION", buff.get(0));

    JsonArray array = new JsonArray();
    try {
      final int GL_NUM_SHADING_LANGUAGE_VERSIONS = 0x82E9;
      buff.clear();
      Gdx.gl.glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS, buff);
      if(Gdx.gl.glGetError() == GL20.GL_NO_ERROR && gl30 != null) {
        int size = buff.get(0);
        for(int i=0; i < size; ++i) {
          array.add(gl30.glGetStringi(GL20.GL_SHADING_LANGUAGE_VERSION, i));
        }
      }
    }
    catch (IllegalStateException e) {
      // The above may not work depending what OpenGL version is supported.
    }
    platformInfoJson.add("Supported_GLSL_versions", array);

  }
 
Example 6
Source File: Program.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void link() {
	Gdx.gl.glLinkProgram( handle );
	
	IntBuffer status = BufferUtils.newIntBuffer(1);
	Gdx.gl.glGetProgramiv( handle, Gdx.gl.GL_LINK_STATUS, status );
	if (status.get() == Gdx.gl.GL_FALSE) {
		throw new Error( Gdx.gl.glGetProgramInfoLog( handle ) );
	}
}
 
Example 7
Source File: Shader.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void compile() {
	Gdx.gl.glCompileShader( handle );
	
	IntBuffer status = BufferUtils.newIntBuffer(1);
	Gdx.gl.glGetShaderiv( handle, Gdx.gl.GL_COMPILE_STATUS, status);
	if (status.get() == Gdx.gl.GL_FALSE) {
		throw new Error( Gdx.gl.glGetShaderInfoLog( handle ) );
	}
}
 
Example 8
Source File: World.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void takeScreenshot(String filename, int w) {

		// get viewport
		IntBuffer results = BufferUtils.newIntBuffer(16);
		Gdx.gl20.glGetIntegerv(GL20.GL_VIEWPORT, results);

		int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth);

		FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false);

		fbo.begin();
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		draw();
		Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h);

		// restore viewport
		fbo.end(results.get(0), results.get(1), results.get(2), results.get(3));

		// Flip the pixmap upside down
		ByteBuffer pixels = pixmap.getPixels();
		int numBytes = w * h * 4;
		byte[] lines = new byte[numBytes];
		int numBytesPerLine = w * 4;
		for (int i = 0; i < h; i++) {
			pixels.position((h - i - 1) * numBytesPerLine);
			pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
		}
		pixels.clear();
		pixels.put(lines);

		PixmapIO.writePNG(EngineAssetManager.getInstance().getUserFile(filename), pixmap);

		fbo.dispose();
	}
 
Example 9
Source File: Program.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void link() {
	Gdx.gl.glLinkProgram( handle );
	
	IntBuffer status = BufferUtils.newIntBuffer(1);
	Gdx.gl.glGetProgramiv( handle, GL20.GL_LINK_STATUS, status );
	if (status.get() == GL20.GL_FALSE) {
		throw new Error( Gdx.gl.glGetProgramInfoLog( handle ) );
	}
}
 
Example 10
Source File: Shader.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void compile() {
	Gdx.gl.glCompileShader( handle );

	IntBuffer status = BufferUtils.newIntBuffer(1);
	Gdx.gl.glGetShaderiv( handle, GL20.GL_COMPILE_STATUS, status);
	if (status.get() == GL20.GL_FALSE) {
		throw new Error( Gdx.gl.glGetShaderInfoLog( handle ) );
	}
}
 
Example 11
Source File: Framebuffer.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public Framebuffer() {
	IntBuffer buf = BufferUtils.newIntBuffer(1);
	Gdx.gl.glGenBuffers( 1, buf );
	id = buf.get();
}
 
Example 12
Source File: Framebuffer.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public void delete() {
	IntBuffer buf = BufferUtils.newIntBuffer(1);
	buf.put(id);
	Gdx.gl.glDeleteFramebuffers( 1, buf );
}
 
Example 13
Source File: Renderbuffer.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public Renderbuffer() {
	IntBuffer buf = BufferUtils.newIntBuffer(1);
	Gdx.gl.glGenRenderbuffers( 1, buf );
	id = buf.get();
}
 
Example 14
Source File: Renderbuffer.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public void delete() {
	IntBuffer buf = BufferUtils.newIntBuffer(1);
	buf.put(id);
	Gdx.gl.glDeleteRenderbuffers( 1, buf );
}