Presentation is loading. Please wait.

Presentation is loading. Please wait.

Xin Liu Sep 16, 2013. Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453.

Similar presentations


Presentation on theme: "Xin Liu Sep 16, 2013. Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453."— Presentation transcript:

1 Xin Liu Sep 16, 2013

2 Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453 Email: liuxin@ucalgary.ca

3 What do we need? Computer Graphics C/C++ OpenGL/GLSL GLUT

4 Rules Linux/Unix: √ Windows: √ Mac OS: × c/c++: √ Java: × Java = ZERO GNU c/c++:√ Visual c++: √ Objective c:×

5 Getting started with C ++ C/ C ++ The most widely used programming language Operating systems Applications Fast Good for real-time applications Full control of your computer A better understanding of the hardware Can be “dangerous” Professional Good for your future career

6 C vs. C++ vs. Java Java is the son of C++ Java is a totally different language though C++ is the son of C C++ is a superset of C You can compile pure C with a C++ compiler Java is a good start for c/c++ programming Similar grammar

7 C++ vs Java – some differences FunctionC++Java ReferenceYes PointerYesNo Garbage collectionNo (new, delete)Yes Operator overloadingYesNo ClassYes StructYesNo DestructorYesNo

8 Hello world Edit program Compile Run #include “iostream.h” int main () { cout << “Hello\n”; } g++ hello.c –o hello ----------- OR ------------ g++ -c hello g++ hello.o hello hello

9 Compile options -Wall Generate many warnings about questionable looking code g++ -Wall myprog.c –o myprog -O Generate optimized code g++ -O myprog.c –o myprog -g Generate code with symbolic info for debugging g++ -g myprog.c myprog

10 Compiling multi source files A program composed of several souce files, “file1.c”, “file2.c” g++ -file1.c file2.c –o myprog ------------ OR ------------ g++ -c file1.c g++ -c file2.c g++ file1.o file2.o –o myprog

11 Make file The “make program” Compile all source files by a “make” command Track changes of source files Recompile only affected files according to the dependency of source files Requires a makefile to define the dependency

12 Writing a makefile Four basic types of statements Comments any line beginning with a # Macros defined by: name = data used by: $(name), “$(name)” is then replaced by “data” Explicit rules defines the dependency take the form of Example: Implicit rules similar to explicit rules, except listed without commands. uses the suffixes on the files to determine what command to perform targetfile: sourcefiles commands# there is a TAB before each command main: main.c List.h # to create main, these files must exist gcc –o main main.m List.h # the command to create main

13 Using IDE Functions of an IDE (an Integrated Development Environment) Edit program Generating a makefile automatically Compile program Debug program Run program Popular IDEs Eclipse on Linux-suggested Visual Studio on Windows-suggested Xcode on Mac OS-no OpenGL 3.3

14 Example – MyColor.h #include class CMyColor { public: double r; double g; double b; CMyColor (double argR = 0.0, double argG = 0.0, double argB = 0.0); void print(); }; CMyColor operator + (const CMyColor& a, const CMyColor& b); CMyColor operator - (const CMyColor& a, const CMyColor& b); CMyColor operator * (const CMyColor& a, const CMyColor& b); CMyColor operator * (const CMyColor& a, const double& k);

15 Example – MyColor.cpp #include "stdafx.h" #include "MyColor.h" CMyColor:: CMyColor (double argR, double argG, double argB) { r = argR; g = argG; b = argB; } void CMyColor:: print() { printf("[%f, %f, %f]\n", r, g, b); } CMyColor operator + (const CMyColor& a, const CMyColor& b) { return CMyColor(a.r + b.r, a.g + b.g, a.b + b.b); } CMyColor operator - (const CMyColor& a, const CMyColor& b) { return CMyColor(a.r - b.r, a.g - b.g, a.b - b.b); } CMyColor operator * (const CMyColor& a, const CMyColor& b) { return CMyColor(a.r * b.r, a.g * b.g, a.b * b.b); } CMyColor operator * (const CMyColor& a, const double& k) { return CMyColor(k * a.r, k * a.g, k * a.b); }

16 Example – Colors.cpp #include "MyColor.h" int main(int argc, char* argv[]) { CMyColor clr; clr.print(); CMyColor *pClr = 0; pClr = new CMyColor(1.0, 1.0, 1.0); pClr->print(); CMyColor clr2 = (clr + (*pClr)) * 2.0; clr2.print(); delete pClr; return 0; }

17 The End


Download ppt "Xin Liu Sep 16, 2013. Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453."

Similar presentations


Ads by Google