Java Code Examples for org.lwjgl.BufferUtils#createShortBuffer()

The following examples show how to use org.lwjgl.BufferUtils#createShortBuffer() . 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: Sky.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
private final ShortVBO[] makeSkyStripIndices() {
	ShortVBO[] strip_indices = new ShortVBO[subdiv_height - 2];
	for (int i = 0; i < strip_indices.length; i++) {
		int size = subdiv_axis*2 + 2;
		ShortBuffer temp = BufferUtils.createShortBuffer(size);
		for (int j = 0; j < subdiv_axis; j++) {
			temp.put(j*2, (short)(i*subdiv_axis + j));
			temp.put(j*2 + 1, (short)((i + 1)*subdiv_axis + j));
		}
		temp.put(subdiv_axis*2, (short)(i*subdiv_axis));
		temp.put(subdiv_axis*2 + 1, (short)((i + 1)*subdiv_axis));
		strip_indices[i] = new ShortVBO(ARBBufferObject.GL_STATIC_DRAW_ARB, size);
		temp.rewind();
		strip_indices[i].put(temp);
	}
	return strip_indices;
}
 
Example 2
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 6 votes vote down vote up
@Override
public TextureHandle generateTexture(int width, int height, ShortBuffer data, String name) {
	int texture = GL11.glGenTextures();
	if (texture == 0) {
		return null;
	}

	//fix strange alpha test problem (minimap and landscape are unaffected)
	ShortBuffer bfr = BufferUtils.createShortBuffer(data.capacity());
	int cap = data.capacity();
	for(int i = 0;i != cap;i++)	bfr.put(i, data.get(i));

	TextureHandle textureHandle = new TextureHandle(this, texture);
	bindTexture(textureHandle);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0,
			GL11.GL_RGBA, GL12.GL_UNSIGNED_SHORT_4_4_4_4, bfr);
	setTextureParameters();

	setObjectLabel(GL11.GL_TEXTURE, texture, name + "-tex");

	return textureHandle;
}
 
Example 3
Source File: GearGL20.java    From ldparteditor with MIT License 5 votes vote down vote up
public GearGL20() {
    bvertices = BufferUtils.createFloatBuffer(3);
    bvertices.put(0f);
    bvertices.put(0f);
    bvertices.put(0f);
    bindices = BufferUtils.createShortBuffer(3);
    bindices.put((short) 0);
    bindices.put((short) 0);
    bindices.put((short) 0);
    bvertices.flip();
    bindices.flip();
}
 
Example 4
Source File: SphereGL20.java    From ldparteditor with MIT License 5 votes vote down vote up
public SphereGL20() {
    bvertices = BufferUtils.createFloatBuffer(3);
    bvertices.put(0f);
    bvertices.put(0f);
    bvertices.put(0f);
    bindices = BufferUtils.createShortBuffer(3);
    bindices.put((short) 0);
    bindices.put((short) 0);
    bindices.put((short) 0);
    bvertices.flip();
    bindices.flip();
}
 
Example 5
Source File: LandscapeRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public LandscapeRenderer(World world, WorldInfo world_info, GUIRoot gui_root, AnimationManager manager) {
	ShortBuffer indices = world.getLandscapeIndices().getIndices();
	this.indices_vbo = new ShortVBO(ARBBufferObject.GL_STATIC_DRAW_ARB, indices.remaining());
	this.indices_vbo.put(indices);

	this.landscape_vertices = new LandscapeTileVertices(world.getHeightMap(), HeightMap.GRID_UNITS_PER_PATCH_EXP, world.getHeightMap().getPatchesPerWorld());
	this.patch_levels = new PatchLevel[world.getHeightMap().getPatchesPerWorld()][world.getHeightMap().getPatchesPerWorld()];
	for (int y = 0; y < patch_levels.length; y++)
		for (int x = 0; x < patch_levels.length; x++)
			patch_levels[y][x] = new PatchLevel();
	for (int y = 0; y < patch_levels.length; y++)
		for (int x = 0; x < patch_levels.length; x++) {
			PatchLevel right = getPatchWrapped(x + 1, y);
			PatchLevel top = getPatchWrapped(x, y + 1);
			patch_levels[y][x].init(right, top);
		}
	this.detail = world_info.detail;
	this.colormaps = world_info.colormaps;
	this.gui_root = gui_root;
	this.world = world;
	this.manager = manager;
	int levels = LandscapeTileIndices.getNumLOD(HeightMap.GRID_UNITS_PER_PATCH_EXP);
	patch_lists = new ArrayList[levels];
	for (int i = 0; i < patch_lists.length; i++)
		patch_lists[i] = new ArrayList();
	manager.registerAnimation(this);
	this.shadow_indices_buffer = BufferUtils.createShortBuffer(LandscapeTileIndices.getNumTriangles(world.getLandscapeIndices().getNumLOD() - 1)*3);
	resetEditing();
}
 
Example 6
Source File: Sky.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final ShortVBO makeSkyFanIndices() {
	int size = subdiv_axis + 2;
	ShortBuffer temp = BufferUtils.createShortBuffer(size);
	temp.put(0, (short)(sky_vertices.capacity()/3 - 1));
	for (int i = 0; i < subdiv_axis; i++) {
	   temp.put(i + 1, (short)((subdiv_height - 1)*subdiv_axis - i - 1));
	}
	temp.put(subdiv_axis + 1, (short)((subdiv_height - 1)*subdiv_axis - 1));
	
	ShortVBO fan_indices = new ShortVBO(ARBBufferObject.GL_STATIC_DRAW_ARB, size);
	temp.rewind();
	fan_indices.put(temp);
	return fan_indices;
}
 
Example 7
Source File: GLMesh.java    From WraithEngine with Apache License 2.0 4 votes vote down vote up
@Override
public void update(VertexData vertexData)
{
    if (isDisposed())
        throw new IllegalStateException("Mesh already disposed!");

    FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexData.getDataArray().length);
    vertexBuffer.put(vertexData.getDataArray());
    vertexBuffer.flip();

    ShortBuffer indexBuffer = BufferUtils.createShortBuffer(vertexData.getTriangles().length);
    indexBuffer.put(vertexData.getTriangles());
    indexBuffer.flip();

    if (!created)
    {
        vaoId = opengl.generateVertexArray();
        vboId = opengl.generateBuffer();
        indexId = opengl.generateBuffer();
    }

    bindStates.bindVao(vaoId);

    bindStates.bindBuffer(false, vboId);
    opengl.uploadBufferData(vertexBuffer);

    int stride = vertexData.getVertexByteSize();
    int offset = 0;

    ShaderAttributes attributes = vertexData.getAttributeSizes();
    for (int i = 0; i < attributes.getCount(); i++)
    {
        opengl.setVertexAttributePointer(i, attributes.getAttributeSize(i), stride, offset);
        offset += attributes.getAttributeSize(i) * 4;
    }

    bindStates.bindBuffer(true, indexId);
    opengl.uploadBufferData(indexBuffer);

    created = true;
    indexCount = vertexData.getTriangles().length;
}
 
Example 8
Source File: SphereGL20.java    From ldparteditor with MIT License 4 votes vote down vote up
public SphereGL20(float radius, int segments) {

        final ArrayList<Float> vertices = new ArrayList<Float>();

        final double R = 1d / (segments - 1);
        final double S = 1d / (segments - 1);
        double r, s;

        for (r = 0; r < segments; ++r) {
            for (s = 0; s < segments; ++s) {

                final float y = (float) Math.sin(-0.5d * Math.PI + Math.PI * r * R);
                final float x = (float) (Math.cos(2d * Math.PI * s * S) * Math.sin(Math.PI * r * R));
                final float z = (float) (Math.sin(2d * Math.PI * s * S) * Math.sin(Math.PI * r * R));

                vertices.add(x * radius);
                vertices.add(y * radius);
                vertices.add(z * radius);

                short curRow = (short) (r * segments);
                short nextRow = (short) ((r + 1) * segments);

                if (s != segments - 1) {
                    indices.add((short) (curRow + s));
                    indices.add((short) (curRow + (s + 1)));
                    indices.add((short) (nextRow + (s + 1)));
                    indices.add((short) (nextRow + s));
                }
            }
        }
        for (r = 1; r < segments; ++r) {
            indices.remove(indices.size() - 1);
            indices.remove(indices.size() - 1);
            indices.remove(indices.size() - 1);
            indices.remove(indices.size() - 1);
        }

        bvertices = BufferUtils.createFloatBuffer(vertices.size());
        bindices = BufferUtils.createShortBuffer(indices.size());

        for (Float f : vertices) {
            bvertices.put(f);
        }
        int vertex_count = vertices.size() / 3;

        for (Short sh : indices) {
            bindices.put((short) (sh % vertex_count));
        }

        bvertices.flip();
        // bnormals.flip();
        bindices.flip();

    }
 
Example 9
Source File: Utils.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static ShortBuffer toBuffer(short[] shorts) {
	ShortBuffer buffer = BufferUtils.createShortBuffer(shorts.length);
	buffer.put(shorts);
	buffer.rewind();
	return buffer;
}
 
Example 10
Source File: GLMesh.java    From WraithEngine with Apache License 2.0 4 votes vote down vote up
@Override
public void update(VertexData vertexData)
{
    if (isDisposed())
        throw new IllegalStateException("Mesh already disposed!");

    FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexData.getDataArray().length);
    vertexBuffer.put(vertexData.getDataArray());
    vertexBuffer.flip();

    ShortBuffer indexBuffer = BufferUtils.createShortBuffer(vertexData.getTriangles().length);
    indexBuffer.put(vertexData.getTriangles());
    indexBuffer.flip();

    if (!created)
    {
        vaoId = opengl.generateVertexArray();
        vboId = opengl.generateBuffer();
        indexId = opengl.generateBuffer();
    }

    bindStates.bindVao(vaoId);

    bindStates.bindBuffer(false, vboId);
    opengl.uploadBufferData(vertexBuffer);

    int stride = vertexData.getVertexByteSize();
    int offset = 0;

    ShaderAttributes attributes = vertexData.getAttributeSizes();
    for (int i = 0; i < attributes.getCount(); i++)
    {
        opengl.setVertexAttributePointer(i, attributes.getAttributeSize(i), stride, offset);
        offset += attributes.getAttributeSize(i) * 4;
    }

    bindStates.bindBuffer(true, indexId);
    opengl.uploadBufferData(indexBuffer);

    created = true;
    indexCount = vertexData.getTriangles().length;
}