Chapter 1
1. Basics
1.1 Using RHIDE to write our first C++ program
First, you should create a new directory for this tutorial. When you have done so, start RHIDE from within it. The RHIDE startup screen should appear if it was installed properly.
첫째, 너는 튜토리얼을 위해서 디렉토리를 하나 만들어야 한다. 다 했으면, 해당 디렉토리에서 RHIDE(터보C IDE같이 생겼음)을 실행해야 한다. RHIDE가 제대로 설치되어 있다면 화면이 뜰거다.
At the top, there are some menus. We want to create a new project for our game. Hit Alt-P to open the Project menu. Choose "Open project". Give your new project a name, e.g. tutorial. Set up your environment according to your preferences in the Options menu (Alt-O), if you wish (e.g. I prefer 80x50 screen mode). Be sure to check -Wall in the Warnings box in the Compilers menu, as this will enable many helpful warnings. Beginners and experts alike will benefit from having the compiler spot a lot of potential bugs this way.
상단에 몇개의 메뉴가 있을거야. 우리는 우리 게임을 만들기 위해서 새로운 프로젝트를 생성해야 한다. 알트-P 를 눌러서 프로젝트 메뉴를 열자. "Open Project" 를 선택해라. 새 프로젝트 이름을 주고, 예) tutorial, 필요하다면 옵션 메뉴(알트-O)를 열어서 환경을 적당히 설정해 주도록 하자. (본인의 경우 80x50 사이즈의 스크린 모드를 설정했다.) 컴파일러 메뉴에서 경고 박스에 -Wall 이라고 설정해 주자. 이것은 도움이 될만한 모든 경고를 출력해준다. 전문가나 초심자나 경고 옵션을 통해서 잠재적인 버그를 발견할 수 있을것이다.
It is now time to write your first C++ program to check that the compiler actually works. In the Project menu, select Add item. In the dialog box that pops up, type tut1.cc and hit Enter. The name will appear in the Project Window at the bottom of the screen. Hit Esc to return. Then hit Enter again to select this project entry. Since the file does already not exist, an empty window should now pop up. In it, type:
자 이제 코드를 작성할 시간이다. 프로젝트 메뉴에서 Add 를 선택하자. 다이얼로그 박스가 뜨면, tut1.cc 라고 입력하고 엔터를 치자. 프로젝트 윈도우에 앞서 입력한 (파일)이름이 나타날것이다. 원래 화면으로 돌아가기 위해서 Esc를 입력하자. 프로젝트 엔트리에서 파일을 선택한다음 엔터를 입력하자. 만약 파일에 아무것도 입력된 것이 없다면 빈 화면(윈도우)만 보일것이다. 아래와 같이 입력하자.
#include <iostream.h>
int main()
{
cout << "Hello world." << endl;
return 0;
}
This is the classical first C++ program, it does not do anything particularly useful, but we want to make sure the compiler works. Hit F9 to make it. If there are no error messages, DJGPP is properly set up. If there are problems, re-read README.1ST that accompanies the DJGPP distribution. To run our first program, hit Ctrl-F9. The screen will flash briefly while the program does its deed. If you want to see what it did, now hit Alt-F5 to view the User Screen.
이것은 아주아주 전형적인 C+ 프로그램이다. 이것은 쓸모있는 일은 전혀 하지 않는다, 다만 컴파일러가 정상적으로 동작하는지 확인해 볼 수 있을뿐이다. F9를 누르면 컴파일 된다. 만약 에러가 출력되지 않는다면, 컴파일러가 정상적으로 동작한다는 이야기다. 만약 에러가 나왔다면, 컴파일러를 설치하자. (DJGPP 라는 검색어로 구글에서 검색해라.) 우리가 만든 프로그램을 동작시키려면 컨트롤-F9를 누르자. 화면이 잠깐 번쩍일것이다. 그게 실행된거다. 너무 빨라서 뭐가 뭔지 모르겠다면 알트-F5를 눌러라. 실행 모습이 별도의 유저 스트린을 통해서 보일것이다. (라고 번역은 되는데, RHIDE로 테스트 해보지 않아서 번역한 내용과 틀릴수 있음.)
The curious reader will note that the .EXE file that our exercise has produced is very large (almost 200K). This is normal and nothing to worry about, you should remember that DJGPP is a feature-rich 32-bit protected-mode compiler. The DJGPP startup and library code detects and starts up a DPMI host, enters protected mode, takes care of a lot of memory management, reads, parses, and expands command-line arguments, loads environment variables, sets up protected-mode exception handlers, and so on. Of course, all this is wasted on a program that just prints a few characters and exits. If you really are concerned about executable size, consult the DJGPP FAQ about how to reduce its size, but once we write bigger programs this overhead will soon be negligible anyway.
호기심 많은 독자는 .exe 파일이 하는 일에 비해 너무 큰 사이즈(200k 가까이)가 아닌가 하는 의문이 생길수도 있을것이다. 걱정하지 마라. 정상이다. 다만, 이걸 기억해라. 우리가 사용하는 컴파일러(DJGPP)는 32bit 보호모드 컴파일러다. 이 컴파일러는 필요한 라이브러리 코드를 검색하고 DPMI 호스트(...???)를 시작하고, 보호 모드로 진입한다. 메모리도 관리해야 하고 커맨드라인 매개변수를 읽고 분석하기도 하고 환경변수도 로드해야 하고 보호모드 예외핸들러도 설정한다 그리고도 또 뭔가 뭔가 많이 한다. 물론 이 모든것이 단순히 글자 몇개 찍는 프로그램에서는 걍 쓰잘데기 없는것이긴 하다. 만약 내가 이렇게 적어뒀는데도 '하는짓도 없는데 용량만 더럽게 먹네'라고 생각이 든다면 구글을 통해서 `컴파일시 용량 줄이기`에 관련된 내용을 검색해 봐라. 하지만, 다시 말하건데 진짜 큰 프로그램을 만들다 보면 이따위 소소한 오버헤드따위는 신경 안쓰게 될거다.
1.2 Introducing Allegro
I will not waste too much time introducing the theory behind C++, for this the reader may want to consult a dedicated C++ tutorial for more information, and I assume the reader to be at least vaguely familiar with C syntax. I will explain what else we need to know once we need it. And what we need to know right now, is how to start using Allegro. Most concepts concerning the use of Allegro is covered in its own examples, you may want to take a look at them also.
나는 C+ 이론 따위에 집착하고 싶지 않다. C+에관해 더 많이 알고 싶다면 관련된 책을 뒤벼봐라. 나는 기본적으로 이 글을 읽는 사람들이 C 문법정도는 알고 있을거라고 생각하고 이야기를 진행하겠다. 나는 우리가 필요한 것만 언급하겠다. 그리고 지금 현재 우리가 알아야 할것은 알레그로를 어떻게 시작해야 하느냐 하는것이다. 대부분의 알레그로 사용법에 관련된것은 예제로 보여주겠다. 예제만 잘 봐도 된다는 말이다. : )
So, in our tut1.cc, we add some code, to make it look like this:
앞서 작성한 코드에 약간의 코드를 추가해서 다음과 같은 코드를 만들어 보자.
#include <iostream.h>
#include <allegro.h>
int main()
{
allegro_init();
cout << "Ready. Beep." << endl;
return 0;
}
Since we are now using the Allegro library, the linker is going to complain if we compile this right away. In the Options menu, choose Libraries. Type alleg there and check the box beside it. Our program will now link with Allegro if Allegro was properly installed. If it doesn't, read the Allegro FAQ. If run, this program will obviously say "Ready. Beep." instead of "Hello world.", but otherwise not do very much interesting.
만약 우리가 위 코드를 가지고 컴파일을 하면 컴파일러가 관련 라이브러리를 찾을수 없다는 불평을 내 뱉을 것이다. 옵션 메뉴로 가서 라이브러리를 선택하자. alleg를 입력하고 옆에 있는 체크박스에 체크하자. 자, 이제 알레그로 라이브러리가 설치되어 있다면 컴파일시 별 에러 없이 컴파일 될 것이다. 응? 그래도 에러가 난다고? Allegro FAQ 를 구글에서 검색 키워드로 넣어서 어떤 문제인지 확인해 보자. (왠만한 문제는 대체로 해결 될 것이다.) 정상적으로 컴파일이 되었다면 실행해 보자.(앞 서브 챕터에서 컴파일, 런 에 관련해서 다뤘었다.) Ready. Beep. 라는 문자열이 출력되는 것이 보이는가? 정상이다. 근데, 앞서 했던것과 별다를것이 없다. 별로 재미없다. (- _-)
1.3 Using Allegro
We will now add even more code to our little introductory program, and this time use Allegro for the output.
알레그로를 사용해서 출력하도록 앞서 코드에 초큼 더 변경을 가해보겠다.
#include <allegro.h>
int main()
{
allegro_init();
install_keyboard();
set_gfx_mode(GFX_VGA,320,200,0,0);
textout_centre(screen,font,"Ready. Beep.",160,100,255);
readkey();
return 0;
}
Hit Ctrl-F9 to run it. This program does not use the C++ iostream routines to output its text, so we have removed any references to it. Instead, it enters graphics mode, writes "Ready. Beep." at the center of the screen, and waits for you to press a key before it exits. For more details about the functions used here, refer to the Allegro documentation.
컨트롤-F9를 눌러서 실행해 보자. 이 프로그램은 문자열 출력에 C+ iostream 루틴을 사용하지 않는다. 따라서 우리는 #include <iostream> 라인및 iostream 관련 루틴을 뺴버렸다. 대신에 그래픽 모드를 변경하고 Ready. Beep. 를 화면의 중간에 출력하도록 변경해서 키 입력이 발생하면 종료하도록 수정했다. 사용된 함수들에 대해 좀더 자세히 알고 싶다면 알레그로 문서를 참조하자.
Exit RHIDE and proceed to the next chapter
그럼... 다음시간에 다시봐용 : )
1. Basics
1.1 Using RHIDE to write our first C++ program
First, you should create a new directory for this tutorial. When you have done so, start RHIDE from within it. The RHIDE startup screen should appear if it was installed properly.
첫째, 너는 튜토리얼을 위해서 디렉토리를 하나 만들어야 한다. 다 했으면, 해당 디렉토리에서 RHIDE(터보C IDE같이 생겼음)을 실행해야 한다. RHIDE가 제대로 설치되어 있다면 화면이 뜰거다.
At the top, there are some menus. We want to create a new project for our game. Hit Alt-P to open the Project menu. Choose "Open project". Give your new project a name, e.g. tutorial. Set up your environment according to your preferences in the Options menu (Alt-O), if you wish (e.g. I prefer 80x50 screen mode). Be sure to check -Wall in the Warnings box in the Compilers menu, as this will enable many helpful warnings. Beginners and experts alike will benefit from having the compiler spot a lot of potential bugs this way.
상단에 몇개의 메뉴가 있을거야. 우리는 우리 게임을 만들기 위해서 새로운 프로젝트를 생성해야 한다. 알트-P 를 눌러서 프로젝트 메뉴를 열자. "Open Project" 를 선택해라. 새 프로젝트 이름을 주고, 예) tutorial, 필요하다면 옵션 메뉴(알트-O)를 열어서 환경을 적당히 설정해 주도록 하자. (본인의 경우 80x50 사이즈의 스크린 모드를 설정했다.) 컴파일러 메뉴에서 경고 박스에 -Wall 이라고 설정해 주자. 이것은 도움이 될만한 모든 경고를 출력해준다. 전문가나 초심자나 경고 옵션을 통해서 잠재적인 버그를 발견할 수 있을것이다.
It is now time to write your first C++ program to check that the compiler actually works. In the Project menu, select Add item. In the dialog box that pops up, type tut1.cc and hit Enter. The name will appear in the Project Window at the bottom of the screen. Hit Esc to return. Then hit Enter again to select this project entry. Since the file does already not exist, an empty window should now pop up. In it, type:
자 이제 코드를 작성할 시간이다. 프로젝트 메뉴에서 Add 를 선택하자. 다이얼로그 박스가 뜨면, tut1.cc 라고 입력하고 엔터를 치자. 프로젝트 윈도우에 앞서 입력한 (파일)이름이 나타날것이다. 원래 화면으로 돌아가기 위해서 Esc를 입력하자. 프로젝트 엔트리에서 파일을 선택한다음 엔터를 입력하자. 만약 파일에 아무것도 입력된 것이 없다면 빈 화면(윈도우)만 보일것이다. 아래와 같이 입력하자.
#include <iostream.h>
int main()
{
cout << "Hello world." << endl;
return 0;
}
This is the classical first C++ program, it does not do anything particularly useful, but we want to make sure the compiler works. Hit F9 to make it. If there are no error messages, DJGPP is properly set up. If there are problems, re-read README.1ST that accompanies the DJGPP distribution. To run our first program, hit Ctrl-F9. The screen will flash briefly while the program does its deed. If you want to see what it did, now hit Alt-F5 to view the User Screen.
이것은 아주아주 전형적인 C+ 프로그램이다. 이것은 쓸모있는 일은 전혀 하지 않는다, 다만 컴파일러가 정상적으로 동작하는지 확인해 볼 수 있을뿐이다. F9를 누르면 컴파일 된다. 만약 에러가 출력되지 않는다면, 컴파일러가 정상적으로 동작한다는 이야기다. 만약 에러가 나왔다면, 컴파일러를 설치하자. (DJGPP 라는 검색어로 구글에서 검색해라.) 우리가 만든 프로그램을 동작시키려면 컨트롤-F9를 누르자. 화면이 잠깐 번쩍일것이다. 그게 실행된거다. 너무 빨라서 뭐가 뭔지 모르겠다면 알트-F5를 눌러라. 실행 모습이 별도의 유저 스트린을 통해서 보일것이다. (라고 번역은 되는데, RHIDE로 테스트 해보지 않아서 번역한 내용과 틀릴수 있음.)
The curious reader will note that the .EXE file that our exercise has produced is very large (almost 200K). This is normal and nothing to worry about, you should remember that DJGPP is a feature-rich 32-bit protected-mode compiler. The DJGPP startup and library code detects and starts up a DPMI host, enters protected mode, takes care of a lot of memory management, reads, parses, and expands command-line arguments, loads environment variables, sets up protected-mode exception handlers, and so on. Of course, all this is wasted on a program that just prints a few characters and exits. If you really are concerned about executable size, consult the DJGPP FAQ about how to reduce its size, but once we write bigger programs this overhead will soon be negligible anyway.
호기심 많은 독자는 .exe 파일이 하는 일에 비해 너무 큰 사이즈(200k 가까이)가 아닌가 하는 의문이 생길수도 있을것이다. 걱정하지 마라. 정상이다. 다만, 이걸 기억해라. 우리가 사용하는 컴파일러(DJGPP)는 32bit 보호모드 컴파일러다. 이 컴파일러는 필요한 라이브러리 코드를 검색하고 DPMI 호스트(...???)를 시작하고, 보호 모드로 진입한다. 메모리도 관리해야 하고 커맨드라인 매개변수를 읽고 분석하기도 하고 환경변수도 로드해야 하고 보호모드 예외핸들러도 설정한다 그리고도 또 뭔가 뭔가 많이 한다. 물론 이 모든것이 단순히 글자 몇개 찍는 프로그램에서는 걍 쓰잘데기 없는것이긴 하다. 만약 내가 이렇게 적어뒀는데도 '하는짓도 없는데 용량만 더럽게 먹네'라고 생각이 든다면 구글을 통해서 `컴파일시 용량 줄이기`에 관련된 내용을 검색해 봐라. 하지만, 다시 말하건데 진짜 큰 프로그램을 만들다 보면 이따위 소소한 오버헤드따위는 신경 안쓰게 될거다.
1.2 Introducing Allegro
I will not waste too much time introducing the theory behind C++, for this the reader may want to consult a dedicated C++ tutorial for more information, and I assume the reader to be at least vaguely familiar with C syntax. I will explain what else we need to know once we need it. And what we need to know right now, is how to start using Allegro. Most concepts concerning the use of Allegro is covered in its own examples, you may want to take a look at them also.
나는 C+ 이론 따위에 집착하고 싶지 않다. C+에관해 더 많이 알고 싶다면 관련된 책을 뒤벼봐라. 나는 기본적으로 이 글을 읽는 사람들이 C 문법정도는 알고 있을거라고 생각하고 이야기를 진행하겠다. 나는 우리가 필요한 것만 언급하겠다. 그리고 지금 현재 우리가 알아야 할것은 알레그로를 어떻게 시작해야 하느냐 하는것이다. 대부분의 알레그로 사용법에 관련된것은 예제로 보여주겠다. 예제만 잘 봐도 된다는 말이다. : )
So, in our tut1.cc, we add some code, to make it look like this:
앞서 작성한 코드에 약간의 코드를 추가해서 다음과 같은 코드를 만들어 보자.
#include <iostream.h>
#include <allegro.h>
int main()
{
allegro_init();
cout << "Ready. Beep." << endl;
return 0;
}
Since we are now using the Allegro library, the linker is going to complain if we compile this right away. In the Options menu, choose Libraries. Type alleg there and check the box beside it. Our program will now link with Allegro if Allegro was properly installed. If it doesn't, read the Allegro FAQ. If run, this program will obviously say "Ready. Beep." instead of "Hello world.", but otherwise not do very much interesting.
만약 우리가 위 코드를 가지고 컴파일을 하면 컴파일러가 관련 라이브러리를 찾을수 없다는 불평을 내 뱉을 것이다. 옵션 메뉴로 가서 라이브러리를 선택하자. alleg를 입력하고 옆에 있는 체크박스에 체크하자. 자, 이제 알레그로 라이브러리가 설치되어 있다면 컴파일시 별 에러 없이 컴파일 될 것이다. 응? 그래도 에러가 난다고? Allegro FAQ 를 구글에서 검색 키워드로 넣어서 어떤 문제인지 확인해 보자. (왠만한 문제는 대체로 해결 될 것이다.) 정상적으로 컴파일이 되었다면 실행해 보자.(앞 서브 챕터에서 컴파일, 런 에 관련해서 다뤘었다.) Ready. Beep. 라는 문자열이 출력되는 것이 보이는가? 정상이다. 근데, 앞서 했던것과 별다를것이 없다. 별로 재미없다. (- _-)
1.3 Using Allegro
We will now add even more code to our little introductory program, and this time use Allegro for the output.
알레그로를 사용해서 출력하도록 앞서 코드에 초큼 더 변경을 가해보겠다.
#include <allegro.h>
int main()
{
allegro_init();
install_keyboard();
set_gfx_mode(GFX_VGA,320,200,0,0);
textout_centre(screen,font,"Ready. Beep.",160,100,255);
readkey();
return 0;
}
Hit Ctrl-F9 to run it. This program does not use the C++ iostream routines to output its text, so we have removed any references to it. Instead, it enters graphics mode, writes "Ready. Beep." at the center of the screen, and waits for you to press a key before it exits. For more details about the functions used here, refer to the Allegro documentation.
컨트롤-F9를 눌러서 실행해 보자. 이 프로그램은 문자열 출력에 C+ iostream 루틴을 사용하지 않는다. 따라서 우리는 #include <iostream> 라인및 iostream 관련 루틴을 뺴버렸다. 대신에 그래픽 모드를 변경하고 Ready. Beep. 를 화면의 중간에 출력하도록 변경해서 키 입력이 발생하면 종료하도록 수정했다. 사용된 함수들에 대해 좀더 자세히 알고 싶다면 알레그로 문서를 참조하자.
Exit RHIDE and proceed to the next chapter
그럼... 다음시간에 다시봐용 : )
ref: http://www.ping.uio.no/~ovehk/allegro/tut1.html


덧글