source: trunk/src/video.cpp @ 142

Last change on this file since 142 was 142, checked in by sam, 10 years ago

Disable depth test. We do our own management.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#ifdef WIN32
11#   define WIN32_LEAN_AND_MEAN
12#   include <windows.h>
13#endif
14#if defined __APPLE__ && defined __MACH__
15#   include <OpenGL/gl.h>
16#else
17#   define GL_GLEXT_PROTOTYPES
18#   include <GL/gl.h>
19#endif
20
21#include "video.h"
22
23/*
24 * Public Video class
25 */
26
27void Video::Setup(int width, int height)
28{
29    /* Initialise OpenGL */
30    glViewport(0, 0, width, height);
31
32    glEnable(GL_TEXTURE_2D);
33    glShadeModel(GL_SMOOTH);
34    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
35    glClearDepth(1.0);
36    glDisable(GL_DEPTH_TEST);
37    glDepthFunc(GL_LEQUAL);
38    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
39
40    glEnable(GL_BLEND);
41    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
42
43    /* Projection matrix: once and for all */
44    glMatrixMode(GL_PROJECTION);
45    glLoadIdentity();
46    glOrtho(0, width, height, 0, -(width + height), width + height);
47}
48
49void Video::Clear()
50{
51    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
52
53    /* Model view matrix: for each frame, just in case */
54    glMatrixMode(GL_MODELVIEW);
55    glLoadIdentity();
56}
57
58void Video::Capture(uint32_t *buffer)
59{
60    GLint v[4];
61    glGetIntegerv(GL_VIEWPORT, v);
62    int width = v[2], height = v[3];
63
64    glPixelStorei(GL_PACK_ROW_LENGTH, 0);
65    glPixelStorei(GL_PACK_ALIGNMENT, 1);
66
67    glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
68
69    for (int j = 0; j < height / 2; j++)
70        for (int i = 0; i < width; i++)
71        {
72            uint32_t tmp = buffer[j * width + i];
73            buffer[j * width + i] = buffer[(height - j - 1) * width + i];
74            buffer[(height - j - 1) * width + i] = tmp;
75        }
76}
77
78int Video::GetWidth()
79{
80    GLint v[4];
81    glGetIntegerv(GL_VIEWPORT, v);
82    return v[2];
83}
84
85int Video::GetHeight()
86{
87    GLint v[4];
88    glGetIntegerv(GL_VIEWPORT, v);
89    return v[3];
90}
91
Note: See TracBrowser for help on using the repository browser.