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

The following examples show how to use com.badlogic.gdx.utils.BufferUtils#newByteBuffer() . 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: MSI.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  final Calendar calendar = Calendar.getInstance();
  DateFormat format = DateFormat.getDateTimeInstance();
  Gdx.app.log(TAG, format.format(calendar.getTime()));

  try {
    InetAddress address = InetAddress.getLocalHost();
    Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT);
    Gdx.app.log(TAG, "Host Name: " + address.getHostName());
  } catch (UnknownHostException e) {
    Gdx.app.error(TAG, e.getMessage(), e);
  }

  Gdx.app.log(TAG, "Starting server...");
  server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null);
  buffer = BufferUtils.newByteBuffer(4096);
}
 
Example 2
Source File: BasePicker.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public Pixmap getFrameBufferPixmap(Viewport viewport) {
    int w = viewport.getScreenWidth();
    int h = viewport.getScreenHeight();
    int x = viewport.getScreenX();
    int y = viewport.getScreenY();
    final ByteBuffer pixelBuffer = BufferUtils.newByteBuffer(w * h * 4);

    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbo.getFramebufferHandle());
    Gdx.gl.glReadPixels(x, y, w, h, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pixelBuffer);
    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);

    final int numBytes = w * h * 4;
    byte[] imgLines = new byte[numBytes];
    final int numBytesPerLine = w * 4;
    for (int i = 0; i < h; i++) {
        pixelBuffer.position((h - i - 1) * numBytesPerLine);
        pixelBuffer.get(imgLines, i * numBytesPerLine, numBytesPerLine);
    }

    Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    BufferUtils.copy(imgLines, 0, pixmap.getPixels(), imgLines.length);

    return pixmap;
}
 
Example 3
Source File: FreeType.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public ByteBuffer getBuffer() {
	if (getRows() == 0)
		// Issue #768 - CheckJNI frowns upon env->NewDirectByteBuffer with NULL buffer or capacity 0
		//                  "JNI WARNING: invalid values for address (0x0) or capacity (0)"
		//              FreeType sets FT_Bitmap::buffer to NULL when the bitmap is empty (e.g. for ' ')
		//              JNICheck is on by default on emulators and might have a point anyway...
		//              So let's avoid this and just return a dummy non-null non-zero buffer
		return BufferUtils.newByteBuffer(1);
	return getBuffer(address);
}
 
Example 4
Source File: PipelineState.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
protected PipelineState () {
	byteBuffer = BufferUtils.newByteBuffer(32);
}
 
Example 5
Source File: MCP.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  final Calendar calendar = Calendar.getInstance();
  DateFormat format = DateFormat.getDateTimeInstance();
  Gdx.app.log(TAG, format.format(calendar.getTime()));

  try {
    InetAddress address = InetAddress.getLocalHost();
    Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT);
    Gdx.app.log(TAG, "Host Name: " + address.getHostName());
  } catch (UnknownHostException e) {
    Gdx.app.error(TAG, e.getMessage(), e);
  }

  clientThreads = new ThreadGroup("MCPClients");

  Gdx.app.log(TAG, "Starting server...");
  server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null);
  buffer = BufferUtils.newByteBuffer(4096);
  kill = new AtomicBoolean(false);
  main = new Thread(new Runnable() {
    @Override
    public void run() {
      while (!kill.get()) {
        Gdx.app.log(TAG, "waiting...");
        Socket socket = server.accept(null);
        Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress());
        if (CLIENTS.size() >= MAX_CLIENTS) {
          try {
            ConnectionDenied(socket, "Server is Full");
          } catch (Throwable ignored) {
          } finally {
            socket.dispose();
          }
        } else {
          try {
            ConnectionAccepted(socket);
            new Client(socket).start();
          } catch (Throwable ignored) {
            socket.dispose();
          }
        }
      }

      Gdx.app.log(TAG, "killing child threads...");
      for (Client client : CLIENTS) {
        if (client != null) {
          client.kill.set(true);
        }
      }

      Gdx.app.log(TAG, "killing thread...");
    }
  });
  main.setName("MCP");
  main.start();

  cli = new Thread(new Runnable() {
    @Override
    public void run() {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      while (!kill.get()) {
        try {
          if (!reader.ready()) continue;
          String in = reader.readLine();
          if (in.equalsIgnoreCase("exit")) {
            Gdx.app.exit();
          } else if (in.equalsIgnoreCase("games")) {
            Gdx.app.log(TAG, "games:");
            for (GameSession session : sessions.values()) {
              Gdx.app.log(TAG, "  " + session);
            }
          }
        } catch (Throwable t) {
          Gdx.app.log(TAG, t.getMessage());
        }
      }
    }
  });
  cli.setName("CLI");
  cli.start();
}
 
Example 6
Source File: Main.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  final Calendar calendar = Calendar.getInstance();
  DateFormat format = DateFormat.getDateTimeInstance();
  Gdx.app.log(TAG, format.format(calendar.getTime()));

  try {
    InetAddress address = InetAddress.getLocalHost();
    Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT);
    Gdx.app.log(TAG, "Host Name: " + address.getHostName());
  } catch (UnknownHostException e) {
    Gdx.app.error(TAG, e.getMessage(), e);
  }

  clientThreads = new ThreadGroup("D2CSClients");

  Gdx.app.log(TAG, "Starting server...");
  server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null);
  buffer = BufferUtils.newByteBuffer(4096);
  kill = new AtomicBoolean(false);
  main = new Thread(new Runnable() {
    @Override
    public void run() {
      while (!kill.get()) {
        Gdx.app.log(TAG, "waiting...");
        Socket socket = server.accept(null);
        Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress());
        synchronized (clients) {
          if (clients.size >= MAX_CLIENTS) {
            try {
              ConnectionDenied(socket, "Server is Full");
            } catch (Throwable ignored) {
            } finally {
              socket.dispose();
            }
          } else {
            try {
              ConnectionAccepted(socket);
              int id = clients.size;
              Client client = new Client(id, socket);
              clients.add(client);
              client.start();
            } catch (Throwable ignored) {
              socket.dispose();
            }
          }
        }
      }

      Gdx.app.log(TAG, "killing child threads...");
      synchronized (clients) {
        for (Client client : clients) {
          if (client != null) {
            client.kill.set(true);
          }
        }

        clients.clear();
      }

      Gdx.app.log(TAG, "killing thread...");
    }
  });
  main.setName("D2CS");
  main.start();
}
 
Example 7
Source File: BNLS.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {
  Gdx.app.setLogLevel(Application.LOG_DEBUG);

  final Calendar calendar = Calendar.getInstance();
  DateFormat format = DateFormat.getDateTimeInstance();
  Gdx.app.log(TAG, format.format(calendar.getTime()));

  try {
    InetAddress address = InetAddress.getLocalHost();
    Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT);
    Gdx.app.log(TAG, "Host Name: " + address.getHostName());
  } catch (UnknownHostException e) {
    Gdx.app.error(TAG, e.getMessage(), e);
  }

  clientThreads = new ThreadGroup("BNLSClients");

  Gdx.app.log(TAG, "Starting server...");
  server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null);
  buffer = BufferUtils.newByteBuffer(4096);
  kill = new AtomicBoolean(false);
  main = new Thread(new Runnable() {
    @Override
    public void run() {
      while (!kill.get()) {
        Gdx.app.log(TAG, "waiting...");
        Socket socket = server.accept(null);
        Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress());
        if (CLIENTS.size() >= MAX_CLIENTS) {
          try {
            ConnectionDenied(socket, "Server is Full");
          } catch (Throwable ignored) {
          } finally {
            socket.dispose();
          }
        } else {
          try {
            ConnectionAccepted(socket);
            new Client(socket).start();
          } catch (Throwable ignored) {
            socket.dispose();
          }
        }
      }

      Gdx.app.log(TAG, "killing child threads...");
      for (Client client : CLIENTS) {
        if (client != null) {
          client.kill.set(true);
        }
      }

      Gdx.app.log(TAG, "killing thread...");
    }
  });
  main.setName("BNLS");
  main.start();

  cli = new Thread(new Runnable() {
    @Override
    public void run() {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      while (!kill.get()) {
        try {
          if (!reader.ready()) continue;
          String in = reader.readLine();
          if (in.equalsIgnoreCase("exit")) {
            Gdx.app.exit();
          } else if (in.equalsIgnoreCase("realms")) {
            Gdx.app.log(TAG, "realms:");
            for (String[] realms : REALMS) {
              Gdx.app.log(TAG, "  " + realms[0] + " " + realms[1]);
            }
          }
        } catch (Throwable t) {
          Gdx.app.log(TAG, t.getMessage());
        }
      }
    }
  });
  cli.setName("CLI");
  cli.start();
}
 
Example 8
Source File: PipelineState.java    From RuinsOfRevenge with MIT License 4 votes vote down vote up
protected PipelineState() {
	byteBuffer = BufferUtils.newByteBuffer( 32 );
}