all repos — mgba @ 4659635fb57e27c15bc2419130d5e0c9542d6fef

mGBA Game Boy Advance Emulator

src/platform/qt/Display.cpp (view raw)

 1#include "Display.h"
 2
 3#include <QTimer>
 4
 5using namespace QGBA;
 6
 7static const GLint _glVertices[] = {
 8	0, 0,
 9	256, 0,
10	256, 256,
11	0, 256
12};
13
14static const GLint _glTexCoords[] = {
15	0, 0,
16	1, 0,
17	1, 1,
18	0, 1
19};
20
21Display::Display(QWidget* parent) : QGLWidget(QGLFormat(QGL::Rgba | QGL::DoubleBuffer), parent) {
22	setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
23	QTimer* timer = new QTimer(this);
24	connect(timer, SIGNAL(timeout()), this, SLOT(updateGL()));
25	timer->setInterval(0);
26	timer->start();
27}
28
29void Display::initializeGL() {
30	glEnable(GL_TEXTURE_2D);
31	glGenTextures(1, &m_tex);
32	glBindTexture(GL_TEXTURE_2D, m_tex);
33	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
34	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
35	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
36}
37
38void Display::draw(const QImage& image) {
39	makeCurrent();
40	glEnable(GL_TEXTURE_2D);
41	glBindTexture(GL_TEXTURE_2D, m_tex);
42	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.constBits());
43}
44
45void Display::paintGL() {
46	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
47	glEnableClientState(GL_VERTEX_ARRAY);
48	glVertexPointer(2, GL_INT, 0, _glVertices);
49	glTexCoordPointer(2, GL_INT, 0, _glTexCoords);
50	glMatrixMode (GL_PROJECTION);
51	glLoadIdentity();
52	glOrtho(0, 240, 160, 0, 0, 1);
53	glEnable(GL_TEXTURE_2D);
54	glBindTexture(GL_TEXTURE_2D, m_tex);
55	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
56}