Simple Texture question

Blitz3D Forums/Blitz3D Beginners Area/Simple Texture question

webhauser(Posted 2009) [#1]
Hi GameMakers!

My aim is to create a 3D ping-pong table, and i want to put some white lines on top it with minimal effort..

My entity is a simple cube (The Table), and my pixel drawing program is "MS Paint".

What picture dimensions and saving format suitable to this situation with Blitz3D using textures on entity? (eg. 128x128 jpg or 16x32 bmp is enough?)

Also i want to create a 3D "Scoreborad" display object. Is it possible to change the texture only one face of a 3D object ?
without using any commercial software ..

Any suggestions are honestly appreciated.


Warner(Posted 2009) [#2]
A texture's width and height have to be a power of two. Saving format can be .bmp or .png, where .png is smaller, and .bmp is uncompressed/lossless.
You could change the texture on one side of the cube by changing the texture coordinates. (UV coords) For that, use the VertexTexCoords command.


fox95871(Posted 2009) [#3]
Pngs are lossless too. In my opinion there's no reason to ever use bmps or jpgs. Bmps are exactly the same quality as pngs but huge, and jpgs, though small, get recompressed down by Blitz making them noticeably bad quality. Pngs by the way are about the same size as jpgs, amazingly.


Warner(Posted 2009) [#4]
Ah, I never knew that. That is amazing indeed.


_PJ_(Posted 2009) [#5]
Also i want to create a 3D "Scoreborad" display object. Is it possible to change the texture only one face of a 3D object ?
without using any commercial software ..


You may find some of the code in the Code Archives dealing with Pixel-Petfect sprites, or 'quads' useful. Since these are flat.


webhauser(Posted 2009) [#6]
Thank you All for the useful info!

Ok, l will use png for my simple texture maps, as they minimal, lossless and free.

Now I want to apply a "top.png" texture only to the top face of the table in my demo. For simplicity i choosed a Cube entity for modeling the table.

What is the right way to accomplish this in Blitz3D ?
I checked the Code Archive but i am not sure how to do this.

;
; This paints all the 6 faces of the Cube -- Not for me
;
table=CreateCube()
tex=LoadTexture("top.png")
EntityTexture table, tex

;
; Maybe this way? But how i get TOPFACE% ???
;
table=CreateCube()
brush=LoadBrush("top.png")
face=GetSurface(cube, TOPFACE%) ; "Table top" ???
PaintSurface face, brush

pls. help and in weeks i can release my first demo that plays Ping-Pong in 3D ;)


Ross C(Posted 2009) [#7]
I wouldn't say bitmaps are completely useless. They are faster to load, as they don't need to be decompressed. Eat up Hard disk space though, if your using alot of them.

I stick to png's and .dds textures myself.


Warner(Posted 2009) [#8]
A mesh can have several materials. Each material is called a brush.
A surface is a collection of triangles.
You can use a brush to paint a surface.
If you create a cube using CreateCube, the cube has only one surface.
If you construct the cube yourself, using CreateMesh/CreateSurface/AddVertex/AddTriangle, you can make one surface that contains the front face of the cube, and another surface that contains the other faces.

In the castle.bb example, a skybox is made. That skybox is a cube, with a different surface for each face/side.
mesh = createmesh() ;create new empty mesh
surf = createsurface(mesh) ;add surface to mesh
v0 = addvertex(surf, -1,  1, 0, 0.0, 0.0) ;upperleft - first three numbers are coords, other two are texture coords.
v1 = addvertex(surf,  1,  1, 0, 1.0, 0.0) ;upperright
v2 = addvertex(surf,  1, -1, 0, 1.0, 1.0) ;lowerright
v3 = addvertex(surf, -1, -1, 0, 0.0, 1.0) ;lowerleft
addtriangle surf, v0, v1, v2 ;add vertices in clockwise order
addtriangle surf, v0, v2, v3

If you want to create a 2nd surface, use
surf2 = createsurface(mesh)

Then, in the addvertex/addtriangle commands, use 'surf2' instead of 'surf'.


webhauser(Posted 2009) [#9]
Thank you Warner, i got it!


fox95871(Posted 2009) [#10]
I wouldn't say bitmaps are completely useless. They are faster to load, as they don't need to be decompressed. Eat up Hard disk space though, if your using alot of them.

Ross, are you saying pngs are compressed? I did some pretty extensive testing of pngs vs bmps once and I always wondered how they could be so small yet identical to bmps, even after a high contrast test which almost always reveals lossiness. But there wasn't any with pngs. Could it be that only the binary is encoded while the actual pixels remain identical? If that's the case, and you say bmps load faster initially compared to pngs because they don't have to decompress, I might just change over to bmps afterall because who cares about drive space nowadays? Load time's more important I think.


_PJ_(Posted 2009) [#11]
PNG's are compressed, if not,m they would be identical in size to an equivalent bitmap.
Though the compression is truly lossless and ideal too because unlike JPG, alpha channels are included, and unlike GIF, the palette (at least any colours actually used) is preserved too.

Details of the filter algorithms can be read here:

http://www.libpng.org/pub/png/spec/1.2/PNG-Filters.html


Adam Novagen(Posted 2009) [#12]
Pngs by the way are about the same size as jpgs, amazingly.


Wrong. A well-compressed JPEG can be less than a third the size of a maximum-compression PNG of the same image.

For Blitz3D though, I agree with everyone here: use PNG every time.

Also, you should take a look at the GIMP, a free multi-OS image editor. It's like Budget Photoshop, and if you get used to it, you'll never use MS Paint again. Cheers!


fox95871(Posted 2009) [#13]
I still use Photoshop 5 LE, I got it free with a scanner years ago. I'm going to do some testing on what I asked about in post 10 if I don't hear back from Ross. If I can get my engine to load a lot faster using bmps instead of pngs, that'd be great. I never would have thought to try that, but if the difference is bmps don't have to decompress first and pngs do, then I guess that would make a difference in load time since I have a million and one interface files that are apparently decompressing every time I start my engine. Or not. We'll see. I'll post the results soon.


Ross C(Posted 2009) [#14]
Sorry man. Yeah, PNG's are compressed, i believe based on colour mainly. I don't to be perfectly honest, think the time difference will be that great. I was being hyper critical. Another point actually, that would probably swing in favour of .PNG's is, because of the smaller file size, they will load quicker from the hard disc.

And since the hard disc transfer is probably the slowest part of the operation, .PNG's should be quicker now i think about it. The time taken to compress vs the time taken to load from the hard disc, is what will really determine the speed.


fox95871(Posted 2009) [#15]
Here are the results!

After restart
230 bmps = 22 seconds
230 pngs = 11 seconds

Consecutive
230 bmps = 8 seconds
230 pngs = 8 seconds

These are averages too, I tested each several times. If someone wants to test pngs vs jpgs now, that'd be good for jpg users. Remember how blitz treats them though:



(This link will be fixed eventually, I'm using a different file host now.)

I posted some more information about this topic at the link below.

http://www.blitzbasic.com/Community/posts.php?topic=92766

Last edited 2010


Ross C(Posted 2009) [#16]
Blitz shouldn't recompress anything when loading. It should de-compress into memory. Is that what you mean? Because i don't see blitz resaving a jpg back to the hard disc.


jfk EO-11110(Posted 2009) [#17]
I wouldn't be amused about that :)
Just for the records: BLit3D supports these texture formats:

bmp jpg, png, pcx, tga, dds

Talking about compression: PNG is indead about the size of zipped BMP, although PNG is officially lossless, I think I experienced some tone-altering behaviour with PNG, kind of darkening, but unlike JPG that really edits the pixels individually (depending on loss level of compression).

DDS rules, since it is even compressed in VRAM, but it also has some rather tricky to handle Mipmapping options that causes bleeding edges sometimes.
DDS (dxt5) rules absolutely for masked textures.

Since many tools however don't support DDS it may be best to use an other format during the design process and then finally patch the meshes to use the DDS version of the texture.