/
ImageLoader.cpp
74 lines (59 loc) · 1.51 KB
/
ImageLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// ImageLoader.cpp: implementation of the ImageLoader class.
//
//////////////////////////////////////////////////////////////////////
#include "ijl.h"
#include "jpeg.h"
#include "png.h"
#include "Stream.h"
#include "ImageLoader.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/*
some day this will be a texturepool class ;)
*/
ImageLoader::ImageLoader()
{
}
ImageLoader::~ImageLoader()
{
}
void ImageLoader::error(String txt)
{
ShowCursor (1); // show cursor
MessageBox(0, txt.c_String(), "Error", MB_OK|MB_ICONERROR);
PostQuitMessage(0);
}
GLTexture * ImageLoader::loadJPG(String name, int blending)
{
unsigned long *tex;
int x,y;
if (!DecodeJPGFileToGeneralBuffer(name.c_String(),&x,&y,(unsigned char **)&tex))
{
error(name+" error loading jpeg.");
return NULL;
}
unsigned char *tchar=(unsigned char *)tex;
for (int i=0;i<x*y;i++) // vaihdetaan punainen ja sininen keskenään. bgr -> rgb
{
int r,b;
r=tchar[i*3]; b=tchar[i*3+2];
tchar[i*3 ]=b; // pun
tchar[i*3+2]=r; // sin
}
GLTexture *tekstuuri=new GLTexture(tex,x,y,24,blending);
return tekstuuri;
}
GLTexture * ImageLoader::loadPNG(String name, int blending)
{
unsigned long *tex;
int x=-1,y;
loadpng32((char *)name.c_String(), x,y, (unsigned int*&)tex);
if (x==-1)
{
error(name+" error loading png.");
return NULL;
}
GLTexture *tekstuuri=new GLTexture(tex,x,y,32,blending);
return tekstuuri;
}