Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] creating a mesh with different textures on: 2014-03-17 20:32:06
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   private Mesh createQuad() {
      Mesh quad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3,   "a_position"),
            new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));

      TextureRegion region = new TextureRegion("you spritesheet texture", 0, 0, 128, 128); // Basically this just gets the texture region that you want the side to be ("texture path", xLocation, yLocation, width, height)

      quad.setVertices(new float[] { -1f, -1f, 0, region.getU(), region.getV2(), // bottom left
           1f, -1f, 0, region.getU2(), region.getV2(), // bottom right
           1f, 1f, 0, region.getU2(), region.getV(), // top right
           -1f, 1f, 0, region.getU(), region.getV() }); // top left
     quad.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
      return quad;
   }


Getting the u/v/u2/v2 will give you the texture coordinates of that part of the whole texture. You'll just have to repeat this for every face with different vertex locations & region locations. Basically, you use a spritesheet like this. This way, you don't have to bind different textures, you just use different texture coordinates to locate the image you want.

Sorry for delay in reply, I was in CeBIT and what not, had a birthday etc. Thanks for the answer Longarmx!

Why are you instantiating the TextureRegion inside the createQuad? Couldn't you just pass the same coordinates (here 0, 0, 128, 128) as u/v/u2/v2 ?

I ended up doing this like this:

1  
2  
3  
4  
5  
6  
7  
         TextureRegion region = textureAtlas.findRegion("regionName");

         quad.setVertices(new float[] { -1f, -1f, 0, region.getU(), region.getV2(), // bottom left
              1f, -1f, 0, region.getU2(), region.getV2(), // bottom right
              1f, 1f, 0, region.getU2(), region.getV(), // top right
              -1f, 1f, 0, region.getU(), region.getV() }); // top left
        quad.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });


And I have created the TextureAtlas like in my previous example. This works all very well.

Now, If I need to create all 6 quads, the next question is do I have to pass the Material to ModelBulder each time I create a MeshPart like this:

1  
2  
builder.part("1", createQuad(),   GL10.GL_TRIANGLES, new Material("1", TextureAttribute.createDiffuse(myTexture)));
builder.part("2", createQuad(),   GL10.GL_TRIANGLES, new Material("2", TextureAttribute.createDiffuse(myTexture)));


Here I am passing the same texture possibly 6 times which I find a bit strange.

Cheers, Jaxes
2  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] creating a mesh with different textures on: 2014-03-10 20:10:19
Ok, I don't understand. I admit it.

Relevant parts of my code:
create:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
      textureAtlas = new TextureAtlas(Gdx.files.internal("data/pack.atlas"));
      Texture myTexture = new Texture(Gdx.files.internal("data/treasure.jpg"));
     
      ModelBuilder builder = new ModelBuilder();
      builder.begin();
      builder.part("1", createQuad(),   GL10.GL_TRIANGLES,new Material("1", TextureAttribute.createDiffuse(myTexture)));
      //builder.part("1", createQuad(),   GL10.GL_TRIANGLES,new Material("1", TextureAttribute.createDiffuse(textureAtlas
     //            .findRegion("myRegionName"))));
     quadInstance = new ModelInstance(builder.end(), 0, 0, 0);
      instances.add(quadInstance);


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   private Mesh createQuad() {
      Mesh quad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3,   "a_position"),
            new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));

      quad.setVertices(new float[] { -1f, -1f, 0, 0, 1, // bottom left
           1f, -1f, 0, 1, 1, // bottom right
           1f, 1f, 0, 1, 0, // top right
           -1f, 1f, 0, 0, 0 }); // top left
     quad.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
      return quad;
   }


render:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
   public void render() {
      Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

      camera.update();

      modelBatch.begin(camera);
      modelBatch.render(instances, environment);
      modelBatch.end();
   }


Now, how do I assign the texture from TextureAtlas to the mesh (the out commented part) ? The direct assign from Texture works.

Cheers, Jaxes
3  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] creating a mesh with different textures on: 2014-03-10 19:41:20
You dont need a separate texture for each image. Use one texture with all the images on it. You bind that one texture at the start of rendering. Then, each vertex has position, texture coordinates, color, and normal. The texture coordinates tell what part of the the image to render. Basically, theyre texture regions. Use a texture region to get the texture coordinates for the part of the texture youre trying to render.

Thanks. I am gonna try it now. I am not sure about the binding thing though. I am currently not binding the textures explicitly (at the render), but if OpenGL requires that then it might be done my the framework.

Cheers, Jaxes
4  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] creating a mesh with different textures on: 2014-03-10 13:27:44
Thank you for the answer.

Uhmm.. Start with LWJGL instead of LibGDX. You obviously have no idea what we are talking about.

Maybe you are right, but I got it working already. I did it by using MeshBuilder by adding 6 meshes with 6 textures and created a model. Now I can rotate the modelInstance created from the Model. This works all very well.

This is how rendering works:
- Bind certain texture to opengl
- Point opengl to vertex data: each vertex has position, color, texture coordinate, normal. You can also add custom vertex attributes.
- Tell opengl to rendering everything

This applies in general level how this is achieved. I know how to do this. But my question was specifically LibGDX specific and moreover I was wondering if there's any easier way than using MeshBuilder which to me felt a little bit "clumsy".

If you want to use different textures for 1 mesh, you will need to render mesh in separate parts: render 1st part with texture 1, render 2nd part of the mesh with texture 2, render 3rd part of the mesh with texture 3. That is the only way. If you want to have different textures for 1 mesh, you have to split the mesh into manageable pieces..

Yeah, this is what I have done.

I might be asking too simple question but this is really LibGDX specific and I would like to know if there's a better way to do this in LibGDX than building the mesh with MeshBuilder. Sorry if I am repeating myself or being just a noob but to me it still looks the actual question remains unanswered.

Cheers, Jaxes
5  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] creating a mesh with different textures on: 2014-03-10 11:00:31
You use one texture with the mesh then you use texture coordinates to say what part of the texture you want to be drawn.

Thank you for the answer. Can you elaborate your answer? Or give me guidance where to find documents / tutorial / material regarding how to do this specific task in LibGDX?

I have done this like you say with MeshBuilder but it seems just a little bit tedious and clumsy. It works though which is the best part. Smiley
I might be asking too simple thing but is there easier way for doing this?

Cheers, Jaxes
6  Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] creating a mesh with different textures on: 2014-03-09 21:59:26
You can use something call atlas, texturesheet or spritesheet.
Basically, lets say you have 4 textures of size 256x256. You can put them into single texture the size of 1024x1024 and render certain part of that altas.

Thanks for the answer.

I tried TextureAtlas and I got everything correctly packed with the tool but my problem is that I don't know how to assign the textures to certain parts of the mesh (here cube face). I am not sure if you can assign texture from TextureAtlas because what you get returned is TextureRegion, but I might be wrong.

You might be answering the correct question but I don't understand how using TextureAtlas helps me in setting different Textures for different parts of the Mesh?

I have also looked the attributes of the Model class and there's an materials but but... How does one compose a Model with 6 meshes with 6 different textures?

Now I have actually done it in MeshBuilder but it sure feels clumsy.

Cheers, Jaxes
7  Java Game APIs & Engines / Engines, Libraries and Tools / [LibGDX] creating a mesh with different textures on: 2014-03-09 21:05:37
Hi,

What would be the best way to create a mesh (here a cube) with different textures each side?

I have tried this by creating a textured mesh in Blender. In Blender I have mapped the texture and then exported it to LibGDX. This works, no problem. But I would like to dynamically assign the texture (maybe different ones) to each side. Importing the model is to my understanding static.

As an alternative I have also created a quad (one face) to which I can put a texture. This works too but obviously I am missing 5 sides of the mesh (cube).

1) I probably can create the missing 5 sides (as quads) and have them textured, but is this really the only option?
2) Can I set texture for a mesh parts or faces created by modelBuilder.createBox somehow?
3) Any other or better alternatives for doing this?

Thanks you in advance! I really have tried first to look the net and forum for an answer.

Cheers, Jaxes

WordSlinger- The best word game if developer opinion counts.
https://play.google.com/store/apps/details?id=com.method.wordslinger
8  Game Development / Newbie & Debugging Questions / Re: Simple 2D renderer? on: 2014-03-09 10:59:13
I am not sure what you really need. But if you are building a mock up which is something that doesn't have functionality and since you are mocking a GUI can't you use some drawing tool (offline or web based) to draw the GUI like Gimp or similar? It doesn't at least get any faster what comes to seeing the result, does it?

Cheers, Jaxes
9  Game Development / Newbie & Debugging Questions / Re: [LIBGDX] skinning a cube with multiple textures on: 2014-03-09 09:49:15
Hello Community,

I have this same problem as the OP. Does anyone have an idea how it could be done?

I have tried this by creating a textured mesh in Blender. In Blender I have mapped the texture and then exported it to LibGDX. This works, no problem. But I would like to dynamically assign the texture (maybe different ones) to each side. Importing the model is to my understanding static.

As an alternative I have also created a quad to which I can put a texture. This works too but obviously I am missing 5 sides of the mesh.

1) I probably can create the missing 5 sides (as quads) and have them skinned, but is this really the only option?
2) Can I skin a mesh created by modelBuilder.createBox somehow?
3) Any other or better alternatives for doing this?

Thanks you in advance!

Cheers, Jaxes

WordSlinger- The best word game if developer opinion counts.
https://play.google.com/store/apps/details?id=com.method.wordslinger
10  Games Center / Showcase / Re: Word Slinger, an Android game on: 2014-03-02 19:49:10
Game is now updated.

Version 1.01:

- Added "tap to continue" hints for Game Paused, Game Over and Level Completed states.
- Added version number to menu screen.
- Stars moved in the highscore screen. Scoreloop player name is now truncated.
- Fixed a bug with the speed mode bonus.
- Fixed clipping problem with bonus text.

Hope you enjoy!

Cheers, Jaxes
11  Games Center / Showcase / Re: Word Slinger, an Android game on: 2014-02-27 20:36:26
Hello community,

I would like to hear any comments on my game if anyone have had the time to try it or even look at the screens. I know the game idea isn't new or original but for a learning project I really would appreciate any feedback I can possible get.  Cheesy

Thank you all in advance!

Cheers, Jaxes
12  Games Center / Showcase / Re: [Android] Superior Tactics - Tactical Space Battles RTS on: 2014-02-27 20:31:52
Hi JRenner,

It looks absolutely nice and polished to me. I like the amount of details in this game. There is definitely a lot going on in the game which can cause a little bit confusion. But when you spend a little time with the game it starts to open up.

Excellent job!

Cheers, Jaxes
13  Games Center / Showcase / Re: [Android] Hard Riddle on: 2014-02-27 20:24:52
Hi Ricardo,

Nice game you have created. I just downloaded and tested it. Pack 1 seems to be very hard if you don't have the hints, but like you wrote it's supposed to. I like that. I tried the Pack 2 and got three or four riddles forward. I will definitely try it later too. I like the clean and nice design and graphics.

Few comments:
- I understand the ads, but once the ad shows up it pushes the rest of the screen down which can be annoying when trying to press something. Maybe you could adjust your code so that the space is already "reserved" so when you just show the ad the rest of the screen stays as is?
- Now my screen gets turned off while thinking the riddle. Maybe this is conscious decision but I would consider adding: WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON so the screen will not go off.

What comes to possibilities to make some bucks with the game: I agree what Genius Coder already said it could be possible to make riddle packs and put a small fee on them.

Keep up the good work!

Cheers, Jaxes
14  Games Center / Showcase / Word Slinger, an Android game on: 2014-02-10 09:03:57
Hello everyone!

I am a wanna be indie game developer from Finland. I finally released my first mobile game ever. It's more a learning project than a serious attempt but I hope you find it nice and entertaining. All comments, feedback and criticism is highly appreciated!

You can download it from Google Play Store at https://play.google.com/store/apps/details?id=com.method.wordslinger

Play screen:


Features:
- 2 play modes, normal and speed (against time)
- local and global high scores
- addictive bonuses
- 4 different difficulties
- in game hint system (and IAP via Play)
- instructions and help
- dictionary of over 100 000 words
- supports different screensizes

Cheers, Jaxes
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (62 views)
2014-04-15 18:08:23

BurntPizza (60 views)
2014-04-15 03:46:01

UprightPath (73 views)
2014-04-14 17:39:50

UprightPath (56 views)
2014-04-14 17:35:47

Porlus (73 views)
2014-04-14 15:48:38

tom_mai78101 (99 views)
2014-04-10 04:04:31

BurntPizza (159 views)
2014-04-08 23:06:04

tom_mai78101 (254 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!