Tuesday, April 28, 2009

Memorizing SDL

I read an article about the best study method. I want to learn how to use SDL, so I'm going to apply this method now. I'm going to try to recall whatever code I can from lesson 4 and type it here.

#include "SDL/SDL.h" // always need when SDL program
#include "SDL/SDL_Img.h" // need for .png files to display
#include <strings>

//screen attributes

const int scn_h = 640; //screen height
const int scn_w = 480; //screen width
const int scn_bpp = 32; // screen bits per pixel

/* darn, I'm not sure width was 480 (I'll check when I'm completely lost.) */

SDL_Event event; //structure to hold events for us to handle

// function prototypes

SDL_Surface * load_image (std::string); // returns pointer to SDL Surface with a parameter to a string

/*OK. I'm lost. Lazy Foo, defines several other functions before he gets into the main, but I barely remember I'm going to have to re read the whole section. Yes, I know that I said SDL was easy to understand since I pretty much know the C++ invovled but I don't want to be tutorial dependent for every function. I want to know the SDL library so I can do things off the top of my head with it.*/

In our experiments, when students repeatedly read something, it falsely inflates their sense of their own learning."

Saturday, April 18, 2009

C PLUS PLUS NEWB

I wanted to change my blog URL to www.cplusplusnewb.blogspot.com to avoid the negative connotations of the word "noob", but somebody already took that URL. I went to check out what cplusplusnewb is all about; turns out that cplusplusnewb is a very neat blog. I love the way this programmer organized the blog where you can see pictures of the the program in action, download the program, and download the source. The blog style is very clean, simple, and easy to learn from.

The Meaning of Noob

I just discovered that the word "noob" has very negative connotations.

"Contrary to the belief of many, a noob/n00b and a newbie/newb are not the same thing. Newbs are those who are new to some task* and are very beginner at it, possibly a little overconfident about it, but they are willing to learn and fix their errors to move out of that stage. n00bs, on the other hand, know little and have no will to learn any more. They expect people to do the work for them and then expect to get praised about it, and make up a unique species of their own. It is the latter we will study in this guide so that the reader is prepared to encounter them in the wild if needed." -urban dictionary on the definition of noob

I'm not a noob if that's what a noob is. I don't wish to be praised by others' works. I hope to become a great programmer, but I know now that I'm far from being one. I'm still a newbie learning from my programming errors and learning from programmers that I'm a mere fraction of. I think this blog's URL is cplusplusnoob.blogspot.com and I'm not sure there is anything I can do to change this. :(

edit: I managed to change the site name to www.cppnewb.blogspot.com

I wish I could have changed the site name to cplusplusnewb, but that was taken by somebody.

Changed Colors on the C++ Blog

I changed some colors. I'm bored of the white text over a black background I had before.

Friday, April 17, 2009

Pointer to Functions

I've seen pointers point to all the fundamental types and I've seen pointers point to the compound type known as array but I recently learned that pointers can also point to functions. To declare a pointer to a function that returns an integer and has an integer as its parameter you write

(int)(*pt)(int);

Say you have a function called square. The square function returns an integer and has an integer as its parameter.

int square(int x) { return x * x ; }

Now you want to assign the pointer to the function. Note: The address of a function is in the function name, therefore

pt = square; // is valid.

now if you want to call the function through the pointer, all you have to do is

(*pt)(2); // is 4

or simply

pt(2); // is 4 too

The pointer's ability to point to a function is useful when one wants to create a function that has other functions as its parameters. You would not want to create entire copies of the function, rather you'd want to refer to the function, therefore saving space and time.

Monday, April 13, 2009

Learning the Simple DirectMedia Layer (SDL)


I just discovered SDL and some great tutorials at http://lazyfoo.net. I'm on lesson 5 now, but moving quickly through them since I understand most of the C++. Before, I would look at all code referencing functions in a library and have no idea what I was looking at, but now after about a year of studying C++ everything makes sense. I'm already getting a feel of what event driven programming is and how it's implemented by reading through lazy foo's tutorial. I'm somewhat sidetracking at the moment from my goal -- inspired by John Carmack -- to program for my Nokia cell phone. I guess as long as I'm focused on programming, I'm being productive.

Friday, April 3, 2009

Amazing Array Discovery for Scrabble Cheater

Scrabble Cheater Intro.
I don't know if I've mentioned this here before, but I've been working on a scrabble cheater. I know you're probably thinking "aren't there scrabble cheaters on the internet for free?" I've seen some of them myself and they're mediocre. I hope to make one that's fast an organized. I want the user to just be able to enter the characters available and for the program to output all possible words that can be made from in those letters in order of least to greatest word size.
The ArrayAlign Center
Well, I just disocovered a very important aspect of c++. I didn't know this before but you can actually access a string in an array and access a specific character in that string with a 2-dimensional array. Here's some source code to illustrate:
include string
string Array[4] = {"dog", "cat", "house", "iguana"};
cout Array[0][0];

The code above would output the first character in first element in the array of strings (e.i. 'd')

cout Array[1][0];

The code above would output the first character in the second element in the array of strings (e.i. 'c')