Scrabble tiles in JPCT

Started by Muhammad, October 23, 2014, 05:39:23 PM

Previous topic - Next topic

Muhammad

Hi there,

First of all I would like to thank the makers/maintainers of JPCT. There are more powerful engines out there but JPCT seems simple and elegant, and perfect for beginners like me.

I am trying to make a scrabble like game using JPCT, and learning game programming at the same time. I have managed to make a tile in blender, export as .3ds and render in android. Currently its only showing a big black tile but that's probably because its so easy to mess up naming textures, materials in blender and for it not to match up.

My question is, as you know in scrabble you have A-Z, so I need many tiles, I was thinking:

1. Make 1 tile
2. Make many textures with 'A', 'B' etc.
3. Apply the required texture in android when I need a certain tile.

However, to apply textures properly I need get it right in blender, which pretty much binds the model to a certain file, ie. A.png ... so when I need to replace it with texture B.png in my app will it texture correctly?

Maybe an alternative approach would be to make 1 massive texture with all tiles, and somehow set the coordinates on the fly in android. The worst approach seems to make a tile model for every letter, and also a texture for every letter.

Can you please let me know how I can approach this problem in JPCT?

Thanks.

Darai

Don't worry,

it will work, just use the setTexture method of the Object3D object (Or any other retexturing method).

Darai

Go ahead, try it out, it is not that hard experiment.

Muhammad

Thanks Darai for the response, I will try when I get home today.

EgonOlsen

Another option would be to merge all letters into one texture, map the tile so that that upper left letter is visible only and then use a different texture matrix (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setTextureMatrix(com.threed.jpct.Matrix)) on different tiles to move the desired letter into view.

Muhammad

#5
Thanks for the reply. I am currently struggling with even loading my .3ds model. Before it loaded fine when:

1. I made a tile object in blender
2. I set its dimensions, applied a default material and then just applied my texture (picture of a K with beige bkg) on top.
3. Exported to .3ds

Then I tried to be more clever :

1. I made a tile object in blender
2. I set its dimensions, applied a default material [and set its color to beige] then just applied my texture (picture of a K [with transparent bkg]) on top.
3. Exported to .3ds

Now the whole tile is black in jpct, and I have retried many times, trying to get the right names etc but it does not affect it. I am not on my home pc otherwise I would have posted logs. But I recall nothing seemed odd in the logs, and the name I set for my texture was matched up.

As for the second issue, it would be great if I did not even have to set a texture in the blender model, and I could set the map in code, it would make it much easier. Could you point me to an example of what the matrix coordinates may look like?

Also can I also get away with not setting a material in blender and setting that in code also? It would be nice to make it shiny like plastic. If you can point me to examples that should be sufficient, I am a beginner in all things game related, but I have been programming for a long time.


EgonOlsen

If it's black, you have no texture assigned (assuming that your scene isn't 100% dark), which means that the names don't match. You should find a log message about the loader creating a new texture with the proper name. But anyway, in your case, you don't have to rely on the names. Just assign the texture with setTexture() after loading your model. The names-way of doing things mainly exist to support models that are using multiple textures. Yours don't, so you don't have to do it that way.
About the materials in any 3d editor: jPCT-AE doesn't care much about them. It loads texture(-names), transparency and diffuse color, but that's it. If you want a plastic effect, you have to write a shader for this. jPCT-AE doesn't come with a built-in plastic look. But i would postpone that and take care of the basics first.

The texture matrix thing works like this: You create a texture that contains all letters in a grid based fashion, i.e. if each letter is 32*32, a 512*512 texture can contain 256 letters/elements. You then map your model so that it only uses the first 32*32 part of the texture. Then you create a texture matrix and assign it. By translating this matrix, you can make different parts of the texture appear. Texture coordinates are normalized, so in this example, a x-translation of (1/16) will move the texture on the tile to the next letter in x-direction, 2/16 to the next etc... The same applies to the y-direction.