1 3d modelling with opengl brian farrimond robina hetherington
Post on 22-Dec-2015
232 views
TRANSCRIPT
![Page 1: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/1.jpg)
1
3D Modelling with OpenGL
Brian Farrimond
Robina Hetherington
![Page 2: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/2.jpg)
2
ScheduleWeek 7 C programming
2D OpenGL
Week 8 3D OpenGL
Animation
Interaction
Week 9 Colour, materials, lighting
Using 3DSMax models
Week 10 Portfolio work
![Page 3: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/3.jpg)
3
Today’s class
• Programming in C
• Using .NET Visual C++
• Compiling + Linking = Building a program
• C programming with OpenGL
• Computer Graphics
• A first OpenGL program
![Page 4: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/4.jpg)
4
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
![Page 5: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/5.jpg)
5
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
/* and */ enclosecomments which are ignored by the compiler
![Page 6: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/6.jpg)
6
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
Include information about the standard library
![Page 7: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/7.jpg)
7
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
A C function.Its name is main
A C program consists of a collection of
functions
![Page 8: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/8.jpg)
8
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
A C function consists of:•a header line•a body made up of statements enclosed by { and }
![Page 9: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/9.jpg)
9
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
header line
body made up of statements
![Page 10: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/10.jpg)
10
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
This is where the program actually starts.
![Page 11: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/11.jpg)
11
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
Every C program has a main function
![Page 12: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/12.jpg)
12
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
printf is a library function to print characters
![Page 13: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/13.jpg)
13
Programming in C
The “Hello world” program
/* hello.cpp */
#include <stdio.h>
int main()
{
printf(“hello, world\n”);
return 0;
}
Return from the main function – i.e. end the program
![Page 14: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/14.jpg)
14
.NET Visual C++
• Microsoft’s C programming environment
• Program code is placed inside a .NET project
• .NET builds the program (or application) with this project
• We shall build a console application (as opposed to a Windows application)
![Page 15: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/15.jpg)
15
Using .NET
• Copy the folder
dotNetExamples\hello
from the CD to your disc space
• Launch .NET
• Open the hello project using File | Open and navigate to hello.sln inside the hello folder
![Page 16: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/16.jpg)
16
Exploring the hello project
• Solution tree
![Page 17: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/17.jpg)
17
Exploring the hello project
• Solution tree
• Double click on hello.cpp to see the program code
![Page 18: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/18.jpg)
18
Hello.cpp
![Page 19: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/19.jpg)
19
Building the program
• To build the program, select the menu item
Build | Build Solution
Or use one of these two buttons
![Page 20: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/20.jpg)
20
Running the program
• To run the program, select menu item
Debug | Start
Or use this button
![Page 21: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/21.jpg)
21
Use of getchar()
• Without getchar() the program terminates at once before we can see what printf has done
• getchar() pauses the program until we press the return key.
![Page 22: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/22.jpg)
22
Exercises
• Modify the text inside the printf statement
• Modify the program so that it prints outOne
Two
Three
![Page 23: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/23.jpg)
23
Building = Compiling + linking
• Building is a two stage process:– Compiling source code into object code– Linking object code and library code to produce
the program (known as the executable)
![Page 24: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/24.jpg)
24
More on Building
• See using dotNET IDE in C page 16
![Page 25: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/25.jpg)
25
Separate compilation
• Large programs are made up of many source files
• Each file compiled separately
• Advantages:– Changing the code of one file does not require
recompiling the entire program– Team of programmers can work on different
files
![Page 26: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/26.jpg)
26
Multifile example
![Page 27: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/27.jpg)
27
The multifile .NET project
• Copy the folderdotNetExamples\multifile
from the CD to your disc space
• Open the project usingFile | Open
• Examine the solution tree
![Page 28: 1 3D Modelling with OpenGL Brian Farrimond Robina Hetherington](https://reader034.vdocuments.mx/reader034/viewer/2022051516/56649d7a5503460f94a5e3c5/html5/thumbnails/28.jpg)
28
The multifile .NET project
• Build and run the program
• Edit func2.cpp so that it prints out:
This is the new func 2
• Rebuild and rerun the program