3 static GLuint textures
[1] = {0};
5 static void glEnable2D () {
7 glGetIntegerv(GL_VIEWPORT
, viewport
);
8 glMatrixMode(GL_PROJECTION
);
11 glOrtho(viewport
[0], viewport
[0]+viewport
[2],
12 viewport
[1]+viewport
[3], viewport
[1], -1, 1);
13 glMatrixMode(GL_MODELVIEW
);
16 glPushAttrib(GL_DEPTH_BUFFER_BIT
|GL_LIGHTING_BIT
);
17 glDisable(GL_DEPTH_TEST
);
18 glDisable(GL_LIGHTING
);
21 static void glDisable2D () {
23 glMatrixMode(GL_PROJECTION
);
25 glMatrixMode(GL_MODELVIEW
);
29 void GLInit (int w
, int h
) {
30 glViewport(0, 0, w
, h
);
31 glDisable(GL_LIGHTING
);
33 glDisable(GL_DEPTH_TEST
);
34 glClearColor(0.0, 0.0, 0.0, 1.0);
35 glEnable(GL_TEXTURE_2D
);
38 glGenTextures(1, textures
);
39 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
40 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
41 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
42 glClear(GL_COLOR_BUFFER_BIT
);
46 glDeleteTextures(1, textures
);
50 void GLScaleSurface(SDL_Surface
*source
, SDL_Surface
*dest
, uint32_t pix_ratio
) {
51 uint32_t src_w
= source
->w
;
52 uint32_t src_h
= source
->h
;
55 uint32_t dst_w
= dest
->w
;
56 uint32_t dst_h
= dest
->h
;
57 uint32_t x_ratio
, y_ratio
;
58 uint32_t x_factor
, y_factor
;
60 if (pix_ratio
< 0x10000UL
) {
62 y_factor
= 0x10000UL
/ pix_ratio
;
64 x_factor
= pix_ratio
/ 0x10000UL
;
68 x_ratio
= (dst_w
<< 16) / (src_w
* x_factor
);
69 y_ratio
= (dst_h
<< 16) / (src_h
* y_factor
);
70 if (x_ratio
< y_ratio
) {
71 dst_h
= (src_h
* x_ratio
* y_factor
) >> 16;
72 dst_y
= (dest
->h
- dst_h
) >> 1;
74 dst_w
= (src_w
* y_ratio
* x_factor
) >> 16;
75 dst_x
= (dest
->w
- dst_w
) >> 1;
78 SDL_LockSurface(source
);
79 glTexImage2D(GL_TEXTURE_2D
, 0, 4, src_w
, src_h
, 0, GL_RGBA
,
80 GL_UNSIGNED_BYTE
, source
->pixels
);
81 SDL_UnlockSurface(source
);
85 glVertex2i(dst_x
, dst_y
);
87 glVertex2i(dst_x
+ dst_w
, dst_y
);
89 glVertex2i(dst_x
+ dst_w
, dst_y
+ dst_h
);
91 glVertex2i(dst_x
, dst_y
+ dst_h
);