overlapping/combinign textures

Im trying to create weapon screen. i have the base of it. But how do i add the picture of the gun on it? Im using VBO to render the base of it.
THis code draws a rectangle and puts a texture on it. But how do i but additional textures/pictures on this rectangle.
In addition it should display currentammo and the totalammo of the weapon.

public class WeaponDisplay extends HudComponent{
	String texPath = "res/models/hud/HudWep.png";
	public WeaponDisplay(){
		position = new Vector2f(10,10);
		width = 200;
		height = 100;
		
		//Create Vertex Buffer
		vertices = BufferUtils.createFloatBuffer(2 * 4); //(x,y)*(4 vertices on a rectangle)
		vertices.put(new float[]{0,height, width,height, width,0, 0,0});
		vertices.rewind();
		
		//testing texture
		isTextured = true;
		
		if(isTextured){
			texVertices = BufferUtils.createFloatBuffer(2 * 4);
			texVertices.put(new float[]{0,1, 1,1, 1,0, 0,0});
			texVertices.rewind();
		}
	}

	@Override
	public void renderInitStart() {
		if(isTextured){
			Texture tex = Texture.loadTexture(texPath);
			texture = tex.id;
			vboTexVertexID = glGenBuffers();
			
            glBindBuffer(GL_ARRAY_BUFFER, vboTexVertexID);
            glBufferData(GL_ARRAY_BUFFER, texVertices, GL_STATIC_DRAW);
            glBindBuffer(GL_ARRAY_BUFFER, 0);
		}
		
	}

	@Override
	public void renderDraw() {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDrawArrays(GL_QUADS, 0, 4);
		glDisable(GL_BLEND);
		
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub
		
	}

}

so what is not working for you?

My brain. I have no idea how to combine the textures into 1 texture or how to draw a second object onto the first with a different texture in the same VBO.

So … draw the images as seperate sprites on it?

look into texture atlas or spritesheets.
You can only draw vbo with 1 texture. That is just how it works.

But can i combine the textures into 1 texture?

Yes, that’s called a spritesheet or a texture atlas like trollwarrior just said. Its a large texture with all the other textures drawn into it, like this:

I mean something like this

Yes and so do they, have both sprites on the same texture. Then it is only 1 texture, just cut out what you need.

What you wan’t can be done in two ways.

  1. Use a spritesheet! (easy)
  2. Use a pre-combined texture.

The first is easy:
Take all of the textures and stuff them into a single big texture, and also store somewhere (somehow) where your textures in the big texture are located and how much space they take, or in easy words, just store their texture-coordinates (min-X Y, max-X Y).

Then just bind the big texture and access the single textures in the big one using simply their texture-coordinates.
As I said, its easy.

The second one is not so easy:

  1. Take all of your single textures.
  2. Find ALL combinations your textures will have.
  3. Create a new texture for each combination… (This is the part where all the smart people facepalm)
  4. And combine the texture in memory into the new ones.
  5. ???
  6. Draw the whateverything using your ‘combined’ texture.

Do what you wan’t! :slight_smile:

Have a nice day.

  • Longor1996

The first one seems simple enough. Now i need to make my thingi into sub shapes. 1 rectangle into 4 rectangles… but then ther e is the problem that i cant use VBO.

And why can you not use a buffer object?

1 VBO can draw 1 shape. i have 4 shapes now. so i need VBO for each of those. which means i cant draw em with 1 call. So it seems i need VAO, but i dont know how to use VAO-s.

You definitively CAN draw multiple shapes with a single VBO.
Who told you that you can’t draw multiple things with a single VBO?
Even though I am not using VBO’s (and never did), I do know for sure that you can draw as many rectangles as you want with them.

  • Longor1996

Silly me :smiley: i forgot to raise the amount of things to draw in the drawarrays :D.

By the way. A buffer object just holds data, there’s no such thing as rendering a buffer object. There’s also no such thing as a buffer that can only hold one object. A buffer object just holds data, of course you can have multiple “objects” in a buffer.