Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  overlapping/combinign textures  (Read 1077 times)
0 Members and 1 Guest are viewing this topic.
Offline vastrolorde

Junior Member





« Posted 2014-03-12 19:05:21 »

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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
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
     
   }

}
Offline trollwarrior1
« Reply #1 - Posted 2014-03-12 19:23:39 »

so what is not working for you?
Offline vastrolorde

Junior Member





« Reply #2 - Posted 2014-03-12 19:43:19 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Drenius
« Reply #3 - Posted 2014-03-12 19:45:58 »

So ... draw the images as seperate sprites on it?
Offline trollwarrior1
« Reply #4 - Posted 2014-03-12 19:55:00 »

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

Junior Member





« Reply #5 - Posted 2014-03-16 14:57:01 »

But can i combine the textures into 1 texture?
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2014-03-16 16:46:45 »

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:

Offline vastrolorde

Junior Member





« Reply #7 - Posted 2014-03-17 07:30:49 »

I mean something like this
Offline Gibbo3771
« Reply #8 - Posted 2014-03-17 08:57:47 »

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.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Longor1996
« Reply #9 - Posted 2014-03-17 14:32:40 »

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. Huh
6. Draw the whateverything using your 'combined' texture.

Do what you wan't! Smiley

Have a nice day.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vastrolorde

Junior Member





« Reply #10 - Posted 2014-03-18 19:07:11 »

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.
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #11 - Posted 2014-03-18 19:08:30 »

And why can you not use a buffer object?

Offline vastrolorde

Junior Member





« Reply #12 - Posted 2014-03-18 19:10:54 »

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.
Offline Longor1996
« Reply #13 - Posted 2014-03-18 19:13:53 »

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

Sorry for my bad English! That's because i am from Germany.
Offline vastrolorde

Junior Member





« Reply #14 - Posted 2014-03-18 19:19:30 »

Silly me Cheesy i forgot to raise the amount of things to draw in the drawarrays Cheesy.
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #15 - Posted 2014-03-18 19:50:34 »

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.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (55 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!