Add DevIL 1.7.8.

This commit is contained in:
rude
2013-09-26 00:20:08 +02:00
parent 6e493fb605
commit c065120c58
487 changed files with 219483 additions and 0 deletions
@@ -0,0 +1,51 @@
// Almost identical to Allegro's ex15.c
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <allegro.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
BITMAP *Image;
PALETTE Pal;
ILuint Id;
if (argc != 2) {
printf("Please specify a filename.\n");
return 1;
}
ilInit();
ilGenImages(1, &Id);
ilBindImage(Id);
ilLoadImage(argv[1]);
// if (ilGetInteger(IL_IMAGE_FORMAT) == GL_BGR ||
// ilGetInteger(IL_IMAGE_FORMAT) == GL_BGRA)
ilSwapColours();
Image = (BITMAP*)ilutConvertToAlleg(Pal);
allegro_init();
install_keyboard();
if (ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) == 8) {
set_color_depth(8);
set_palette(Pal);
}
else
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
blit(Image, screen, 0, 0, (SCREEN_W - Image->w) / 2,
(SCREEN_H - Image->h) / 2, Image->w, Image->h);
destroy_bitmap(Image);
readkey();
return 0;
}
@@ -0,0 +1,379 @@
//-----------------------------------------------------------------------------
//
// ImageLib Windows (GDI) Test Source
// Copyright (C) 2000 by Denton Woods
// Last modified: 08/26/2001 <--Y2K Compliant! =]
//
// Filename: testil/animtest/animtest.c
//
// Description: Animation test application for DevIL.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#ifdef _DEBUG
#define IL_DEBUG
#endif
#include <il/il.h>
#include <il/ilu.h>
#include <il/ilut.h>
#include "resource.h"
// Evil globals!
HINSTANCE hInstance;
HDC hDC, hMemDC = NULL;
HWND HWnd;
#define BORDER_W 8
#define MENU_H 46
#define MIN_W 205 // Accomodate the menu bar.
#define MAX_W 400
#define MAX_H 400
#define TITLE "DevIL Animation Test"
ILuint FilterType;
ILuint FilterParamInt;
ILfloat FilterParamFloat;
char FilterEditString[255];
char NewTitle[512];
BITMAPINFOHEADER *BmpInfo = NULL;
HBITMAP *Bitmaps = NULL;
ILuint *Durations = NULL;
ILuint NumImages = 0, CurImage = 0;
__int64 StartTime, TimerFreq;
double TimerRes;
bool IsPaused = false;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void GenFilterString(char *Out, char **Strings);
void DisplayImage(void);
void LoadImages(char *FileName);
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASSEX wcex;
HACCEL hAccelTable;
hInstance = hInst;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDR_MENU1;
wcex.lpszClassName = TITLE;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
RegisterClassEx(&wcex);
HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
50, 50, 400, 300, NULL, NULL, hInstance, NULL);
if (HWnd == NULL)
return FALSE;
// Display the window
ShowWindow(HWnd, nCmdShow);
UpdateWindow(HWnd);
ilInit();
ilEnable(IL_ORIGIN_SET);
ilEnable(IL_TYPE_SET);
ilEnable(IL_FORMAT_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
ilTypeFunc(IL_UNSIGNED_BYTE);
ilFormatFunc(IL_BGR);
// Is there a file to load from the command-line?
if (__argc > 1) {
LoadImages(__argv[1]);
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
void LoadImages(char *FileName)
{
ILuint Image, i;
hDC = GetDC(HWnd);
hMemDC = CreateCompatibleDC(hDC);
ilGenImages(1, &Image);
ilBindImage(Image);
if (!ilLoadImage(FileName)) {
ilDeleteImages(1, &Image);
return;
}
ilEnable(IL_ORIGIN_SET);
ilEnable(IL_FORMAT_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
//ilFormatFunc(IL_BGRA);
ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
ilutRenderer(ILUT_WIN32);
CurImage = 0;
NumImages = ilGetInteger(IL_NUM_IMAGES) + 1;
Bitmaps = new HBITMAP[NumImages];
BmpInfo = new BITMAPINFOHEADER[NumImages];
Durations = new ILuint[NumImages];
if (Bitmaps == NULL || BmpInfo == NULL || Durations == NULL) {
ilDeleteImages(1, &Image);
return;
}
for (i = 0; i < NumImages; i++) {
ilActiveImage(0);
ilActiveImage(i);
Durations[i] = ilGetInteger(IL_IMAGE_DURATION);
*(Bitmaps + i) = ilutConvertToHBitmap(hDC);
ilutGetBmpInfo((BITMAPINFO*)(BmpInfo + i));
}
SelectObject(hMemDC, Bitmaps[0]);
ilDeleteImages(1, &Image);
sprintf(NewTitle, "%s - %s", TITLE, FileName);
SetWindowText(HWnd, NewTitle);
QueryPerformanceFrequency((LARGE_INTEGER*)&TimerFreq);
TimerRes = 1.0 / TimerFreq;
QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);
return;
}
void DestroyGDI()
{
ILuint i;
if (Bitmaps) {
for (i = 0; i < NumImages; i++) {
DeleteObject(*(Bitmaps + i));
}
}
if (hMemDC)
DeleteDC(hMemDC);
if (Bitmaps)
delete []Bitmaps;
if (BmpInfo)
delete []BmpInfo;
Bitmaps = NULL;
BmpInfo = NULL;
hMemDC = NULL;
return;
}
void DisplayImage()
{
static PAINTSTRUCT ps;
static __int64 CurTime;
static double TimeElapsed;
// Not created yet.
if (Durations == NULL || BmpInfo == NULL || Bitmaps == NULL)
return;
if (!IsPaused) {
QueryPerformanceCounter((LARGE_INTEGER*)&CurTime);
TimeElapsed = (CurTime - StartTime) * TimerRes;
if (TimeElapsed * 1000 > Durations[CurImage]) {
StartTime = CurTime;
CurImage++;
if (CurImage >= NumImages) {
CurImage = 0;
}
SelectObject(hMemDC, Bitmaps[CurImage]);
}
}
hDC = BeginPaint(HWnd, &ps);
BitBlt(hDC, 0, 0, (WORD)BmpInfo[CurImage].biWidth, (WORD)BmpInfo[CurImage].biHeight,
hMemDC, 0, 0, SRCCOPY);
EndPaint(HWnd, &ps);
return;
}
// Window procedure, handles all messages for this program
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HMENU hMenu;
static ILuint Colours;
static RECT Rect;
static HDROP hDrop;
static char OpenFileName[2048];
static char OpenFilter[2048];
static char *OFilter[] = {
"All Files (*.*)", "*.*",
"Half-Life Model Files (*.mdl)", "*.mdl",
"Homeworld Image Files (*.lif)", "*.lif",
"Image Files (All Supported Types)", "*.jpe;*.jpg;*.jpeg;*.lif;*.bmp;*.ico;*.pbm;*.pgm;*.pnm;*.ppm;*.png;*.bw;*.rgb;*.rgba;*.sgi;*.tga;*.tif;*.tiff;*.pcx",
"Jpeg Files (*.jpe, *.jpg, *.jpeg)", "*.jpe;*.jpg;*.jpeg",
"Microsoft Bitmap Files (*.bmp)", "*.bmp",
"Microsoft Icon Files (*.ico)", "*.ico",
"OpenIL Files (*.oil)", "*.oil",
"Portable AnyMap Files (*.pbm, *.pgm, *.pnm, *.ppm)", "*.pbm;*.pgm;*.pnm;*.ppm",
"Portable Network Graphics Files (*.png)", "*.png",
"Sgi Files (*.sgi)", "*.bw;*.rgb;*.rgba;*.sgi",
"Targa Files (*.tga)", "*.tga",
"Tiff Files (*.tif)", "*.tif;*.tiff",
"Quake Wal Files (*.wal)", "*.wal",
"ZSoft Pcx Files (*.pcx)", "*.pcx",
"\0\0"
};
static OPENFILENAME Ofn = {
sizeof(OPENFILENAME),
hWnd,
NULL,
OpenFilter,
NULL,
0,
0,
OpenFileName,
512,
NULL,
0,
NULL,
NULL,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
0,
0,
NULL,
NULL,
NULL,
NULL
};
switch (message)
{
case WM_CREATE:
GenFilterString(OpenFilter, OFilter);
hDC = GetDC(hWnd);
DragAcceptFiles(hWnd, TRUE);
break;
case WM_CLOSE:
DestroyGDI();
ReleaseDC(hWnd, hDC);
DestroyWindow(hWnd);
UnregisterClass(TITLE, hInstance);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
DisplayImage();
InvalidateRect(hWnd, NULL, FALSE);
break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
PostQuitMessage(0);
InvalidateRect(hWnd, NULL, FALSE);
break;
case WM_DROPFILES:
hDrop = (HDROP)wParam;
DragQueryFile(hDrop, 0, OpenFileName, 512);
DestroyGDI();
LoadImages(OpenFileName);
DragFinish (hDrop);
return 0;
case WM_COMMAND:
FilterType = LOWORD(wParam);
switch (LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
return (0L);
case ID_FILE_LOAD:
sprintf(OpenFileName, "*.*");
Ofn.lpstrFilter = OpenFilter;
Ofn.lpstrFile = OpenFileName;
Ofn.lpstrTitle = "Open File";
Ofn.nFilterIndex = 1;
Ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
if (!GetOpenFileName(&Ofn))
return (0L);
DestroyGDI();
LoadImages(OpenFileName);
return (0L);
case ID_EDIT_PAUSE:
IsPaused = true;
return 0;
case ID_EDIT_RESUME:
IsPaused = false;
QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);
return 0;
}
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (0L);
}
void GenFilterString(char *Out, char **Strings)
{
int OutPos = 0, StringPos = 0;
while (Strings[StringPos][0] != 0) {
sprintf(Out + OutPos, Strings[StringPos]);
OutPos += strlen(Strings[StringPos++]) + 1;
}
Out[OutPos++] = 0;
Out[OutPos] = 0;
return;
}
@@ -0,0 +1,109 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
#include "resource.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""resource.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...\tCtrl+O", ID_FILE_LOAD
MENUITEM "E&xit\tEsc", ID_FILE_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "&Pause", ID_EDIT_PAUSE
MENUITEM "&Resume", ID_EDIT_RESUME
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON DISCARDABLE "OpenIL.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MENU1 ACCELERATORS DISCARDABLE
BEGIN
"O", ID_FILE_LOAD, VIRTKEY, CONTROL, NOINVERT
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

@@ -0,0 +1,75 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by AnimTest.rc
//
#define IDC_MYICON 2
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDC_OPENIL 109
#define IDR_MAINFRAME 128
#define IDI_ICON1 155
#define IDR_MENU1 167
#define IDD_DIALOG_ABOUT 168
#define IDC_ABOUT_VENDOR 1001
#define IDC_ABOUT_VER_STRING 1002
#define IDC_ABOUT_VER_NUM 1003
#define IDC_FILTER_EDIT 1004
#define IDC_FILTER_DESC_TEXT 1005
#define IDC_ERROR1 1014
#define IDC_ERROR2 1015
#define IDC_ERROR3 1016
#define IDC_ERROR4 1017
#define IDC_ERROR5 1018
#define IDC_ERROR6 1019
#define IDC_OPENIL_LINK 1020
#define ID_FILE_EXIT 32771
#define ID_HELP_ABOUT 32772
#define ID_CONVERT_RGB 32773
#define ID_CONVERT_RGBA 32774
#define ID_CONVERT_BGR 32775
#define ID_CONVERT_BGRA 32776
#define ID_CONVERT_LUMINANCE 32777
#define ID_FILE_LOAD 32778
#define ID_FILE_SAVE 32779
#define ID_FILTER_BITFILTER1 32780
#define ID_FILTER_BITFILTER2 32781
#define ID_FILTER_BITFILTER3 32782
#define ID_FILTER_EMBOSS 32783
#define ID_FILTER_NOISE 32784
#define ID_FILTER_PIXELIZE 32785
#define ID_EFFECTS_FILTERS_SCALE 32786
#define ID_EFFECTS_FILTERS_EDGEDETECT_SOBEL 32787
#define ID_EFFECTS_FILTERS_EDGEDETECT_PREWITT 32788
#define ID_EDIT_UNDO 32789
#define ID_EDIT_UNDOLEVEL 32790
#define ID_FILTERS_BLUR_AVERAGE 32791
#define ID_FILTERS_BLUR_GAUSSIAN 32792
#define ID_FILTER_GAMMACORRECT 32793
#define ID_FILTER_ALIENIFY 32794
#define ID_FILTER_SHARPEN 32795
#define ID_FILTER_NEGATIVE 32796
#define ID_EFFECTS_FLIP 32797
#define ID_EFFECTS_MIRROR 32798
#define ID_EFFECTS_COUNTCOLORS 32799
#define ID_EDIT_COPY 32800
#define ID_EDIT_PASTE 32801
#define ID_EFFECTS_FILTERS_ROTATE 32802
#define ID_EFFECTS_FILTERS_EDGEDETECT_EMBOSS 32804
#define ID_FILE_OPENURL 32808
#define ID_CONVERT_PALETTE 32809
#define ID_EDIT_PAUSE 32810
#define ID_EDIT_RESUME 32811
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 182
#define _APS_NEXT_COMMAND_VALUE 32812
#define _APS_NEXT_CONTROL_VALUE 1021
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif
@@ -0,0 +1,23 @@
#include <IL/devil_cpp_wrapper.hpp>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
if (argc < 2) {
cout << "Please specify a filename." << endl;
return 1;
}
ilImage Image(argv[1]);
cout << Image.Width() << 'x' << Image.Height() << '@' << (ILuint)Image.Bpp() << endl;
ilEnable(IL_FILE_OVERWRITE);
Image.Save("test.tga");
return 0;
}
@@ -0,0 +1,335 @@
//-----------------------------------------------------------------------------
//
// ImageLib GL Test Source
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 04/28/2001 <--Y2K Compliant! =]
//
// Filename: testil/d3dtest/d3dtest.cpp
//
// Description: Sample implementation of a Direct3D 8.0a image viewer.
//
//
// 20040801 XIX: DX9 update, hopefully :)
//
//-----------------------------------------------------------------------------
#define STRICT
#include <stdio.h>
#include <math.h>
#include <D3DX9.h>
//#include "dxstdafx.h"
//#include "D3DApp.h"
//#include "D3DFile.h"
//#include "D3DFont.h"
//#include "D3DUtil.h"
#ifdef _DEBUG
#define IL_DEBUG
#endif//_DEBUG
#include <il/ilut.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "winmm.lib")
//
//
// Taken from the D3D 8.0a SDK Volumetric Texture Sample.
//
//
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
struct VERTEX
{
FLOAT x, y, z;
DWORD color;
FLOAT tu, tv;
};
#define D3DFVF_VERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1|D3DFVF_TEXCOORDSIZE2(0))
VERTEX g_vVertices[4] =
{
{ 1.0f,-1.0f, 0.0f, 0xffffffff, 1.0f, 1.0f },
{-1.0f,-1.0f, 0.0f, 0xffffffff, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f, 0xffffffff, 1.0f, 0.0f },
{-1.0f, 1.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }
};
//-----------------------------------------------------------------------------
// Name: class CMyD3DApplication
// Desc: Application class. The base class (CD3DApplication) provides the
// generic functionality needed in all Direct3D samples. CMyD3DApplication
// adds functionality specific to this sample program.
//-----------------------------------------------------------------------------
class CMyD3DApplication : public CD3DApplication
{
CD3DFont* m_pFont;
LPDIRECT3DTEXTURE9 m_pTexture;
LPDIRECT3DVERTEXBUFFER9 m_pVB;
HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT );
protected:
HRESULT OneTimeSceneInit();
HRESULT InitDeviceObjects();
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();
HRESULT FinalCleanup();
HRESULT Render();
HRESULT FrameMove();
public:
CMyD3DApplication();
};
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Idle time is used to render the scene.
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
CMyD3DApplication d3dApp;
if (__argc <= 1)
return 1;
if( FAILED( d3dApp.Create( hInst ) ) )
return 0;
return d3dApp.Run();
}
//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Application constructor. Sets attributes for the app.
//-----------------------------------------------------------------------------
CMyD3DApplication::CMyD3DApplication()
{
m_strWindowTitle = _T("DevIL Direct3D Test");
// m_bUseDepthBuffer = TRUE;
m_pFont = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
m_pTexture = NULL;
m_pVB = NULL;
}
//-----------------------------------------------------------------------------
// Name: OneTimeSceneInit()
// Desc: Called during initial app startup, this function performs all the
// permanent initialization.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::OneTimeSceneInit()
{
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FrameMove()
// Desc: Called once per frame, the call is the entry point for animating
// the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FrameMove()
{
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Called once per frame, the call is the entry point for 3d
// rendering. This function sets up render states, clears the
// viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Render()
{
// Clear the viewport
m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x00000000, 1.0f, 0L );
// Begin the scene
if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
// Draw the quad, with the volume texture
m_pd3dDevice->SetTexture( 0, m_pTexture );
// m_pd3dDevice->SetVertexShader( D3DFVF_VERTEX );
m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(VERTEX) );
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);
// Output statistics
m_pFont->DrawText( 2, 0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats );
m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats );
// End the scene.
m_pd3dDevice->EndScene();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
HRESULT hr;
m_pFont->InitDeviceObjects( m_pd3dDevice );
ilInit();
iluInit();
ilutInit();
ilutD3D8TexFromFile(m_pd3dDevice, __argv[1], &m_pTexture);
//D3DXCreateTextureFromFile(m_pd3dDevice, __argv[1], &m_pTexture);
// Create a vertex buffer
{
if( FAILED( hr = m_pd3dDevice->CreateVertexBuffer( 4*sizeof(VERTEX),
D3DUSAGE_WRITEONLY,
D3DFVF_VERTEX,
D3DPOOL_MANAGED, &m_pVB ) ) )
return hr;
VERTEX* pVertices;
m_pVB->Lock( 0, 4*sizeof(VERTEX), (BYTE**)&pVertices, 0 );
memcpy( pVertices, g_vVertices, sizeof(VERTEX)*4 );
m_pVB->Unlock();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
m_pFont->RestoreDeviceObjects();
// Set the matrices
D3DXVECTOR3 vEye( 0.0f, 0.0f,-3.0f );
D3DXVECTOR3 vAt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUp( 0.0f, 1.0f, 0.0f );
D3DXMATRIX matWorld, matView, matProj;
D3DXMatrixIdentity( &matWorld );
D3DXMatrixLookAtLH( &matView, &vEye,&vAt, &vUp );
FLOAT fAspect = m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f );
m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
// Set state
m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InvalidateDeviceObjects()
{
m_pFont->InvalidateDeviceObjects();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DeleteDeviceObjects()
// Desc: Called when the app is exiting, or the device is being changed,
// this function deletes any device dependent objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::DeleteDeviceObjects()
{
m_pFont->DeleteDeviceObjects();
SAFE_RELEASE( m_pTexture );
SAFE_RELEASE( m_pVB );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FinalCleanup()
// Desc: Called before the app exits, this function gives the app the chance
// to cleanup after itself.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FinalCleanup()
{
SAFE_DELETE( m_pFont );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: ConfirmDevice()
// Desc: Called during device intialization, this code checks the device
// for some minimum set of capabilities
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS8* pCaps, DWORD dwBehavior,
D3DFORMAT Format )
{
return S_OK;
}
@@ -0,0 +1,259 @@
//-----------------------------------------------------------------------------
//
// ImageLib GL Test Source
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 05/17/2002 <--Y2K Compliant! =]
//
// Filename: examples/gl example/gl example.c
//
// Description: Sample implementation of an OpenGL image viewer.
//
//-----------------------------------------------------------------------------
//
// We use FreeGlut in Windows, because it's more stable.
//
#ifdef _WIN32
#include <GL/freeglut.h>
#else
#include <GL/glut.h>
#endif
#ifdef _DEBUG
#define IL_DEBUG
#endif//_DEBUG
#define ILUT_USE_OPENGL
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include "gltest.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//
// Easier to do this than change the project's settings in MSVC++. (I'm lazy!)
//
#ifdef _MSC_VER
#pragma comment(lib, "freeglut.lib")
// Prevent the console window from popping up.
//#pragma comment(linker, "/entry:mainCRTStartup")
//#pragma comment(linker, "/subsystem:windows")
#endif
char *FileName;
ILuint Width, Height, window;
void HandleDevILErrors ()
{
ILenum error = ilGetError ();
if (error != IL_NO_ERROR) {
do {
printf ("\n\n%s\n", iluErrorString (error));
} while ((error = ilGetError ()));
exit (1);
}
}
extern int main(int argc, char** argv);
int main(int argc, char** argv)
{
// No filename is specified on the command-line.
if (argc < 2) {
printf ("Please run as:\n\nDevIL_testGL image_filename\n");
return 1;
}
FileName = argv[1]; // Set filename equal to the first argument.
//
// Check if the shared lib's version matches the executable's version.
//
//
// fixed to get the right numbers from the right library call...
//
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION ||
ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) {
printf ("DevIL library is out of date! Please upgrade\n");
return 2;
}
// Needed to initialize DevIL.
ilInit ();
iluInit();
// GL cannot use palettes anyway, so convert early.
ilEnable (IL_CONV_PAL);
// Gets rid of dithering on some nVidia-based cards.
ilutEnable (ILUT_OPENGL_CONV);
// Generate the main image name to use.
ilGenImages (1, &ImgId);
// Bind this image name.
ilBindImage (ImgId);
// Loads the image specified by File into the ImgId image.
if (!ilLoadImage (FileName)) {
HandleDevILErrors ();
}
// Make sure the window is in the same proportions as the image.
// Generate the appropriate width x height less than or equal to MAX_X x MAX_Y.
// Instead of just clipping Width x Height to MAX_X x MAX_Y, we scale to
// an appropriate size, so the image isn't stretched/squished.
Width = ilGetInteger (IL_IMAGE_WIDTH);
Height = ilGetInteger (IL_IMAGE_HEIGHT);
if (Width > 0) { // Don't want a divide by 0...
if (Width > MAX_X) {
Width = MAX_X;
Height = (ILuint)(MAX_X / (ILfloat)ilGetInteger(IL_IMAGE_WIDTH) * Height);
}
}
if (Height > 0) { // Don't want a divide by 0...
if (Height > MAX_Y) {
Height = MAX_Y;
Width = (ILuint)(MAX_Y / (ILfloat)ilGetInteger(IL_IMAGE_HEIGHT) * Width);
}
}
HandleDevILErrors ();
// Standard glut initializations.
glutInit (&argc, argv); // Standard glut initialization.
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowPosition (100, 100);
glutInitWindowSize (Width, Height);
window = glutCreateWindow("Developer's Image Library (DevIL) Test");
ilutInit();
glutDisplayFunc (DisplayFunc);
glutKeyboardFunc (KeyboardFunc);
// Goes into our setup function.
if (Setup() == IL_FALSE)
return 1;
// Enter the main (Free)GLUT processing loop
glutMainLoop();
// Clean up any loose ends.
CleanUp();
return 0;
}
//
// Standard glut resize function.
//
void ResizeFunc(int NewWidth, int NewHeight)
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glViewport (0, 0, NewWidth, NewHeight);
glOrtho (0, Width, Height, 0, -1, 1);
}
//
// Standard glut display function.
//
void DisplayFunc()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear the colour buffer.
// Texture a quad with our image that fills the entire window.
glBindTexture (GL_TEXTURE_2D, TexID);
glBegin (GL_QUADS);
/*glTexCoord2f (0.0f, 0.0f); glVertex3i (0, 0, 0);
glTexCoord2f (1.0f, 0.0f); glVertex3i (Width, 0, 0);
glTexCoord2f (1.0f, 1.0f); glVertex3i (Width, Height, 0);
glTexCoord2f (0.0f, 1.0f); glVertex3i (0, Height, 0);*/
glTexCoord2f (0.0f, 1.0f); glVertex3i (0, 0, 0);
glTexCoord2f (1.0f, 1.0f); glVertex3i (Width, 0, 0);
glTexCoord2f (1.0f, 0.0f); glVertex3i (Width, Height, 0);
glTexCoord2f (0.0f, 0.0f); glVertex3i (0, Height, 0);
glEnd();
glutSwapBuffers(); // We use double buffering, so swap the buffers.
}
//
// Standard glut idle function
//
void IdleFunc()
{
glutShowWindow ();
glutPostRedisplay ();
}
//
// Any keypress closes the window - standard glut keypress function.
//
void KeyboardFunc(unsigned char cChar, int nMouseX, int nMouseY)
{
CleanUp(); // Clean up OpenGL.
glutDestroyWindow(window); // Destroy the window.
#ifndef _WIN32
// Must use this with regular glut, since it never returns control to main().
exit(0);
#endif
}
//
// Setup OpenGL to use our image.
//
ILboolean Setup()
{
glEnable (GL_TEXTURE_2D); // Enable texturing.
glMatrixMode (GL_PROJECTION); // We want to use the projection matrix.
glLoadIdentity (); // Loads the identity matrix into the current matrix.
// Lets ILUT know to use its OpenGL functions.
ilutRenderer (ILUT_OPENGL);
// Goes through all steps of sending the image to OpenGL.
TexID = ilutGLBindTexImage();
// We're done with our image, so we go ahead and delete it.
ilDeleteImages(1, &ImgId);
glOrtho(0, Width, Height, 0, -1, 1); // Set up an orthographic projection with OpenGL.
return IL_TRUE;
}
//
// Cleans up any loose ends.
//
void CleanUp()
{
if (!bCleaned) // Can only delete the texture once.
glDeleteTextures (1, &TexID); // Delete our OpenGL texture.
bCleaned = IL_TRUE; // Want to make sure we only delete it once.
}
@@ -0,0 +1,36 @@
//-----------------------------------------------------------------------------
//
// ImageLib GL Test Source
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 10/13/2000 <--Y2K Compliant! =]
//
// Filename: examples/gl example/gl example.h
//
// Description: Sample implementation of an OpenGL image viewer.
//
//-----------------------------------------------------------------------------
#ifndef GLTEST_H
#define GLTEST_H
// We don't want a larger window than this.
#define MAX_X 640
#define MAX_Y 480
// Function prototypes.
void DisplayFunc(void);
void CleanUp(void);
void ResizeFunc(int NewWidth, int NewHeight);
void IdleFunc(void);
void KeyboardFunc(unsigned char cChar, int nMouseX, int nMouseY);
ILboolean Setup();
// Has the main GL texture been deleted?
ILboolean bCleaned = 0;
// GL texture ID
GLuint TexID = 0;
// IL image ID
ILuint ImgId = 0;
#endif//GLTEST_H
@@ -0,0 +1,165 @@
//-----------------------------------------------------------------------------
//
// ImageLib Source Example
// Copyright (C) 2000-2001 by Denton Woods
// Last modified: 09/06/2001 <--Y2K Compliant! =]
//
// Filename: examples/file override/file override.c
//
// Description: An example of overriding the DevIL reading and
// writing functions via ilSetRead and ilSetWrite.
//
//-----------------------------------------------------------------------------
// Required include files.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <IL/il.h>
#include <stdio.h>
/* We would need ILU just because of iluErrorString() function... */
/* So make it possible for both with and without ILU! */
#ifdef ILU_ENABLED
#include <IL/ilu.h>
#define PRINT_ERROR_MACRO printf("Error: %s\n", iluErrorString(Error))
#else /* not ILU_ENABLED */
#define PRINT_ERROR_MACRO printf("Error: 0x%X\n", (unsigned int)Error)
#endif /* not ILU_ENABLED */
ILHANDLE ILAPIENTRY iOpenRead(const char *FileName)
{
return (ILHANDLE)fopen(FileName, "rb");
}
void ILAPIENTRY iCloseRead(ILHANDLE Handle)
{
fclose((FILE*)Handle);
return;
}
ILHANDLE ILAPIENTRY iOpenWrite(const char *FileName)
{
return (ILHANDLE)fopen(FileName, "wb");
}
void ILAPIENTRY iCloseWrite(ILHANDLE Handle)
{
fclose((FILE*)Handle);
return;
}
ILboolean ILAPIENTRY iEof(ILHANDLE Handle)
{
return (feof((FILE*)Handle) != 0);
}
ILint ILAPIENTRY iGetc(ILHANDLE Handle)
{
return fgetc((FILE*)Handle);
}
ILint ILAPIENTRY iPutc(ILubyte Char, ILHANDLE Handle)
{
return fputc(Char, (FILE*)Handle);
}
ILint ILAPIENTRY iRead(void *Buffer, ILuint Size, ILuint Number, ILHANDLE Handle)
{
return fread(Buffer, Size, Number, (FILE*)Handle);
}
ILint ILAPIENTRY iWrite(const void *Buffer, ILuint Size, ILuint Number, ILHANDLE Handle)
{
return fwrite(Buffer, Size, Number, (FILE*)Handle);
}
ILint ILAPIENTRY iReadSeek(ILHANDLE Handle, ILint Offset, ILint Mode)
{
return fseek((FILE*)Handle, Offset, Mode);
}
ILint ILAPIENTRY iWriteSeek(ILHANDLE Handle, ILint Offset, ILint Mode)
{
return fseek((FILE*)Handle, Offset, Mode);
}
ILint ILAPIENTRY iReadTell(ILHANDLE Handle)
{
return ftell((FILE*)Handle);
}
ILint ILAPIENTRY iWriteTell(ILHANDLE Handle)
{
return ftell((FILE*)Handle);
}
int main(int argc, char **argv)
{
ILuint ImgId;
ILenum Error;
// We use the filename specified in the first argument of the command-line.
if (argc < 2) {
printf("Please specify a file to open.\n");
return 1;
}
// Check if the shared lib's version matches the executable's version.
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) {
printf("DevIL version is different...exiting!\n");
return 2;
}
// Initialize DevIL.
ilInit();
// Generate the main image name to use.
ilGenImages(1, &ImgId);
// Bind this image name.
ilBindImage(ImgId);
// Override the reading functions.
ilSetRead(iOpenRead, iCloseRead, iEof, iGetc, iRead, iReadSeek, iReadTell);
ilSetWrite(iOpenWrite, iCloseWrite, iPutc, iWriteSeek, iWriteTell, iWrite);
// Loads the image specified by File into the image named by ImgId.
if (!ilLoadImage(argv[1])) {
printf("Could not open file...exiting.\n");
return 3;
}
// Display the image's dimensions to the end user.
printf("Width: %d Height: %d Depth: %d Bpp: %d\n", ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));
// Enable this to let us overwrite the destination file if it already exists.
ilEnable(IL_FILE_OVERWRITE);
// If argv[2] is present, we save to this filename, else we save to test.tga.
if (argc > 2)
ilSaveImage(argv[2]);
else
ilSaveImage("test.tga");
// Reset the reading / writing functions when we're done loading specially.
// This isn't required here, since we're exiting, but here's how it's done:
ilResetRead();
ilResetWrite();
// We're done with the image, so let's delete it.
ilDeleteImages(1, &ImgId);
// Simple Error detection loop that displays the Error to the user in a human-readable form.
while ((Error = ilGetError())) {
PRINT_ERROR_MACRO;}
return 0;
}
@@ -0,0 +1,119 @@
//-----------------------------------------------------------------------------
//
// ImageLib Source Example
// Copyright (C) 2000-2001 by Denton Woods
// Last modified: 09/07/2001 <--Y2K Compliant! =]
//
// Filename: examples/register read/register read.c
//
// Description: An example of creating your own loading routine
// to use with DevIL -- uses a hypothetical format.
//
//-----------------------------------------------------------------------------
// Required include files.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <IL/il.h>
#include <stdio.h>
/* We would need ILU just because of iluErrorString() function... */
/* So make it possible for both with and without ILU! */
#ifdef ILU_ENABLED
#include <IL/ilu.h>
#define PRINT_ERROR_MACRO printf("Error: %s\n", iluErrorString(Error))
#else /* not ILU_ENABLED */
#define PRINT_ERROR_MACRO printf("Error: 0x%X\n", (unsigned int)Error)
#endif /* not ILU_ENABLED */
ILboolean ILAPIENTRY LoadFunction(const char *FileName)
{
ILuint Width, Height;
FILE *f = fopen(FileName, "rb");
if (f == NULL)
return IL_FALSE;
fread(&Width, 1, 4, f);
fread(&Height, 1, 4, f);
if (!ilTexImage(Width, Height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL)) {
fclose(f);
return IL_FALSE;
}
// Set the origin via the register functions.
ilRegisterOrigin(IL_ORIGIN_UPPER_LEFT);
fread(ilGetData(), 1, Width * Height * 3, f);
fclose(f);
return IL_TRUE;
}
int main(int argc, char **argv)
{
ILuint ImgId;
ILenum Error;
// We use the filename specified in the first argument of the command-line.
if (argc < 2) {
printf("Please specify a file to open.\n");
return 1;
}
// Check if the shared lib's version matches the executable's version.
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) {
printf("DevIL version is different...exiting!\n");
return 2;
}
// Initialize DevIL.
ilInit();
// Set the loading function here.
ilRegisterLoad("xxx", LoadFunction);
// Generate the main image name to use.
ilGenImages(1, &ImgId);
// Bind this image name.
ilBindImage(ImgId);
// Loads the image specified by File into the image named by ImgId.
if (!ilLoadImage(argv[1])) {
printf("Could not open file...exiting.\n");
return 3;
}
// Display the image's dimensions to the end user.
printf("Width: %d Height: %d Depth: %d Bpp: %d\n", ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));
// Enable this to let us overwrite the destination file if it already exists.
ilEnable(IL_FILE_OVERWRITE);
// If argv[2] is present, we save to this filename, else we save to test.tga.
if (argc > 2)
ilSaveImage(argv[2]);
else
ilSaveImage("test.tga");
// Remove the loading function when we're done using it or want to change it.
// This isn't required here, since we're exiting, but here's how it's done:
ilRemoveLoad("xxx");
// We're done with the image, so let's delete it.
ilDeleteImages(1, &ImgId);
// Simple Error detection loop that displays the Error to the user in a human-readable form.
while ((Error = ilGetError())) {
PRINT_ERROR_MACRO;
}
return 0;
}
@@ -0,0 +1,389 @@
//-----------------------------------------------------------------------------
//
// ImageLib SDL Test Source
// Copyright (C) 2000 by Denton Woods
// Copyright (C) 2001 Nelson Rush.
// Last modified: 7/02/2001
//
// Filename: testil/sdltest/sdl_test.c
//
// Description: SDL test application for DevIL.
//
//-----------------------------------------------------------------------------
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#ifdef _DEBUG
#pragma comment(linker, "/NODEFAULTLIB:msvcrt.lib")
#endif//_DEBUG
#endif
/* Bring up a window and play with it */
#define BENCHMARK_SDL
#define NOTICE(X) printf("%s", X);
void DrawPict(SDL_Surface *screen, char *bmpfile,
int speedy, int flip, int nofade)
{
SDL_Surface *picture;
SDL_Rect dest, update;
int i, centered;
int ncolors;
SDL_Color *colors, *cmap;
/* Load the image into a surface */
if ( bmpfile == NULL ) {
bmpfile = "sample.bmp"; /* Sample image */
}
fprintf(stderr, "Loading picture: %s\n", bmpfile);
//picture = SDL_LoadBMP(bmpfile);
picture = ilutSDLSurfaceLoadImage(bmpfile);
if ( picture == NULL ) {
fprintf(stderr, "Couldn't load %s: %s\n", bmpfile,
SDL_GetError());
return;
}
/* Set the display colors -- on a hicolor display this is a no-op */
if ( picture->format->palette ) {
ncolors = picture->format->palette->ncolors;
colors = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
cmap = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
memcpy(colors, picture->format->palette->colors,
ncolors*sizeof(SDL_Color));
} else {
int r, g, b;
/* Allocate 256 color palette */
ncolors = 256;
colors = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
cmap = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
/* Set a 3,3,2 color cube */
for ( r=0; r<8; ++r ) {
for ( g=0; g<8; ++g ) {
for ( b=0; b<4; ++b ) {
i = ((r<<5)|(g<<2)|b);
colors[i].r = r<<5;
colors[i].g = g<<5;
colors[i].b = b<<6;
}
}
}
}
NOTICE("testwin: setting colors\n");
if ( ! SDL_SetColors(screen, colors, 0, ncolors) &&
(screen->format->palette != NULL) ) {
fprintf(stderr,
"Warning: Couldn't set all of the colors, but SDL will map the image\n"
" (colormap fading will suffer - try the -warp option)\n"
);
}
/* Set the screen to black (not really necessary) */
if ( SDL_LockSurface(screen) == 0 ) {
Uint32 black;
Uint8 *pixels;
black = SDL_MapRGB(screen->format, 0, 0, 0);
pixels = (Uint8 *)screen->pixels;
for ( i=0; i<screen->h; ++i ) {
memset(pixels, black,
screen->w*screen->format->BytesPerPixel);
pixels += screen->pitch;
}
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
/* Display the picture */
if ( speedy ) {
SDL_Surface *displayfmt;
fprintf(stderr, "Converting picture\n");
displayfmt = SDL_DisplayFormat(picture);
if ( displayfmt == NULL ) {
fprintf(stderr,
"Couldn't convert image: %s\n", SDL_GetError());
goto done;
}
SDL_FreeSurface(picture);
picture = displayfmt;
}
printf("(image surface located in %s memory)\n",
(picture->flags&SDL_HWSURFACE) ? "video" : "system");
centered = (screen->w - picture->w)/2;
if ( centered < 0 ) {
centered = 0;
}
dest.y = (screen->h - picture->h)/2;
dest.w = picture->w;
dest.h = picture->h;
NOTICE("testwin: moving image\n");
for ( i=0; i<=centered; ++i ) {
dest.x = i;
update = dest;
if ( SDL_BlitSurface(picture, NULL, screen, &update) < 0 ) {
fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
break;
}
if ( flip ) {
SDL_Flip(screen);
} else {
SDL_UpdateRects(screen, 1, &update);
}
}
#ifdef SCREENSHOT
if ( SDL_SaveBMP(screen, "screen.bmp") < 0 )
printf("Couldn't save screen: %s\n", SDL_GetError());
#endif
#ifndef BENCHMARK_SDL
/* Let it sit there for a while */
SDL_Delay(5*1000);
#endif
/* Fade the colormap */
if ( ! nofade ) {
int maxstep;
SDL_Color final;
SDL_Color palcolors[256];
struct {
Sint16 r, g, b;
} cdist[256];
NOTICE("testwin: fading out...\n");
memcpy(cmap, colors, ncolors*sizeof(SDL_Color));
maxstep = 32-1;
final.r = 0xFF;
final.g = 0x00;
final.b = 0x00;
memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
for ( i=0; i<ncolors; ++i ) {
cdist[i].r = final.r-palcolors[i].r;
cdist[i].g = final.g-palcolors[i].g;
cdist[i].b = final.b-palcolors[i].b;
}
for ( i=0; i<=maxstep/2; ++i ) { /* halfway fade */
int c;
for ( c=0; c<ncolors; ++c ) {
colors[c].r =
palcolors[c].r+((cdist[c].r*i))/maxstep;
colors[c].g =
palcolors[c].g+((cdist[c].g*i))/maxstep;
colors[c].b =
palcolors[c].b+((cdist[c].b*i))/maxstep;
}
SDL_SetColors(screen, colors, 0, ncolors);
SDL_Delay(1);
}
final.r = 0x00;
final.g = 0x00;
final.b = 0x00;
memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
for ( i=0; i<ncolors; ++i ) {
cdist[i].r = final.r-palcolors[i].r;
cdist[i].g = final.g-palcolors[i].g;
cdist[i].b = final.b-palcolors[i].b;
}
maxstep /= 2;
for ( i=0; i<=maxstep; ++i ) { /* finish fade out */
int c;
for ( c=0; c<ncolors; ++c ) {
colors[c].r =
palcolors[c].r+((cdist[c].r*i))/maxstep;
colors[c].g =
palcolors[c].g+((cdist[c].g*i))/maxstep;
colors[c].b =
palcolors[c].b+((cdist[c].b*i))/maxstep;
}
SDL_SetColors(screen, colors, 0, ncolors);
SDL_Delay(1);
}
for ( i=0; i<ncolors; ++i ) {
colors[i].r = final.r;
colors[i].g = final.g;
colors[i].b = final.b;
}
SDL_SetColors(screen, colors, 0, ncolors);
NOTICE("testwin: fading in...\n");
memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
for ( i=0; i<ncolors; ++i ) {
cdist[i].r = cmap[i].r-palcolors[i].r;
cdist[i].g = cmap[i].g-palcolors[i].g;
cdist[i].b = cmap[i].b-palcolors[i].b;
}
for ( i=0; i<=maxstep; ++i ) { /* 32 step fade in */
int c;
for ( c=0; c<ncolors; ++c ) {
colors[c].r =
palcolors[c].r+((cdist[c].r*i))/maxstep;
colors[c].g =
palcolors[c].g+((cdist[c].g*i))/maxstep;
colors[c].b =
palcolors[c].b+((cdist[c].b*i))/maxstep;
}
SDL_SetColors(screen, colors, 0, ncolors);
SDL_Delay(1);
}
NOTICE("testwin: fading over\n");
}
done:
/* Free the picture and return */
SDL_FreeSurface(picture);
free(colors); free(cmap);
return;
}
int main(int argc, char *argv[])
{
SDL_Surface *screen;
/* Options */
int speedy, flip, nofade;
int delay;
int w, h;
int desired_bpp;
Uint32 video_flags;
#ifdef BENCHMARK_SDL
Uint32 then, now;
#endif
/* Set default options and check command-line */
ilInit();
speedy = 0;
flip = 0;
nofade = 0;
delay = 1;
w = 640;
h = 480;
desired_bpp = 0;
video_flags = 0;
while ( argc > 1 ) {
if ( strcmp(argv[1], "-speedy") == 0 ) {
speedy = 1;
argv += 1;
argc -= 1;
} else
if ( strcmp(argv[1], "-nofade") == 0 ) {
nofade = 1;
argv += 1;
argc -= 1;
} else
if ( strcmp(argv[1], "-delay") == 0 ) {
if ( argv[2] ) {
delay = atoi(argv[2]);
argv += 2;
argc -= 2;
} else {
fprintf(stderr,
"The -delay option requires an argument\n");
exit(1);
}
} else
if ( strcmp(argv[1], "-width") == 0 ) {
if ( argv[2] && ((w = atoi(argv[2])) > 0) ) {
argv += 2;
argc -= 2;
} else {
fprintf(stderr,
"The -width option requires an argument\n");
exit(1);
}
} else
if ( strcmp(argv[1], "-height") == 0 ) {
if ( argv[2] && ((h = atoi(argv[2])) > 0) ) {
argv += 2;
argc -= 2;
} else {
fprintf(stderr,
"The -height option requires an argument\n");
exit(1);
}
} else
if ( strcmp(argv[1], "-bpp") == 0 ) {
if ( argv[2] ) {
desired_bpp = atoi(argv[2]);
argv += 2;
argc -= 2;
} else {
fprintf(stderr,
"The -bpp option requires an argument\n");
exit(1);
}
} else
if ( strcmp(argv[1], "-warp") == 0 ) {
video_flags |= SDL_HWPALETTE;
argv += 1;
argc -= 1;
} else
if ( strcmp(argv[1], "-hw") == 0 ) {
video_flags |= SDL_HWSURFACE;
argv += 1;
argc -= 1;
} else
if ( strcmp(argv[1], "-flip") == 0 ) {
video_flags |= SDL_DOUBLEBUF;
argv += 1;
argc -= 1;
} else
if ( strcmp(argv[1], "-fullscreen") == 0 ) {
video_flags |= SDL_FULLSCREEN;
argv += 1;
argc -= 1;
} else
break;
}
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit); /* Clean up on exit */
/* Initialize the display */
screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
w, h, desired_bpp, SDL_GetError());
exit(1);
}
printf("Set %dx%dx%d mode\n",
screen->w, screen->h, screen->format->BitsPerPixel);
printf("(video surface located in %s memory)\n",
(screen->flags&SDL_HWSURFACE) ? "video" : "system");
if ( screen->flags & SDL_DOUBLEBUF ) {
printf("Double-buffering enabled\n");
flip = 1;
}
/* Set the window manager title bar */
SDL_WM_SetCaption("SDL test window", "testwin");
/* Do all the drawing work */
#ifdef BENCHMARK_SDL
then = SDL_GetTicks();
DrawPict(screen, argv[1], speedy, flip, nofade);
now = SDL_GetTicks();
printf("Time: %d milliseconds\n", now-then);
#else
DrawPict(screen, argv[1], speedy, flip, nofade);
#endif
SDL_Delay(delay*1000);
return(0);
}
@@ -0,0 +1,94 @@
//-----------------------------------------------------------------------------
//
// DevIL Source Example
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 4/22/2002
//
// Filename: examples/Simple Example/simple.c
//
// Description: Simplest implementation of an DevIL application.
// Loads an image and saves it to a new image.
// The images can be of any format and can be different.
//
//-----------------------------------------------------------------------------
// Required include files.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <IL/il.h>
#include <stdio.h>
/* We would need ILU just because of iluErrorString() function... */
/* So make it possible for both with and without ILU! */
#ifdef ILU_ENABLED
#include <IL/ilu.h>
#define PRINT_ERROR_MACRO printf("Error: %s\n", iluErrorString(Error))
#else /* not ILU_ENABLED */
#define PRINT_ERROR_MACRO printf("Error: 0x%X\n", (unsigned int)Error)
#endif /* not ILU_ENABLED */
int main(int argc, char **argv)
{
ILuint ImgId;
ILenum Error;
// We use the filename specified in the first argument of the command-line.
if (argc < 2) {
fprintf(stderr, "DevIL_test : DevIL simple command line application.\n");
fprintf(stderr, "Usage : DevIL_test <file> [output]\n");
fprintf(stderr, "Default output is test.tga\n");
return 1;
}
// Check if the shared lib's version matches the executable's version.
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) {
printf("DevIL version is different...exiting!\n");
return 2;
}
// Initialize DevIL.
ilInit();
#ifdef ILU_ENABLED
iluInit();
#endif
// Generate the main image name to use.
ilGenImages(1, &ImgId);
// Bind this image name.
ilBindImage(ImgId);
// Loads the image specified by File into the image named by ImgId.
if (!ilLoadImage(argv[1])) {
printf("Could not open file...exiting.\n");
return 3;
}
// Display the image's dimensions to the end user.
printf("Width: %d Height: %d Depth: %d Bpp: %d\n",
ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_DEPTH),
ilGetInteger(IL_IMAGE_BITS_PER_PIXEL));
// Enable this to let us overwrite the destination file if it already exists.
ilEnable(IL_FILE_OVERWRITE);
// If argv[2] is present, we save to this filename, else we save to test.tga.
if (argc > 2)
ilSaveImage(argv[2]);
else
ilSaveImage("test.tga");
// We're done with the image, so let's delete it.
ilDeleteImages(1, &ImgId);
// Simple Error detection loop that displays the Error to the user in a human-readable form.
while ((Error = ilGetError())) {
PRINT_ERROR_MACRO;}
return 0;
}
@@ -0,0 +1,379 @@
#ifdef _WIN32
#include <GL/freeglut.h>
#else
#include <GL/glut.h>
#endif
#include <IL/il.h>
#include <IL/ilu.h>
//#define ILUT_USE_OPENGL
#include <IL/ilut.h>
#include "3dtest.h"
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#ifdef _MSC_VER
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "freeglut.lib")
// Prevent the console window from popping up.
#pragma comment(linker, "/entry:mainCRTStartup")
#pragma comment(linker, "/subsystem:windows")
#endif
char *File;
ILint Width, Height, Depth, Window;
ILuint ActiveImage = 0;
int main(int argc, char** argv)
{
//char Test[6] = { 0, 0, 0, 0, 0, 0 };
if (argc < 2) {
//cout << "Please specify a filename." << endl;
return 1;
}
File = argv[1];
if (argc > 2) {
TransFactor = atoi(argv[2]) != 0 ? -atoi(argv[2]) : TransFactor;
}
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
ilGetInteger(ILU_VERSION_NUM) < ILU_VERSION ||
ilGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) {
//cout << "OpenIL version is different...exiting!" << endl;
return 2;
}
ilInit();
//ilEnable(IL_CONV_PAL);
ilutEnable(ILUT_OPENGL_CONV);
glutInit(&argc, argv);
ilGenImages(1, &ImgId);
ilBindImage(ImgId);
ilLoadImage(File);
// Generate the appropriate width x height less than or equal to MAX_X x MAX_Y.
// Instead of just clipping Width x Height to MAX_X x MAX_Y, we scale to
// an appropriate size, so the image isn't stretched/squished.
Width = ilGetInteger(IL_IMAGE_WIDTH);
Height = ilGetInteger(IL_IMAGE_HEIGHT);
if (Width > 0) { // Don't want a divide by 0...
if (Width > MAX_X) {
Width = MAX_X;
Height = (ILuint)(MAX_X / (ILfloat)ilGetInteger(IL_IMAGE_WIDTH) * Height);
}
}
if (Height > 0) { // Don't want a divide by 0...
if (Height > MAX_Y) {
Height = MAX_Y;
Width = (ILuint)(MAX_Y / (ILfloat)ilGetInteger(IL_IMAGE_HEIGHT) * Width);
}
}
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(Width, Height);
Window = glutCreateWindow("Open Image Library (OpenIL) Test");
glutDisplayFunc(DisplayFunc);
glutKeyboardFunc(KeyboardFunc);
glutSpecialFunc(KeySpecialFunc);
if (Setup() == IL_FALSE)
return 1;
// Enter the main (Free)GLUT processing loop
glutMainLoop();
CleanUp();
return 0;
}
void ResizeFunc(int NewWidth, int NewHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, NewWidth, NewHeight);
//glOrtho(0, Width, 0, Height, -100, 1);
SetPerspective(50.0f);
}
void DisplayFunc()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
SetPerspective(50.0f);
glTranslatef(0.0f, 0.0f, TransFactor);
glRotatef(Angle, 0.0f, 1.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D, TexID1);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3i(-Width, -Height, Depth);
glTexCoord2f(1.0f, 0.0f);
glVertex3i(Width, -Height, Depth);
glTexCoord2f(1.0f, 1.0f);
glVertex3i(Width, Height, Depth);
glTexCoord2f(0.0f, 1.0f);
glVertex3i(-Width, Height, Depth);
glEnd();
glBindTexture(GL_TEXTURE_2D, TexID2);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3i(-Width, -Height, Depth);
glTexCoord2f(1.0f, 0.0f);
glVertex3i(-Width, -Height, -Depth);
glTexCoord2f(1.0f, 1.0f);
glVertex3i(-Width, Height, -Depth);
glTexCoord2f(0.0f, 1.0f);
glVertex3i(-Width, Height, Depth);
glEnd();
glBindTexture(GL_TEXTURE_2D, TexID3);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3i(Width, -Height, Depth);
glTexCoord2f(1.0f, 0.0f);
glVertex3i(Width, -Height, -Depth);
glTexCoord2f(1.0f, 1.0f);
glVertex3i(Width, Height, -Depth);
glTexCoord2f(0.0f, 1.0f);
glVertex3i(Width, Height, Depth);
glEnd();
glBindTexture(GL_TEXTURE_2D, TexID4);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3i(-Width, -Height, -Depth);
glTexCoord2f(1.0f, 0.0f);
glVertex3i(Width, -Height, -Depth);
glTexCoord2f(1.0f, 1.0f);
glVertex3i(Width, Height, -Depth);
glTexCoord2f(0.0f, 1.0f);
glVertex3i(-Width, Height, -Depth);
glEnd();
glFlush();
glFinish();
glutSwapBuffers();
}
void IdleFunc()
{
glutShowWindow();
glutPostRedisplay();
}
void KeyboardFunc(unsigned char cChar, int nMouseX, int nMouseY)
{
if (cChar >= '0' && cChar <= '9') {
ActiveImage = cChar - '0';
CleanUp();
GenSides();
return;
}
if (cChar == '+' || cChar == '=') {
ActiveImage++;
CleanUp();
GenSides();
return;
}
if (cChar == '-' || cChar == '_') {
if (ActiveImage == 0)
return;
ActiveImage--;
CleanUp();
GenSides();
return;
}
CleanUp();
glutDestroyWindow(Window);
#ifndef _WIN32
/* Siigron: added exit(), since glutDestroyWindow() doesn't exit the
program with "normal" GLUT */
exit(0);
#endif
}
void KeySpecialFunc(int Key, int x, int y)
{
switch (Key)
{
case GLUT_KEY_UP:
TransFactor += 10.0f;
//glTranslatef(0.0f, 0.0f, 10.0f);
break;
case GLUT_KEY_DOWN:
TransFactor -= 10.0f;
//glTranslatef(0.0f, 0.0f, -10.0f);
break;
case GLUT_KEY_RIGHT:
Angle += 10.0f;
//glRotatef(10.0f, 0.0f, 1.0f, 0.0f);
break;
case GLUT_KEY_LEFT:
Angle -= 10.0f;
//glRotatef(-10.0f, 0.0f, 1.0f, 0.0f);
break;
}
glutPostRedisplay();
return;
}
#define PI 3.14159265
void SetPerspective(float Fov)
{
float fov = (float)tan(Fov * .5f * PI / 180.0f);
float Aspect = 0.0f;
if (Height != 0)
Aspect = Width / (float)Height;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-fov * Aspect, fov * Aspect, -fov, fov, 1.0f, 10000.0f);
return;
}
ILboolean Setup()
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); // or should this be GL_LESS?
glClearDepth(1);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
ilutRenderer(ILUT_OPENGL);
if (!GenSides())
return IL_FALSE;
TransFactor += -Depth;
glTranslatef(0.0f, 0.0f, -100.0f);
return IL_TRUE;
}
ILboolean GenSides()
{
ILubyte *Buffer, *Data, Bpp, Bpc;
ILuint TempImage;
ILenum Format, Type;
ILint SizePlane, Bps, c, y, z, i;
ilActiveImage(ActiveImage);
Bpp = ilGetInteger(IL_IMAGE_BPP);
Bpc = ilGetInteger(IL_IMAGE_BPC);
Format = ilGetInteger(IL_IMAGE_FORMAT);
Type = ilGetInteger(IL_IMAGE_TYPE);
// Front
TexID1 = ilutGLBindTexImage();
Width = ilGetInteger(IL_IMAGE_WIDTH);
Height = ilGetInteger(IL_IMAGE_HEIGHT);
Depth = ilGetInteger(IL_IMAGE_DEPTH);
ilGenImages(1, &TempImage);
SizePlane = ilGetInteger(IL_IMAGE_PLANESIZE);
SizePlane = Width * Height * Bpp * Bpc;
Bps = Width * Bpp * Bpc;
Data = ilGetData();
// Left
i = 0;
Buffer = (ILubyte*)malloc(Height * Depth * Bpp * Bpc);
for (y = 0; y < Height; y++) {
for (z = 0; z < Depth; z++) {
for (c = 0; c < Bpp * Bpc; c++) {
Buffer[i++] = Data[z * SizePlane + y * Bps + c];
}
}
}
ilBindImage(TempImage);
ilTexImage(Depth, Height, 1, Bpp, Format, Type, Buffer);
TexID2 = ilutGLBindTexImage();
free(Buffer);
// Right
ilBindImage(ImgId);
ilActiveImage(ActiveImage);
i = 0;
Buffer = (ILubyte*)malloc(Height * Depth * Bpp * Bpc);
for (y = 0; y < Height; y++) {
for (z = 0; z < Depth; z++) {
for (c = 0; c < Bpp * Bpc; c++) {
Buffer[i++] = Data[z * SizePlane + y * Bps + (Width - 1) * Bpp * Bpc + c];
}
}
}
ilBindImage(TempImage);
ilTexImage(Depth, Height, 1, Bpp, Format, Type, Buffer);
TexID3 = ilutGLBindTexImage();
free(Buffer);
// Back
ilBindImage(ImgId);
ilActiveImage(ActiveImage);
Buffer = (ILubyte*)malloc(Width * Height * Bpp * Bpc);
ilCopyPixels(0, 0, Depth-1, Width, Height, 1, Format, Type, Buffer);
ilBindImage(TempImage);
ilTexImage(Width, Height, 1, Bpp, Format, Type, Buffer);
TexID4 = ilutGLBindTexImage();
free(Buffer);
//ilDeleteImages(1, &ImgId);
ilDeleteImages(1, &TempImage);
ilBindImage(ImgId);
return IL_TRUE;
}
void CleanUp()
{
glDeleteTextures(1, &TexID1);
glDeleteTextures(1, &TexID2);
glDeleteTextures(1, &TexID3);
glDeleteTextures(1, &TexID4);
return;
}
void ExitClean()
{
if (!bCleaned) {
glDeleteTextures(1, &TexID1);
glDeleteTextures(1, &TexID2);
glDeleteTextures(1, &TexID3);
glDeleteTextures(1, &TexID4);
ilDeleteImages(1, &ImgId);
}
bCleaned = IL_TRUE;
return;
}
@@ -0,0 +1,25 @@
#ifndef TEST3D_H
#define TEST3D_H
#define MAX_X 640
#define MAX_Y 480
void DisplayFunc(void);
void CleanUp(void);
void ExitClean(void);
void ResizeFunc(int NewWidth, int NewHeight);
void IdleFunc(void);
void KeyboardFunc(unsigned char cChar, int nMouseX, int nMouseY);
void KeySpecialFunc(int Key, int x, int y);
void SetPerspective(float Fov);
ILboolean Setup(void);
ILboolean GenSides(void);
ILboolean bCleaned = IL_FALSE;
GLuint TexID1 = 0, TexID2 = 0, TexID3 = 0, TexID4 = 0;
ILuint ImgId;
float Angle = 0.0, TransFactor = -470.0;
#endif//TEST3D_H
@@ -0,0 +1,162 @@
#ifdef _DEBUG
#define IL_DEBUG
#endif//_DEBUG
#include <IL/il.h>
#include <windows.h>
#include <direct.h>
#include <string>
using namespace std;
TCHAR *ImageExtArray[] =
{
L"jpe", L"jpg", L"jpeg",
L"bmp",
L"ico",
L"pbm", L"pgm", L"pnm", L"ppm",
L"png",
L"bw", L"rgb", L"rgba", L"sgi",
L"tga", L"tif", L"tiff",
L"pcx",
NULL
};
void ParseDirs(const string &_Dir, char **ExtList, char *ConvExt, bool Recurse);
bool IsDir(WIN32_FIND_DATA *_Data);
char *GetExtension(const char *FileName);
bool CheckExtension(char *Arg, char *Ext);
TCHAR *Ext;
string NewExt;
int i, j;
//void BatchConv(TCHAR *Directory, TCHAR *ExtList, TCHAR *ConvExt, bool Recurse)
//{
// ILuint Id, OrigId;
// ilGenImages(1, &Id);
// OrigId = ilGetInteger(IL_CUR_IMAGE);
// ilBindImage(Id);
// if (ExtList == NULL)
// ParseDirs(string(Directory), ImageExtArray, ConvExt, Recurse);
// else {
// /*char **List = ConvertExtList(ExtList);
// ParseDirs(string(Directory), ConvertExtList(ExtList), ConvExt, Recurse);
// DestroyExtList(List);*/
// }
// ilDeleteImages(1, &Id);
// ilBindImage(OrigId);
// return;
//}
//
//
//void ParseDirs(const string &_Dir, TCHAR **ExtList, TCHAR *ConvExt, bool Recurse)
//{
// HANDLE Search;
// WIN32_FIND_DATA FindData;
//
// _chdir(_Dir.c_str());
// Search = FindFirstFile("*.*", &FindData);
//
// do {
// if (!strcmp(FindData.cFileName, ".") || !strcmp(FindData.cFileName, ".."))
// continue;
// if (IsDir(&FindData) && Recurse) {
// _chdir(FindData.cFileName);
// string NewDir = _Dir + string("\\");
// NewDir += FindData.cFileName;
// ParseDirs(NewDir, ExtList, ConvExt, Recurse);
// _chdir("..");
// }
// Ext = GetExtension(FindData.cFileName);
// if (Ext == NULL)
// continue;
// if (!_stricmp(Ext, ConvExt)) // Already has that extension.
// continue;
// for (j = 0; ExtList[j] != NULL; j++) {
// if (CheckExtension(FindData.cFileName, ExtList[j])) {
// string NewName;
// for (i = 0; i < Ext - FindData.cFileName; i++) {
// NewName += FindData.cFileName[i];
// }
// NewName += ConvExt;
// if (!ilLoadImage(FindData.cFileName))
// break;
// ilSaveImage((TCHAR*)NewName.c_str());
// break;
// }
// }
// } while (FindNextFile(Search, &FindData));
//
// FindClose(Search);
// return;
//}
//
//
//// Is the file actually a directory?
//bool IsDir(WIN32_FIND_DATA *_Data)
//{
// if (_Data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// return true;
// return false;
//}
TCHAR *GetExtension(const TCHAR *FileName)
{
bool PeriodFound = false;
TCHAR *Ext = (TCHAR*)FileName;
long i, Len = (long)wcslen(FileName);
if (FileName == NULL || !Len) // if not a good filename/extension, exit early
return NULL;
Ext += Len; // start at the end
for (i = Len; i >= 0; i--) {
if (*Ext == '.') { // try to find a period
PeriodFound = true;
break;
}
Ext--;
}
if (!PeriodFound) // if no period, no extension
return NULL;
return Ext+1;
}
// Simple function to test if a filename has a given extension, disregarding case
bool CheckExtension(TCHAR *Arg, TCHAR *Ext)
{
bool PeriodFound = false;
TCHAR *Argu = Arg; // pointer to arg so we don't destroy arg
unsigned int i;
if (Arg == NULL || Ext == NULL || !wcslen(Arg) || !wcslen(Ext)) // if not a good filename/extension, exit early
return false;
Argu += wcslen(Arg); // start at the end
for (i = (int)wcslen(Arg); i >= 0; i--) {
if (*Argu == '.') { // try to find a period
PeriodFound = true;
break;
}
Argu--;
}
if (!PeriodFound) // if no period, no extension
return false;
if (!_wcsicmp(Argu+1, Ext)) // extension and ext match?
return true;
return false; // if all else fails, return IL_FALSE
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,3 @@
#pragma once
#include "resource.h"
@@ -0,0 +1,255 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource."
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG_ABOUT DIALOGEX 0, 0, 278, 220
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About DevIL"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,113,198,50,14
GROUPBOX "Info",IDC_STATIC,7,7,264,69
GROUPBOX "Errors",IDC_STATIC,7,86,264,76
LTEXT "Vendor:",IDC_STATIC,27,22,27,8
LTEXT "Version:",IDC_STATIC,26,35,26,8
CTEXT "",IDC_ERROR1,40,98,79,8
LTEXT "Vendor",IDC_ABOUT_VENDOR,68,22,126,8
LTEXT "Version String",IDC_ABOUT_VER_STRING,68,35,125,8
LTEXT "Version Num",IDC_ABOUT_VER_NUM,68,46,38,8
CTEXT "",IDC_ERROR4,158,98,79,8
CTEXT "",IDC_ERROR6,158,142,79,8
CTEXT "",IDC_ERROR2,40,119,79,8
CTEXT "",IDC_ERROR5,158,120,79,8
CTEXT "",IDC_ERROR3,40,142,79,8
LTEXT "Visit the DevIL website at http://openil.sf.net.",IDC_OPENIL_LINK,56,182,164,8
ICON "",IDC_STATIC,243,15,20,20
END
IDD_DIALOG_FILTER DIALOGEX 0, 0, 186, 95
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog Options"
FONT 8, "MS Sans Serif", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,129,14,50,14
PUSHBUTTON "Cancel",IDCANCEL,129,31,50,14
LTEXT "Enter number of iterations, monkey foo!",IDC_FILTER_DESC_TEXT,21,14,95,31
EDITTEXT IDC_FILTER_EDIT,13,54,160,14,ES_AUTOHSCROLL
END
IDD_DIALOG_RESIZE DIALOGEX 0, 0, 266, 95
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Resize Options"
FONT 8, "MS Sans Serif", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,77,65,50,14
PUSHBUTTON "Cancel",IDCANCEL,137,65,50,14
LTEXT "Enter new image size:",IDC_STATIC,97,15,70,8
EDITTEXT IDC_EDIT_RESIZE_X,33,36,40,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT_RESIZE_Y,109,36,40,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT_RESIZE_Z,187,37,40,14,ES_AUTOHSCROLL
LTEXT "X:",IDC_STATIC,20,39,8,8
LTEXT "Y:",IDC_STATIC,96,38,8,8
LTEXT "Z:",IDC_STATIC,173,39,8,8
END
IDD_DIALOG_BATCHCONV DIALOGEX 0, 0, 200, 138
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Batch Conversion Options"
FONT 8, "MS Sans Serif", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,43,108,50,14
PUSHBUTTON "Cancel",IDCANCEL,107,108,50,14
LTEXT "Enter Directory:",IDC_FILTER_DESC_TEXT,21,14,95,14
EDITTEXT IDC_BATCH_DIR,21,30,160,14,ES_AUTOHSCROLL
CONTROL "Parse Subdirectories?",IDC_BATCH_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,57,89,85,10
LTEXT "Enter New Extension:",IDC_STATIC,21,55,69,8
EDITTEXT IDC_BATCH_NEWEXT,21,66,44,14,ES_AUTOHSCROLL
END
IDD_DIALOG_PROPERTIES DIALOGEX 0, 0, 243, 158
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Image Properties"
FONT 8, "MS Sans Serif", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,81,137,50,14
GROUPBOX "Info",IDC_STATIC,7,7,229,119
LTEXT "Filename:",IDC_STATIC,16,24,31,8
LTEXT "Width:",IDC_STATIC,25,43,22,8
LTEXT "Height:",IDC_STATIC,23,62,24,8
LTEXT "Depth:",IDC_STATIC,25,81,22,8
LTEXT "Filename",IDC_PROP_FILENAME,61,24,169,8
LTEXT "Width",IDC_PROP_WIDTH,61,43,42,8
LTEXT "Height",IDC_PROP_HEIGHT,61,62,42,8
LTEXT "Depth",IDC_PROP_DEPTH,61,81,42,8
LTEXT "Size:",IDC_STATIC,31,100,16,8
LTEXT "Size",IDC_PROP_SIZE,61,100,41,8
LTEXT "byte(s)",IDC_STATIC,111,100,22,8
LTEXT "pixel(s)",IDC_STATIC,111,81,22,8
LTEXT "pixel(s)",IDC_STATIC,111,62,22,8
LTEXT "pixel(s)",IDC_STATIC,111,43,22,8
END
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU1 MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...\tCtrl+O", ID_FILE_LOAD
MENUITEM "Open &URL...\tCtrl+U", ID_FILE_OPENURL
MENUITEM "&Save...\tCtrl+S", ID_FILE_SAVE
MENUITEM "&Image Properties", ID_FILE_PROPERTIES
MENUITEM "&Print", ID_FILE_PRINT
MENUITEM "E&xit\tEsc", ID_FILE_EXIT
END
POPUP "&Convert"
BEGIN
MENUITEM "&Colour Indexed", ID_CONVERT_PALETTE
MENUITEM "&Luminance", ID_CONVERT_LUMINANCE
MENUITEM "L&uminance Alpha", ID_CONVERT_LUMINANCEALPHA
MENUITEM "&Rgb", ID_CONVERT_RGB
MENUITEM "Rgba", ID_CONVERT_RGBA
MENUITEM "&Bgr", ID_CONVERT_BGR
MENUITEM "Bgra", ID_CONVERT_BGRA
MENUITEM "&Alpha", ID_EDIT_VIEWALPHA
MENUITEM "Batch Convert", ID_BATCHCONVERT
END
POPUP "&Edit"
BEGIN
MENUITEM "&Undo", ID_EDIT_UNDO
MENUITEM "Undo &Level", ID_EDIT_UNDOLEVEL
MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY
MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
MENUITEM "View Mipmap", ID_EDIT_VIEWMIPMAP
MENUITEM "View ImageNum", ID_EDIT_VIEWIMAGENUM
MENUITEM "Next Image", ID_EDIT_NEXT
MENUITEM "Previous Image", ID_EDIT_PREV
END
POPUP "&Tools"
BEGIN
MENUITEM "&Count Colours", ID_EFFECTS_COUNTCOLORS
MENUITEM "&Background Colour", ID_EFFECTSTOOLS_BACKGROUNDCOLOUR
POPUP "&Filters"
BEGIN
MENUITEM "&Alienify", ID_FILTER_ALIENIFY
MENUITEM "Apply &Wave", ID_EFFECTS_FILTERS_WAVE
POPUP "Blur"
BEGIN
MENUITEM "&Average", ID_FILTERS_BLUR_AVERAGE
MENUITEM "&Gaussian", ID_FILTERS_BLUR_GAUSSIAN
END
POPUP "Ed&ge Detect"
BEGIN
MENUITEM "&Emboss", ID_EFFECTS_FILTERS_EDGEDETECT_EMBOSS
MENUITEM "Prewitt", ID_EFFECTS_FILTERS_EDGEDETECT_PREWITT
MENUITEM "Sobel", ID_EFFECTS_FILTERS_EDGEDETECT_SOBEL
END
MENUITEM "&Emboss", ID_FILTER_EMBOSS
MENUITEM "E&qualize", ID_FILTER_EQUALIZE
MENUITEM "&Gamma Correct", ID_FILTER_GAMMACORRECT
MENUITEM "&Negative", ID_FILTER_NEGATIVE
MENUITEM "N&oise", ID_FILTER_NOISE
MENUITEM "&Pixelize", ID_FILTER_PIXELIZE
MENUITEM "&Sharpen", ID_FILTER_SHARPEN
END
MENUITEM "Fli&p", ID_EFFECTS_FLIP
MENUITEM "&Mirror", ID_EFFECTS_MIRROR
MENUITEM "&Rotate", ID_EFFECTS_FILTERS_ROTATE
MENUITEM "&Scale", ID_EFFECTS_FILTERS_SCALE
MENUITEM "&ScaleBOX", ID_EFFECTS_FILTERS_SCALEBOX
END
POPUP "&Help"
BEGIN
MENUITEM "&About", ID_HELP_ABOUT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MENU1 ACCELERATORS
BEGIN
"C", ID_EDIT_COPY, VIRTKEY, CONTROL
"O", ID_FILE_LOAD, VIRTKEY, CONTROL
"S", ID_FILE_SAVE, VIRTKEY, CONTROL
"U", ID_FILE_OPENURL, VIRTKEY, CONTROL
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "./resources/DevIL Logo.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.\0"
END
3 TEXTINCLUDE
BEGIN
"\r\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
@@ -0,0 +1,81 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by windows_example.rc
//
#define IDR_MENU1 101
#define IDI_ICON1 102
#define IDR_ACCELERATOR1 103
#define IDD_DIALOG_FILTER 104
#define IDC_FILTER_EDIT 1001
#define IDC_FILTER_DESC_TEXT 1002
#define ID_FILE_OPEN40001 40001
#define ID_FILE_OPENURL 40002
#define ID_FILE_SAVE40003 40003
#define ID_FILE_IMAGEPROPERTIES 40004
#define ID_FILE_PRINT40005 40005
#define ID_FILE_EXIT 40006
#define ID_EDIT_UNDO40007 40007
#define ID_EDIT_UNDOLEVEL 40008
#define ID_EDIT_COOPY 40009
#define ID_EDIT_PASTE40010 40010
#define ID_EDIT_VIEWMIPMAP 40011
#define ID_EDIT_VIEWIMAGENUMBER 40012
#define ID_EDIT_NEXTIMAGE 40013
#define ID_EDIT_C 40014
#define ID_CONVERT_COLORINDEXED 40015
#define ID_CONVERT_LUMINANCE 40016
#define ID_CONVERT_LUMINANCEALPHA 40017
#define ID_CONVERT_RGB 40018
#define ID_CONVERT_RGBA 40019
#define ID_CONVERT_BGR 40020
#define ID_CONVERT_BGRA 40021
#define ID_CONVERT_ALLPHA 40022
#define ID_CONVERT_BATCHCONVERT 40023
#define ID_CONVERT_UNSIGNEDBYTE 40024
#define ID_CONVERT_UNSIGNEDBYTE40025 40025
#define ID_CONVERT_UNSIGNEDSHORT 40026
#define ID_CONVERT_FLOAT 40027
#define ID_CONVERT_DOUBLE 40028
#define ID_CONVERT_HALF 40029
#define ID_HELP_ABOUT 40030
#define ID_TOOLS_COUNTCOLORS 40031
#define ID_TOOLS_BACKGROUNDCOLOR 40032
#define ID_TOOLS_FILTERS 40033
#define ID_TOOLS_FLIP 40034
#define ID_TOOLS_MIRROR 40035
#define ID_TOOLS_ROTATE 40036
#define ID_TOOLS_SCALE 40037
#define ID_TOOLS_SCALEBOX 40038
#define ID_FILTERS_ALIENIFY 40039
#define ID_FILTERS_APPLYWAVE 40040
#define ID_FILTERS_BLUR 40041
#define ID_FILTERS_EDGEDETECT 40042
#define ID_FILTERS_EMBOSS 40043
#define ID_FILTERS_EQUALIZE 40044
#define ID_FILTERS_GAMMACORRECT 40045
#define ID_FILTERS_NEGATIVE 40046
#define ID_FILTERS_NOISE 40047
#define ID_FILTERS_PIXELIZE 40048
#define ID_FILTERS_SHARPEN 40049
#define ID_EDIT_VIEWFACE 40050
#define ID_EDIT_VIEWBASEIMAGE 40051
#define ID_CONVERT_ALPHA 40052
#define ID_CONVERT_UNSIGNEDINT 40053
#define ID_EDIT_COPY40054 40054
#define ID_EDIT_PREVIOUSIMAGE 40055
#define ID_FILTERS_BLURGAUSSIAN 40064
#define ID_FILTERS_BLURAVERAGE 40065
#define ID_EDGEDETECT_SOBEL 40066
#define ID_EDGEDETECT_PREWITT 40067
#define ID_EDGEDETECT_EMBOSS 40068
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40069
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB