Blog do Eduardo Costa Meu blog pessoal


Cube optimization

I'm doing some tests with OpenGL and cubes. I found some impressive numbers and I want to share them.

If you really know OpenGL, you are aware that glVertex with GL_TRIANGLES stinks. It's the simplest way, but is also the worst way. Using Vertex Buffer ObjectsglDrawElements and GL_TRIANGLE_STRIP is always a better idea.

Let's go to the numbers. In a cube, we have 6 faces, right? Each face has two triangles with three vertices each. This is 36 (6x3x2) points. For each point, we have 3 coordinates (X, Y, Z), plus a extra one for shaders (W) , and two more for texturing (U, V). Using floats, we have 6 of them with 4 bytes, this is 24 bytes per "point". This means the cube has 864 bytes (36x24).

How to improve? First, we will change the floats with shorts for XYZW. This will lead to 16 bytes (4 shorts of 2 bytes plus 2 floats of 4 bytes). This reduces the cube to 574 bytes (36x24). Better, but not good, yet.

With triangle strips, we reduce the vertice count. The texture I need for the cube allows me to make a "strip" for the sides, one for the top and one for the bottom. I managed to describe my cube using only 22 points. Now, my cube has 352 bytes (16x22). Way better, but we have the final trick!

VBOs: these 22 points have only 15 unique occurrences. This means we have 240 bytes (16x15), plus 22 shorts for indexes. Total: 284 bytes (44+240)!

This means we have a 68% of memory optimization!


Converting YouTube’s FLC into iMovie’s MP4

If you try to google this, you will surely regret: lots of plugins, sharewares, malwares...But the solution can be much more simple.

First we need to download YouTube's videos. We can use one of many Firefox plugins, or use an evil Safari trick. Open the video you want, then go to "Window > Activity", look for a file greater than 1MB, select it, Cmd-C, go to "Window > Downloads", and Cmd-V. Simple as that! Now you have a FLV.

If you want to play it only, you can install Perian, a nice QuickTime plugin with a lot of useful AV codecs. It will allow opening various files (including FLC) in your QT and fellows (like iDVD). But you will not open it with iMovie (since it needs to edit files, too).

Let's use a nice multiplatform trick that will work on Mac, Windows and Linux: install VLC. You can use it to play the FLC or you can go to "File > Stream/Transcoding Wizard > Transcode/Save to file", select the FLC, unmark both "transcode" (if you installed Perian), select destination, and we are done. Without transcoding, it will only copy the streams, making it a really fast operation.

The result is an MP4 that can be used on every Apple software. I guess this includes iPod/iPhone, but I didn't test this theory.

Filed under: geek No Comments

First Minecraft post

I'm getting good playing Minecraft. Sometimes I still die like a newbie, but my projects are getting larger and complex. It's a nice, relaxing hobby. To help other newbies, I'll publish some tips ovver here. First one is the most basic one: how to survive your first night.

I won't reinvent wheel. There's a nice YouTube video from paulsoaresjr:

If you can't watch it, let's start by telling you how things work on Minecraft. In this blocky world, you need to craft some basic tools and build a shelter before the blocky sun goes away and evil night monsters appears to kill you.

Your first task is to find wood. Go close to a tree, aim for the wood, left click on it and hold until the block "breaks" and a small wood block falls on the ground. Grab it and do the same with another couple of blocks.

I recommend you to start collecting all of one tree at once. If you take it all, leaves will start vanishing and saplings will eventually fall. Grab them, select (probably using "2" key), and right click on grass (green block) or dirt (brown). There! You planted a tree! If you always make like this, you will have a virtually infinite wood supply in the future.

Open your inventory ("E" key). This screen has your blocky hero, his armor slots on the left, the 2x2 crafting space on the right, your inventory in the middle and fast access inventory on bottom. Each fast access slot is associated to a number key (first for "1", second "2", and so on).

Left click on the wood and again on the craft space. Wooden planks will appear. Left click on planks (one time for each wood you have) and then on your inventory. You made your first crafting!

Left click on the planks and right click on each of the squares of crafting area. It will put one plank at a time and make a crafting table. This is one of most important tool of this game! Put it on your fast access and exit the inventory ("Esc"). Now, type the associated key to put the table in your hand and right click any empty space. It installs your table and, if you right click it, your inventory appears with a larger (3x3) crafting area.

Now, put one plank on the top of the other. This gives you "sticks". Make the same with sticks and put three planks in the top row, making something that resembles a "T". Now you have an wooden pickaxe. That's something you will never see on real world.

Exit your inventory, left click the crafting table and hold until it "breaks" into a smaller block that you will carry with you. Time for some exploration. Find some gray blocks (those are "stone blocks"). Go there and look for some gray blocks with black spots. Those are coal ores. Break some of them and collect the coal. Do not enter any natural cave. They are huge and can have monsters inside.

Now, go back to where you spawn and let's make a cave house. You can use an open area and build walls and ceiling (not recommended for your first home) or dig a hole in a mountain. Go to a mountain side and dig at least a 4x4x2 hole. Using the material you got from this hole, close the entrance. You can leave a small 1x1x1 hole to act as an "window". If you make it larger, spiders will get in. If you make it taller, other monsters will invade. And they really do. BTW, do not stay close to that "window" - a "Creeper" may pass by and explode you and your wall off.

Now, let's make some torches. In your craft area, put a coal at the top of a stick. This gives you four torches. Put them in your fast access area, activate them with corresponding key and right click in the wall or on the floor. Now you have some lights.

That's it! You have a small, somehow protected, shelter. You can enjoy the evening expanding your house or using your crafting table to make other cool stuff:

Using six planks (2x3), you can make a door. Put it on the ground to allow easy access to your house. And monsters does not know how to open it!

Using eight cobblestones (break stone blocks to get some), filling all the 3x3 area, except the middle spot, you can make a furnace. You use it like the crafting table: put it on the ground and right click on it. The lower spot is fuel. The upper one is whatever you want to smelt. As fuel, you can use coal or wood. Coal last longer, but you may need it for torches.

You can smelt sand into glass. This can be used as real windows (now you can have larger windows). Looks more like a real house, no?

Now, you are on your own. You can make a better house, explore that huge world or anything you like. By the way, the proportions of the map are the same of Earth: if you walk nonstop to the north, it will take 30 realworld years to reach the edge. That's a lot of space to explore!

Filed under: minecraft 2 Comments

Multilingual WordPress Plugin

After years publishing on this blog, I finally took the chances installing a multilingual plugin. Now, my blog can go beyond my native language, reaching more people on other English-speaking countries, too.