When learning a new computer language I usually start by implementing some simple problems. This method helps me get comfortable with the language progressively and quickly.
This is a learn by doing method. So you'll have to get your hands dirty. It's easy to find the code for the problems in the web, but that won't make you a better programmer. You'll have to put your neurons to works and read the language documentation and make a lot of mistakes so you don't repeat them in the future.
The first of this problems is know by all computer developers (I hope).
HelloWorld - compiler/interpreter, documentation - This problem won't make you proficient in the language, but after you finish it you will have a development environment and know how to create a program, compile and execute it. Additionally you will know where to find the language documentation.
PrimeNumer - syntax, loops, maths, logic - The big objective of this problem is to make you aware of the syntax of the language. After solving this problem you will be able to read most of the code written in this language.
QuickSort - more syntax, recursion, lists/arrays - This problem introduces you to richer data types of the language and by now the syntax should be very familiar.
HuffmanTree - stream reading/writing, types/classes - You learn how to think in the language. The language paradigms should be clear now. You are ready to start to solve real-world problems.
The next step is to get connected with the language community and use what you learn in the best way you can.
Sometimes you may find out that the language you just learn is not your cup of tee. But you probably discover something in that language that you can use to improve your programming skill in your language of choice.
My learning method is more oriented to general propose languages like Java, C/C++, Haskell, Python, Ruby, etc...
But I think this method can be successfully used in languages with a more specific scope like JavaScript, Erlang, PHP, Lua, Prolog, Bash and others. Most of these languages can be as generalist as the ones in the first group.
2010-03-31
2010-03-25
Drawing with openGL on Cocos2d-iphone
After a long search in the web, forums, IRC chats and several hours of trial and error... I finally can make some openGL drawing inside cocos2d-iphone objects.
I'm using the version 0.99.1 of cocos2d-iphone.
In the beginning the code was breaking in the call to
To save some time to the ones that were having the same problem here goes my solution.
I created a very simple class that draws colored line.
The class declaration is minimal:
It just has to subclass the CCNode class from cocos2d-iphone.
For the implementation I just had to overload the
The important parts are that you have to disable
I found out in a forum that having
Then I was using just vertex arrays with a call to
This class is very simple to change so that you can specify the star and end point of the line and the color when you initialize the object.
I hope this will save you some hours of work.
I'm using the version 0.99.1 of cocos2d-iphone.
In the beginning the code was breaking in the call to
glDrawArrays() with a EXC_BAD_ACCESS exception. Then I was able to draw a line but there was no color.To save some time to the ones that were having the same problem here goes my solution.
I created a very simple class that draws colored line.
The class declaration is minimal:
@interface Line : CCNode
{
}
@end
It just has to subclass the CCNode class from cocos2d-iphone.
For the implementation I just had to overload the
draw() method.
@implementation Line
-(void) draw
{
static const GLfloat vertices[] =
{
0.0, 0.0,
250.0, 280.0
};
static const GLubyte squareColors[] = {
255, 0, 0, 255,
0, 0, 255, 255
};
glDisable(GL_TEXTURE_2D);
BOOL colorArrayEnabled = glIsEnabled(GL_COLOR_ARRAY);
if (!colorArrayEnabled) {
glEnableClientState(GL_COLOR_ARRAY);
}
BOOL vertexArrayEnabled = glIsEnabled(GL_VERTEX_ARRAY);
if (!vertexArrayEnabled) {
glEnableClientState(GL_VERTEX_ARRAY);
}
glLineWidth(2.0f);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_LINES, 0, 2);
if (!vertexArrayEnabled) {
glDisableClientState(GL_VERTEX_ARRAY);
}
if (!colorArrayEnabled) {
glDisableClientState(GL_COLOR_ARRAY);
}
glEnable(GL_TEXTURE_2D);
}
@end
The important parts are that you have to disable
GL_TEXTURE_2D and you need to use both color and vertex arrays to do the drawing.I found out in a forum that having
GL_TEXTURE_2D enabled won't allow you to make any drawing with openGL primitives.Then I was using just vertex arrays with a call to
glColor4f(), but this result in a line with no color.This class is very simple to change so that you can specify the star and end point of the line and the color when you initialize the object.
I hope this will save you some hours of work.
Labels:
cocos2d,
iphone,
Objective-C,
OpenGL,
OpenGLES,
programming
2010-03-18
Pimping my Xcode (disable anti-aliasing)
Reading text from a screen several hours a day can be very tiring for one eyes. But there is one setting that can make it easier for your eyes. That is font anti-aliasing. It should be disabled.
The anti-aliasing makes the text look prettier but less sharper and consequently it becomes harder to read.
Several text editor for programmers (jedit, bbedit, ...) already have an option to enable/disable text anti-aliasing. Unfortunately Xcode doesn't have a simple way to disable this. You will have to go to the console and type:
Now every font under 18 size will not be anti-aliased. But there is another catch. The default font Menlo will look blurry in any size. I chose to use the Andale Mono with a size of 12.
Hope that this help you keep your eyes save.
The anti-aliasing makes the text look prettier but less sharper and consequently it becomes harder to read.
Several text editor for programmers (jedit, bbedit, ...) already have an option to enable/disable text anti-aliasing. Unfortunately Xcode doesn't have a simple way to disable this. You will have to go to the console and type:
defaults write com.apple.xcode AppleAntiAliasingThreshold 18
Now every font under 18 size will not be anti-aliased. But there is another catch. The default font Menlo will look blurry in any size. I chose to use the Andale Mono with a size of 12.
Hope that this help you keep your eyes save.
2009-12-21
XCode, macports and SDL ... what a hell
After long searches on the web, mailing lists, forums and wikis, I finally got xcode 3.2 compiling/linking my application that uses libsdl.
Using the macports libsdl won't work. Trying to make it work was my big mistake. I was getting compiler errors and linker undefined symbols like "_SDL_PushEvent" and others similar.
The solution was to download all the latest dmg files from http://www.libsdl.org and don't forget the SDL-devel-1.2.14-extras.dmg with the xcode project templates.
Copy all the frameworks (SDL, SDL_Image, SDL_Mixer ...) to "/Library/Frameworks" install the templates that come with the SDL-devel-1.2.14-extras.dmg and now you can launch Xcode and chose a SDL template. Should compile and link successfully.
Using the macports libsdl won't work. Trying to make it work was my big mistake. I was getting compiler errors and linker undefined symbols like "_SDL_PushEvent" and others similar.
The solution was to download all the latest dmg files from http://www.libsdl.org and don't forget the SDL-devel-1.2.14-extras.dmg with the xcode project templates.
Copy all the frameworks (SDL, SDL_Image, SDL_Mixer ...) to "/Library/Frameworks" install the templates that come with the SDL-devel-1.2.14-extras.dmg and now you can launch Xcode and chose a SDL template. Should compile and link successfully.
2009-10-08
Why Windows OS annoys me...
I was reading news were a windows system went down contaminated by a virus and was promptly replaced by a linux system. Thinking that someone has changed from windows to another operating system made me feel good.
But why did I feel good about it? Windows 3.1 gave GUI to the masses. Windows XP was a nice OS. Most computer games that I loved to play were running on windows. So where did this windows rejection come from?
I realize now that my repulsing instinct to windows OS is caused by my non-technical friends. As a computer guy all my friends tend to call me when their computer fail and they all use windows. The main cause for the windows miss behavior was usually a virus or other malware.
This leads me to the conclude that the main weak point of the Microsoft OS is it being the main target of malware industry and the non-tech users that tend to annoy their tech-friend.
But why did I feel good about it? Windows 3.1 gave GUI to the masses. Windows XP was a nice OS. Most computer games that I loved to play were running on windows. So where did this windows rejection come from?
I realize now that my repulsing instinct to windows OS is caused by my non-technical friends. As a computer guy all my friends tend to call me when their computer fail and they all use windows. The main cause for the windows miss behavior was usually a virus or other malware.
This leads me to the conclude that the main weak point of the Microsoft OS is it being the main target of malware industry and the non-tech users that tend to annoy their tech-friend.
2009-07-27
How to hot-code-swap with erlang
One of the most famous features of erlang is hot code swap.
What we'll do is open a shell into the running process and then load the new code.
Simple!?
What we'll do is open a shell into the running process and then load the new code.
- The application must have been launched with -name app_name flag
- Compile your code
- Launch an erlang shell with:
> erl -name name_of_this_shell -remsh name_of_remote_process@remote_process_host - Load the new module with:
> l(module_name).
Simple!?
2009-07-23
How I fell in love with computers and programming
When I was a little boy I wanted to know how my toys worked, how can you make music from instruments or even how was it possible to animate drawings. And I spent long hours disassemble and trying to reassemble every thing that I could reach, drawing what I saw and making music with my toys.
One day I had a revelation - my uncle showed me his zx-spectrum. It was like a all-in-one thing. The possibilities were infinite. I thought that "It's amazing. I just have to tell it what to do and he'll do it for me!". Since then I've been happily making programs, music and graphics with computers.
Subscribe to:
Posts (Atom)