Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////// HEADER
- #ifndef DISPLAY_H
- #define DISPLAY_H
- #include <QOpenGLWidget>
- #include <QOpenGLFunctions>
- class Display : public QOpenGLWidget
- {
- public:
- Display(QWidget* parent);
- ~Display();
- void render();
- static QSize displaySize() { return QSize(displayWidth, displayHeight); }
- void doTest();
- protected:
- void initializeGL() override;
- void paintGL() override;
- void resizeGL(int width, int height) override;
- private:
- static const quint32 displayWidth = 160;
- static const quint32 displayHeight = 144;
- void setPixelColor(quint32 x, quint32 y, quint32 color);
- QColor clearColor;
- quint32* textureBuffer;
- GLuint texture;
- };
- #endif // DISPLAY_H
- //////////////// SRC
- #include "display.h"
- Display::Display(QWidget* parent)
- : QOpenGLWidget(parent), clearColor(Qt::black)
- {
- textureBuffer = new quint32[displayWidth*displayHeight];
- setMinimumSize(displayWidth, displayHeight);
- }
- Display::~Display()
- {
- delete[] textureBuffer;
- }
- void Display::initializeGL()
- {
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_STENCIL_TEST);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_DITHER);
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, displayWidth);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, displayWidth, displayHeight, 0,
- GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, textureBuffer);
- }
- void Display::paintGL()
- {
- glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), 1.0f);
- glViewport(0, 0, width(), height());
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width(), 0, height(), -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, displayWidth, displayHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, textureBuffer);
- glBindTexture(GL_TEXTURE_2D, texture);
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f(0.0, 1.0);
- glVertex3i(0, 0, 0);
- glTexCoord2f(1.0, 1.0);
- glVertex3i(width(), 0, 0);
- glTexCoord2f(0.0, 0.0);
- glVertex3i(0, height(), 0);
- glTexCoord2f(1.0, 0.0);
- glVertex3i(width(), height(), 0);
- glEnd();
- }
- void Display::resizeGL(int width, int height)
- {
- Q_UNUSED(width);
- Q_UNUSED(height);
- // Do some aspect ratio stuff here eventually...
- }
- void Display::setPixelColor(quint32 x, quint32 y, quint32 color)
- {
- quint32 idx = (x + y* displayWidth);
- textureBuffer[idx] = color;
- }
- #include "mmu.h"
- void Display::doTest()
- {
- for (uint i = 0; i < displayWidth; i++)
- setPixelColor(i/8, i%8, MMU::vram[i]);
- update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement