Some "cast to pointer from integer of different size" warnings removed.
[AROS-Contrib.git] / MultiMedia / cdxlplay / opengl.c
blobcbb5787471124ccd6c760c44ebf00b5e1704a4f4
1 #include "cdxlplay.h"
3 static GLuint textures[1] = {0};
5 static void glEnable2D () {
6 GLint viewport[4];
7 glGetIntegerv(GL_VIEWPORT, viewport);
8 glMatrixMode(GL_PROJECTION);
9 glPushMatrix();
10 glLoadIdentity();
11 glOrtho(viewport[0], viewport[0]+viewport[2],
12 viewport[1]+viewport[3], viewport[1], -1, 1);
13 glMatrixMode(GL_MODELVIEW);
14 glPushMatrix();
15 glLoadIdentity();
16 glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_LIGHTING_BIT);
17 glDisable(GL_DEPTH_TEST);
18 glDisable(GL_LIGHTING);
21 static void glDisable2D () {
22 glPopAttrib();
23 glMatrixMode(GL_PROJECTION);
24 glPopMatrix();
25 glMatrixMode(GL_MODELVIEW);
26 glPopMatrix();
29 void GLInit (int w, int h) {
30 glViewport(0, 0, w, h);
31 glDisable(GL_LIGHTING);
32 glDisable(GL_DITHER);
33 glDisable(GL_DEPTH_TEST);
34 glClearColor(0.0, 0.0, 0.0, 1.0);
35 glEnable(GL_TEXTURE_2D);
36 glDisable(GL_BLEND);
37 glEnable2D();
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);
45 void GLExit () {
46 glDeleteTextures(1, textures);
47 glDisable2D();
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;
53 uint32_t dst_x = 0;
54 uint32_t dst_y = 0;
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) {
61 x_factor = 1;
62 y_factor = 0x10000UL / pix_ratio;
63 } else {
64 x_factor = pix_ratio / 0x10000UL;
65 y_factor = 1;
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;
73 } else {
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);
83 glBegin(GL_QUADS);
84 glTexCoord2i(0, 0);
85 glVertex2i(dst_x, dst_y);
86 glTexCoord2i(1, 0);
87 glVertex2i(dst_x + dst_w, dst_y);
88 glTexCoord2i(1, 1);
89 glVertex2i(dst_x + dst_w, dst_y + dst_h);
90 glTexCoord2i(0, 1);
91 glVertex2i(dst_x, dst_y + dst_h);
92 glEnd();