summaryrefslogtreecommitdiffstats
path: root/sdl/window.c
blob: 50bc72d0b28189019ee58e465217d7a97bd13597 (plain)
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
/* window.c
 *
 * Window
 *
 *
 */

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <GL/glew.h>
#include "window.h"

extern unsigned int bpp_w;
extern const unsigned int sdl_video_flags;

void window_resize(int w, int h)
{
    printf("window: resizing to %dx%d\n", w, h);
    GLfloat fAspect = (GLfloat) w / (GLfloat) h;
    if (h == 0)
        h = 1;
    glViewport(0, 0, w, h);

    /* reset coordinate system */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    /* produce the perspective projection */
    /* void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) */
    gluPerspective(40.0f, fAspect, 1.0, 40.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    /* this needs to be ran again, glut does it for you I suppose */
    SDL_SetVideoMode(w, h, bpp_w, sdl_video_flags);
}