2 * Copyright (C) 2003 Robert Kooima
4 * SUPER EMPTY BALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include <SDL/SDL_image.h>
20 /*---------------------------------------------------------------------------*/
22 static const GLenum format
[5] = {
30 int image_load(struct image
*image
, const char *filename
)
32 if ((image
->s
= IMG_Load(filename
)))
34 void *p
= image
->s
->pixels
;
37 int b
= image
->s
->format
->BytesPerPixel
;
40 glGenTextures(1, &image
->o
);
41 glBindTexture(GL_TEXTURE_2D
, image
->o
);
43 glTexImage2D(GL_TEXTURE_2D
, 0, b
, w
, h
, 0, f
, GL_UNSIGNED_BYTE
, p
);
45 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
46 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
48 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
49 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
56 int image_test(struct image
*image
)
58 return (image
->s
&& glIsTexture(image
->o
)) ? 1 : 0;
61 void image_free(struct image
*image
)
63 if (image
->o
) glDeleteTextures(1, &image
->o
);
64 if (image
->s
) SDL_FreeSurface(image
->s
);
70 /*---------------------------------------------------------------------------*/
72 void image_bind(struct image
*image
)
74 glBindTexture(GL_TEXTURE_2D
, image
->o
);
77 void image_rect(struct image
*image
,
79 double x1
, double y1
, double a
)
81 glMatrixMode(GL_PROJECTION
);
85 glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
87 glMatrixMode(GL_MODELVIEW
);
89 glBindTexture(GL_TEXTURE_2D
, image
->o
);
91 glPushAttrib(GL_ENABLE_BIT
);
93 glDisable(GL_LIGHTING
);
94 glDisable(GL_DEPTH_TEST
);
95 glEnable(GL_COLOR_MATERIAL
);
99 glColor4d(1.0, 1.0, 1.0, a
);
101 glTexCoord2d(0.0, 1.0); glVertex2d(x0
, y0
);
102 glTexCoord2d(1.0, 1.0); glVertex2d(x1
, y0
);
103 glTexCoord2d(1.0, 0.0); glVertex2d(x1
, y1
);
104 glTexCoord2d(0.0, 0.0); glVertex2d(x0
, y1
);
110 glMatrixMode(GL_PROJECTION
);
114 glMatrixMode(GL_MODELVIEW
);
117 /*---------------------------------------------------------------------------*/