 |
(Much of this content is courtesy of Jeff
Molofee (NeHe)'s OpenGL tutorial #36, which you should read.
It's cool to be able to play movies in your applications that have been
pre-rendered. Think of how many games have some amount of digitised footage,
or rendered animation as start/end screens or elsewhere in them.
To play an AVI file you have to load it, retrieve the information you
want, and then display it somehow. There are several ways to do each of
these tasks; we will just consider one method.
We will use Microsoft's Video for Windows as the API for working
with AVI files. It allows us to use pre-built functions for loading and
reading the file, as well as providing the functionality to decompress
the video data without us having to trouble ourselves about how it is
encoded.
First, we need to set up the project to use VFW.
- Include the vfw.h header file.
#include <vfw.h>
- Link to the vfw32.lib library file.
This requires us to edit the project settings in Visual C++. Choose
Project > Settings then go to the Link tab and add vfw32.lib
to the list of library files which are linked in with this project (otherwise
you will get "unresolved external symbol" errors).

Now - follow the tutorial (linked to above) for more information on how
it's done...
Using this code in your project may require some other effort as well:
You can copy the whole thing into your main file, but that's not as neat
in terms of keeping things logically separated. So:
- You should make a header file out of the AVIfile.cpp program (you
can do this by saving at with a .h extension instead of .cpp, then editing
the function definitions to be declarations only (;) and removing all
of the variables, etc. from the top).
- To add the .h file to your project, you can just try to compile it,
which won't compile, but it will add the file.
- Then include this in your main - #include
"AVIfile.h"
- If you wish to use global variables that are known in both files,
you need to use the word "extern"
before the variable declaration in the file where it isn't declared.
e.g. to use the global variable "frame"
from the AVIfile.cpp program in your main code, you should have extern
int frame in your global variable declarations section. This
tells the compiler that it gets the variable declaration from another
code file.
- You should edit the initialize function so that it only does what
it needs to - it doesn't need to set up OpenGL stuff, if you already
have.
- Make sure you don't have any duplicate function names or variable
names, etc.
- This code works by creating texture maps from the frames in the video,
so to use other textures in your code, you will need to glBindTexture(..)
them appropriately.
- A handy idea is to use a global variable that stores what state
your program is in - e.g. INTRO, PLAY, OUTRO, HELP... - then you
can do the appropriate rendering actions in your idle function. E.g.
if the AVI is to be played as your intro, then set the initial state
to INTRO, have the render function play the AVI based on the case of
the state variable, then when the AVI has finished, set the state to
PLAY (or whatever suits your project).
- You can have the AVI file texture mapped onto something in your main
rendering, as opposed to playing it like a movie, but you'll have to
set up and use your textures properly.
Source Code
Thanks to NeHe
for the tutorial files.
|
|
 |
 |
Announcements |
 |
|
Lecture notes are provided as a guide of
the content of lectures for pre-reading, revision and for
students who cannot attend lectures. While almost every
effort is made to make the online notes as complete as possible,
there is always material discussed in lectures that is not
in the notes.
You should not rely on these notes only!
If you miss a lecture and you do not understand something
in the notes, you should consult (in this order) other students,
the tutors, or the lecturer to try to work it out.
You are expected to read these lecture
notes as well as attending lectures, as vital information
is contained in both.
|
|
|
Subject Coordinator: Lindsay
{w} | {e}.
Last Update:
October 15, 2001
|
 |
|
 |