1
//-----------------------------------------------------------------------------
3
// ImageLib Windows (GDI) Test Source
4
// Copyright (C) 2000 by Denton Woods
5
// Last modified: 08/26/2001 <--Y2K Compliant! =]
7
// Filename: testil/animtest/animtest.c
9
// Description: Animation test application for DevIL.
11
//-----------------------------------------------------------------------------
25
HDC hDC, hMemDC = NULL;
30
#define MIN_W 205 // Accomodate the menu bar.
33
#define TITLE "DevIL Animation Test"
36
ILuint FilterParamInt;
37
ILfloat FilterParamFloat;
38
char FilterEditString[255];
41
BITMAPINFOHEADER *BmpInfo = NULL;
42
HBITMAP *Bitmaps = NULL;
43
ILuint *Durations = NULL;
44
ILuint NumImages = 0, CurImage = 0;
46
__int64 StartTime, TimerFreq;
48
bool IsPaused = false;
51
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
52
void GenFilterString(char *Out, char **Strings);
53
void DisplayImage(void);
54
void LoadImages(char *FileName);
57
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
65
wcex.cbSize = sizeof(WNDCLASSEX);
67
wcex.style = CS_HREDRAW | CS_VREDRAW;
68
wcex.lpfnWndProc = (WNDPROC)WndProc;
71
wcex.hInstance = hInstance;
72
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
73
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
74
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
75
wcex.lpszMenuName = (LPCSTR)IDR_MENU1;
76
wcex.lpszClassName = TITLE;
77
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
79
RegisterClassEx(&wcex);
81
HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
82
50, 50, 400, 300, NULL, NULL, hInstance, NULL);
87
ShowWindow(HWnd, nCmdShow);
91
ilEnable(IL_ORIGIN_SET);
92
ilEnable(IL_TYPE_SET);
93
ilEnable(IL_FORMAT_SET);
95
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
96
ilTypeFunc(IL_UNSIGNED_BYTE);
99
// Is there a file to load from the command-line?
101
LoadImages(__argv[1]);
104
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);
106
while (GetMessage(&msg, NULL, 0, 0)) {
107
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
108
TranslateMessage(&msg);
109
DispatchMessage(&msg);
117
void LoadImages(char *FileName)
122
hMemDC = CreateCompatibleDC(hDC);
124
ilGenImages(1, &Image);
126
if (!ilLoadImage(FileName)) {
127
ilDeleteImages(1, &Image);
131
ilEnable(IL_ORIGIN_SET);
132
ilEnable(IL_FORMAT_SET);
133
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
134
//ilFormatFunc(IL_BGRA);
135
ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
136
ilutRenderer(ILUT_WIN32);
139
NumImages = ilGetInteger(IL_NUM_IMAGES) + 1;
140
Bitmaps = new HBITMAP[NumImages];
141
BmpInfo = new BITMAPINFOHEADER[NumImages];
142
Durations = new ILuint[NumImages];
143
if (Bitmaps == NULL || BmpInfo == NULL || Durations == NULL) {
144
ilDeleteImages(1, &Image);
148
for (i = 0; i < NumImages; i++) {
151
Durations[i] = ilGetInteger(IL_IMAGE_DURATION);
152
*(Bitmaps + i) = ilutConvertToHBitmap(hDC);
153
ilutGetBmpInfo((BITMAPINFO*)(BmpInfo + i));
156
SelectObject(hMemDC, Bitmaps[0]);
158
ilDeleteImages(1, &Image);
160
sprintf(NewTitle, "%s - %s", TITLE, FileName);
161
SetWindowText(HWnd, NewTitle);
163
QueryPerformanceFrequency((LARGE_INTEGER*)&TimerFreq);
164
TimerRes = 1.0 / TimerFreq;
165
QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);
176
for (i = 0; i < NumImages; i++) {
177
DeleteObject(*(Bitmaps + i));
199
static PAINTSTRUCT ps;
200
static __int64 CurTime;
201
static double TimeElapsed;
204
if (Durations == NULL || BmpInfo == NULL || Bitmaps == NULL)
208
QueryPerformanceCounter((LARGE_INTEGER*)&CurTime);
209
TimeElapsed = (CurTime - StartTime) * TimerRes;
210
if (TimeElapsed * 1000 > Durations[CurImage]) {
213
if (CurImage >= NumImages) {
216
SelectObject(hMemDC, Bitmaps[CurImage]);
220
hDC = BeginPaint(HWnd, &ps);
221
BitBlt(hDC, 0, 0, (WORD)BmpInfo[CurImage].biWidth, (WORD)BmpInfo[CurImage].biHeight,
222
hMemDC, 0, 0, SRCCOPY);
229
// Window procedure, handles all messages for this program
230
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
233
static ILuint Colours;
237
static char OpenFileName[2048];
238
static char OpenFilter[2048];
239
static char *OFilter[] = {
240
"All Files (*.*)", "*.*",
241
"Half-Life Model Files (*.mdl)", "*.mdl",
242
"Homeworld Image Files (*.lif)", "*.lif",
243
"Image Files (All Supported Types)", "*.jpe;*.jpg;*.jpeg;*.lif;*.bmp;*.ico;*.pbm;*.pgm;*.pnm;*.ppm;*.png;*.bw;*.rgb;*.rgba;*.sgi;*.tga;*.tif;*.tiff;*.pcx",
244
"Jpeg Files (*.jpe, *.jpg, *.jpeg)", "*.jpe;*.jpg;*.jpeg",
245
"Microsoft Bitmap Files (*.bmp)", "*.bmp",
246
"Microsoft Icon Files (*.ico)", "*.ico",
247
"OpenIL Files (*.oil)", "*.oil",
248
"Portable AnyMap Files (*.pbm, *.pgm, *.pnm, *.ppm)", "*.pbm;*.pgm;*.pnm;*.ppm",
249
"Portable Network Graphics Files (*.png)", "*.png",
250
"Sgi Files (*.sgi)", "*.bw;*.rgb;*.rgba;*.sgi",
251
"Targa Files (*.tga)", "*.tga",
252
"Tiff Files (*.tif)", "*.tif;*.tiff",
253
"Quake Wal Files (*.wal)", "*.wal",
254
"ZSoft Pcx Files (*.pcx)", "*.pcx",
258
static OPENFILENAME Ofn = {
259
sizeof(OPENFILENAME),
272
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
284
GenFilterString(OpenFilter, OFilter);
287
DragAcceptFiles(hWnd, TRUE);
293
ReleaseDC(hWnd, hDC);
295
UnregisterClass(TITLE, hInstance);
304
InvalidateRect(hWnd, NULL, FALSE);
308
if (wParam == VK_ESCAPE)
310
InvalidateRect(hWnd, NULL, FALSE);
314
hDrop = (HDROP)wParam;
315
DragQueryFile(hDrop, 0, OpenFileName, 512);
318
LoadImages(OpenFileName);
324
FilterType = LOWORD(wParam);
326
switch (LOWORD(wParam))
329
PostMessage(hWnd, WM_CLOSE, 0, 0);
333
sprintf(OpenFileName, "*.*");
334
Ofn.lpstrFilter = OpenFilter;
335
Ofn.lpstrFile = OpenFileName;
336
Ofn.lpstrTitle = "Open File";
337
Ofn.nFilterIndex = 1;
338
Ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
340
if (!GetOpenFileName(&Ofn))
344
LoadImages(OpenFileName);
354
QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);
359
return (DefWindowProc(hWnd, message, wParam, lParam));
366
void GenFilterString(char *Out, char **Strings)
368
int OutPos = 0, StringPos = 0;
370
while (Strings[StringPos][0] != 0) {
371
sprintf(Out + OutPos, Strings[StringPos]);
372
OutPos += strlen(Strings[StringPos++]) + 1;