블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
  • total
  • today
  • yesterday

Category

2008. 9. 10. 22:08 Computation/Language
http://en.wikipedia.org/wiki/Windows.h

a Windows-specific header file for the C programming language which contains all the function declarations in the API, as well as declarations for all the common macros used by windows programmers, and all the data types used by the various functions and subsystems.

http://en.wikibooks.org/wiki/Windows_Programming



'Computation > Language' 카테고리의 다른 글

C++ Style  (2) 2010.02.09
Communications Functions (Windows)  (0) 2008.08.14
visual c++ solution - dsw  (0) 2008.08.12
16진수 10진수로 변환 strtol()  (0) 2008.08.12
numeric library  (0) 2008.03.18
posted by maetel
2008. 8. 13. 17:10 Method/CG

ftp://medialab.sogang.ac.kr
폴더: 오동훈>opengl

C관련 참고 사이트
www.winapi.co.kr

추천 교재
OpenGL 3판, 정보교육사

컴퓨터 그래픽스, 한빛미디어

http://nehe.gamedev.net

1. Setting OpenGL
다음의 세 파일을 컴퓨터에 설치한다

1) glut.h
소스코드에서 아래와 같이 하면
#include <gl/glut.h>
다음 경로에서 헤더 파일을 호출한다
C:\Program Files\Microsoft Visual Studio\VC98\Include\GL

2) glut32.dll
dll
dynamic link library
다음 위치에 복사한다
C:\WINDOWS\system32

3) glut32.lib
다음 위치에 복사한다
C:\Program Files\Microsoft Visual Studio\VC98\Lib


2. 예제 코드 Simple.c

* call back 함수
glutDisplayFunc(RenderScene)
여기서 argument로 쓰인 RenderScene은 함수이다

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
여기서 argument는 buffer를 single로 할지 double로 할지를 선택한다.

glFlush() - single일 때
glSwapBuffer() - double일 때


SetupRC()
RC=rendering context

glutMainLoop()
일종의 while문이라고 생각하면 된다.
무한 루프를 돌면서 어떤 이벤트가 생기는지 검사한다.


'Method > CG' 카테고리의 다른 글

OpenGL Super Bible  (0) 2008.08.02
Rendering for an Interactive 360 Light Field Display  (0) 2008.07.11
Game Blender  (0) 2008.02.24
Maya tutorials  (0) 2008.02.18
curved surfaces 곡면  (0) 2008.02.12
posted by maetel
2008. 8. 12. 04:17 Computation/Language

'Computation > Language' 카테고리의 다른 글

Communications Functions (Windows)  (0) 2008.08.14
visual c++ solution - dsw  (0) 2008.08.12
numeric library  (0) 2008.03.18
Python tutorials  (0) 2008.02.24
Using Python for CGI programming  (0) 2007.07.11
posted by maetel
Steve Oualline
Practical C Programming

13. Simple Pointers


183p
Pointers are also called address variables because they contain the addresses of other variables.

184p
Pointers can be used as a quick and simple way to access arrays. (...) Pointers can be used to create new variables and complex data structures such as linked lists and trees.

185p
The operator ampersand (&) returns the address of a thing which is a pointer.
The operator asterisk (*) returns the object to which a pointer points.

Operator - Meaning
* - Dereference (given a pointer, get the thing referenced)
& - Address of (given a thing, point to it)

The operator ampersand (&) returns the address of a thing which is a pointer.
The operator asterisk (*) returns the object to which a pointer points.


int *thing_ptr; // declare a pointer to a thing
thing_ptr = &thing; // point to the thing
*thing_ptr = 5; // set "thing" to 5
// The expression &thing is a pointer to a thing. The variable thing is an object
// thing_ptr points to any integer. It may or may not point to the specific variable thing.

The & (address of operator) gets the address of an object (a pointer).
The * (dereference operator) tells C to look at the data pointed to, not hte pointer itself.

http://www.cplusplus.com/doc/tutorial/pointers.html

http://www.cprogramming.com/tutorial/lesson6.html


187p
Several pointers can point to the same thing.

188p
Pointers as Function Arguments

The only result of a function is a single return value.

http://en.wikipedia.org/wiki/Call_by_value#Call_by_value

http://www.cplusplus.com/doc/tutorial/functions2.html

NULL pointer
locale.h
http://www.cplusplus.com/reference/clibrary/clocale/

189p
const Pointers

const char *answer_ptr = "Forty-Two";

char *const name_ptr = "Test";

const char *const title_ptr = "Title";

191p
Pointers and Arrays

(reminding...) 서 교수님:
number[10] 이라고 배열 선언을 하면 컴파일러는 10개의 연속된 데이터를 위한 공간을 확보하고 그 첫번째 공간의 주소를 number 에 넣습니다. 그래서 number 는 number[0] 의 주소를 가지는 것입니다.

number[1] 은 배열에서  number[0] 다음의 값을 가지는데 그 공간의 주소값을 알고 싶으면 &number[1] 이라고 하든지 number+1  이라고 하면 됩니다.

거꾸로, number 에서 시작하여 두번째 즉 number[1] 의 값을 주소로부터 얻고 싶으면 number[1] 이라고  하든지 *(number+1) 로 하여 얻을 수 있습니다.

192p
A pointer can be used to find each element of the array.

197p
Using Pointers to Split a String

strchr()
http://www.cplusplus.com/reference/clibrary/cstring/strchr.html


201p
Pointers and Structures

Instead of having to move a lot of data around, we can declare an array of pointers and then sort the pointers.


Command-Line Arguments

main (int argc, char *argv[])
{
The parameter argc is the number of arguments on the command line (including the program name).
The array argv contains the actual arguments.

(reminding...)
터미널에서, 말씀하신대로 "./V2008122-01 input.txt"라고 치면 다음과 같이 나옵니다.
argc=2
argv[0]=./V2008122-01
argv[1]=input.txt

서 교수님:
argv[0] = 실행프로그램 이름; 1번째는 항상 실행프로그램의 패스/이름 이 들어갑니다.
이번에는 argv[1] 에 들어갈 두 번째 값을 주었기 때문에 그 값이 프린트 된 것입니다.
command-line arguments는 shell 프로그램이 fileio 함수를 호출할 때 매개변수로 주는 것이고, 좀 더 엄밀하게는 OS 가 main 함수를 호출할 때 주는 것입니다.



http://www.cplusplus.com/reference/clibrary/cstdio/fprintf.html

Example 13-12: print.c
// formats files for printing
// usage: print [options] file(s)

#include <stdio.h>
#include <stdlib.h>

int verbose = 0; // verbose mode (default = false)
char *out_file = "print.out"; //output filename
char *program_name; // name of the program for erros
int line_max = 66; // number of lines per page

void do_file(char *name)
{
    printf("Verbose %d Lines %d Input %s Output %s\n",
           verbose, line_max, name, out_file);
}

void usage (void)
{
    fprintf(stderr, "Usage is %s [options] [file-list]\n",
            program_name);
    fprintf(stderr, "Options\n");
    fprintf(stderr, "    -v    verbose\n");
    fprintf(stderr, "    -l<number> Number of line\n");
    fprintf(stderr, "    -o<name>    Set output filename\n");
    exit(8);
}

int main (int argc, char *argv[])
{
    program_name =argv[0];
   
    while ( (argc>1) && (argv[1][0] == '-') )
        // argv[1][1] is the actual option character
    {
        switch (argv[1][1]) {
            case 'v':
                verbose = 1;
                break;
               
            case 'o':
                out_file = &argv[1][2];
                break;
           
            case 'l':
                line_max = atoi(&argv[1][2]);
                break;
           
            default:
                fprintf(stderr, "Bad option %s\n", argv[1]);
                usage();
        }
       
        ++argv;
        --argc;
    }
   
    if (argc == 1) {
        do_file("printf.in");
    }
    else {
        while (argc>1)
        {
            do_file(argv[1]);
            ++argv;
            --argc;
        }
    }
   
    return(0);
}

Xcode 실행창:
Verbose 0 Lines 66 Input printf.in Output print.out

terminal:
999:~/cintro/ch13/eg12 lym$ ./ch13eg12
Verbose 0 Lines 66 Input printf.in Output print.out
999:~/cintro/ch13/eg12 lym$ ./ch13eg12 i am tired
Verbose 0 Lines 66 Input i Output print.out
Verbose 0 Lines 66 Input am Output print.out
Verbose 0 Lines 66 Input tired Output print.out
999:~/cintro/ch13/eg12 lym$ ./ch13eg12 -v -l128 -0title xfile yfile zfile
Bad option -0title
Usage is ./ch13eg12 [options] [file-list]
Options
        -v      verbose
        -l<number> Number of line
        -o<name>        Set output filename
999:~/cintro/ch13/eg12 lym$ ./ch13eg12 -v -l128 -otitle xfile yfile zfile
Verbose 1 Lines 128 Input xfile Output title
Verbose 1 Lines 128 Input yfile Output title
Verbose 1 Lines 128 Input zfile Output title


208p
A pointer does not create any new space for data, but just refers to data that is created elsewhere.


http://www.cplusplus.com/doc/tutorial/pointers.html
The identifier of an array is equivalent to the address of its first element, as a pointer is equivalent to the address of the first element that it points to, so in fact they are the same concept.

An array can be considered a constant pointer.

http://www.cprogramming.com/tutorial/lesson6.html
Arrays can act just like pointers.


'@GSMC > 서용덕: DMD Programming' 카테고리의 다른 글

Similarity Transformation  (0) 2008.06.10
hw 9 - ppm 이미지 회전시키기  (0) 2008.05.30
[Steve Oualline] 12. Advanced Types  (0) 2008.05.28
data type 정리  (0) 2008.05.24
[Steve Oualline] 11. Bit Operations  (0) 2008.05.14
posted by maetel


strcmp
Compare two strings
Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.


printf format tags
%[flags][width][.precision][length]specifier



atoi
Convert string to integer
On success, the function returns the converted integral number as an int value.
If no valid conversion could be performed, a zero value is returned.
If the correct value is out of the range of representable values, INT_MAX or INT_MIN is returned.



StudentRecord record[NStudent];

StudentRecord *record;
StudentRecord *record_c;

record = new StudentRecord[NStudent];

// C++ version of allocating a memory block

record_c = (StudentRecord *) malloc (sizeof(StudentRecord)*NStudent);
// C version of allocating a memory block
// void * malloc ( size_t size );



malloc
Allocate memory block

ref.   Dynamic Memory Allocation: new and delete (C++)



"NUL indicates end-of-string." (교재 65쪽)


memcpy
서 교수님:
두 개의 struct type 데이터에 대해서, A = B;라고 하여 B를 A에 assign 하는 경우 대부분은 성립합니다. 그러나, struct 내부에서 배열을 가지고 있는 경우에는 그렇지 않습니다. 그래서 memcpy() 라는 함수를 사용하여 메모리를 블럭 단위로 카피하는 방법이 있습니다. 이는 음악 CD나 DVD 의 바이너리 카피를 만드는 것과 같은 이치입니다.




posted by maetel
Steve Oualline
Practical C Prgoramming
6. Decision and Control Statements


calculations, expressions, decision and control statements

control flow
linear programs
branching statements (cause one section of code to be executed or not executed, depending on a conditional clause)
looping statements (are used to repeat a section of code a number of times or until some condition occurs)


if Statement


if (condition)
    statement;

relational operator

"According to the C syntax rules, the else goes with the nearest if."


KISS principle (Keep It Simple, Stupid)
: We shoud write code as cleary and simply as possible.

"By adding an extra set of braces, we improve readability, understanding, and clarity."



strcmp
Compare two strings
: The function compare two strings, and then returns zero if they are equal or nonzero if they are different.
: This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminanting null-character is reached.
: Returns an integral value indicating the relationship between the strings: A zero value indicates that both strings are equal. A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.


Looping statements
while statement

while (condition)
    statement;

The program will repeatedly execute the statement inside the while until the condition becomes false (0).

the Fibonacci numbers    (피보나치 수, 한글 위키백과)


break statement
Loops can be exited at any point through the use of a break statement.


continue statement

"Programs should be clear and simple and should not hide anything."




'@GSMC > 서용덕: DMD Programming' 카테고리의 다른 글

[Steve Oualline] 7. Programming Process  (0) 2008.04.05
week 4 review  (0) 2008.03.27
week 3 review  (0) 2008.03.22
[Steve Oualline] 5. Arrays, Qualifiers, and Reading Numbers  (0) 2008.03.16
hw2  (0) 2008.03.15
posted by maetel
2008. 3. 18. 23:24 Computation/Language
C, 자바, 포트란으로 만들어진 산업 표준 IMSL 수치 라이브러리
http://www.vni.co.kr/products/imsl/documentation/index.html


'Computation > Language' 카테고리의 다른 글

visual c++ solution - dsw  (0) 2008.08.12
16진수 10진수로 변환 strtol()  (0) 2008.08.12
Python tutorials  (0) 2008.02.24
Using Python for CGI programming  (0) 2007.07.11
classes in Python  (0) 2007.07.11
posted by maetel
Practical C Programming
http://www.oreilly.com/catalog/pcp3/

Chapter 4. Basic Declarations and Expressions


Basic Program Structure


The basic elements of a program are the data declarations, functions, and comments.

main() 함수는 첫번째로 호출되는 함수이며, 이 main 함수가 다른 함수들을 직접 또는 간접으로 호출한다.

return(0);는 프로그램이 정상적으로 (Status=0) 존재했었음을 OS에게 보고하기 위해 쓰인다. : return value가 클수록 error가 심각하다는 뜻이다.



Variables
Each variable has a variable type.
A variable must be defined in a declaration statement just before the main() line at the top of a program.

http://en.wikipedia.org/wiki/Computer_numbering_formats

http://en.wikipedia.org/wiki/Signed_number_representations



Assignment statements
The general form of the assignment statement is:
variable = expression;
The = is used for assignment.



printf Function

printf

: a standard function to output our message
Print formatted data to stdout
Writes to the standard output (stdout) a sequence of data formatted as the format argument specifies. After the format parameter, the function expects at least as many additional arguments as specified in format.
The format tags follow this prototype:
%[flags][width][.precision][length]specifier

: 표준 입출력 함수- 표준 입출력 장치를 통해 데이터를 입력하거나 출력하는 기능을 갖고 있는 함수
- 표준 입출력 함수를 사용하려면 #include <stdio.h>를 기술해 줘야 한다.
[형식] printf(" 출력양식 ", 인수1,인수2...);
- 서식문자열에는 모든 문자를 사용할 수 있으며 변환문자와 제어문자를 제외하고는 화면에 그대로 출력
- 인수와 변환문자는 일대일 대응해야 하며 반드시 인수의 자료형과 문자의 자료형은 일치해야 한다.
ex) printf("%d + %d= %d\n",10,20,30);
출력결과 10+20=30


stdout
Standard output stream
: the default destination of regular output for applications. It is usually directed to the output device of the standard console (generally, the screen).

cf. library fuctions


%d
: integer conversion specification

parameter list

The general form of the printf statement is:
printf(format, expression-1, expression-2, ...);
where format is the string describing what to point.



Characters

escape character


'@GSMC > 서용덕: DMD Programming' 카테고리의 다른 글

hw2  (0) 2008.03.15
week 2 review  (0) 2008.03.15
hw1  (0) 2008.03.10
Key concepts in programming: statement & expression  (1) 2008.03.09
week 1 review - keywords & file I/O  (0) 2008.03.07
posted by maetel